Skip to content

Instantly share code, notes, and snippets.

@whoisstan
Created April 3, 2014 15:09
Show Gist options
  • Save whoisstan/9956176 to your computer and use it in GitHub Desktop.
Save whoisstan/9956176 to your computer and use it in GitHub Desktop.
Add File to Github
require 'rest_client'
access_token = YOUR_TOKEN
github_user = "whoisstan"
github_repo = "test_for_github_api"
path = "test7.html"
content = Base64.encode64('my file content2')
sha = nil
url="https://api.github.com/repos/#{github_user}/#{github_repo}/contents/#{path}"
#does the path exist already, if yes get the sha code
RestClient.get(url,{ params:{access_token:access_token},accept:'json'}){ |response, request, result|
sha=JSON.parse(response)['sha'] if response.code==200
}
RestClient.put url, { message: "my message", content: content, sha: sha }.to_json,{ params:{access_token:access_token},accept:'json'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment