Created
April 3, 2012 01:54
-
-
Save btoone/2288733 to your computer and use it in GitHub Desktop.
Prototype for a gist library using httparty
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
:username: caspyin | |
:password: PASSWD |
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
{ | |
"description": "the description for this gist", | |
"public": true, | |
"files": { | |
"file1.txt": { | |
"content": "String file contents" | |
} | |
} | |
} |
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 'httparty' | |
require 'pp' | |
require 'json' | |
config = YAML.load_file('credentials.yml') | |
class GitHub | |
include HTTParty | |
base_uri 'https://api.github.com' | |
def initialize(u, p) | |
@auth = {username: u, password: p} | |
end | |
def users(options={}) | |
options.merge!({basic_auth: @auth}) | |
self.class.get('/users/caspyin', options) | |
end | |
def gists(options={}) | |
options.merge!({basic_auth: @auth}) | |
self.class.get('/gists', options) | |
end | |
def starred_gists(options={}) | |
options.merge!({basic_auth: @auth}) | |
self.class.get('/gists/starred', options) | |
end | |
end | |
gist = { | |
"description" => "Test", | |
"public" => false, | |
"files" => { | |
"file1.txt" => { | |
"content" => "API 3:34 PM" | |
} | |
} | |
} | |
options = { | |
basic_auth: { | |
username: config[:username], | |
password: config[:password] | |
}, | |
body: JSON.generate(gist) | |
} | |
github = GitHub.new(config[:username], config[:password]) | |
puts "User Info" | |
pp github.users | |
puts "Gists" | |
pp github.gists | |
puts "Starred Gists" | |
pp github.starred_gists | |
# pp HTTParty.post('https://api.github.com/gists', options) | |
# cli | |
# httparty --user 'user':'passwd' "https://api.github.com/users/caspyin" | |
# httparty -v --action post --user "caspyin":"PASSWD" --header "ContentType:application/json" --data "{\"description\":\"Test\",\"public\":false,\"files\":{\"file1.txt\":{\"content\":\"Post via cmd line\"}}}" "https://api.github.com/gists" | |
# pp HTTParty.get('https://api.github.com/users/caspyin', {basic_auth:{username:config[:username], password:config[:password]}}) | |
# response = HTTParty.get('https://api.github.com/users/caspyin', options) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment