Created
April 3, 2014 15:09
-
-
Save whoisstan/9956176 to your computer and use it in GitHub Desktop.
Add File to Github
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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