Created
January 22, 2011 12:49
-
-
Save juno/791101 to your computer and use it in GitHub Desktop.
w/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
require 'json' | |
require 'httparty' | |
class Github | |
include HTTParty | |
base_uri 'http://github.com/api/v2/json' | |
# @param [String] username GitHub username | |
# @param [String] password Password or API token | |
def initialize(username, password) | |
@auth = { :username => username, :password => password } | |
end | |
# @param [String] username GitHub username | |
# @return [Hash] | |
def show_user(username) | |
response = self.class.get("/user/show/#{username}", { :basic_auth => @auth }) | |
JSON.parse(response.body) | |
end | |
# @param [String] username GitHub username | |
# @param [Hash] values | |
def update_user(username, values) | |
options = { | |
:basic_auth => @auth, | |
:query => { | |
:values => values, | |
}, | |
} | |
self.class.post("/user/show/#{username}", options) | |
end | |
end | |
gh = Github.new('username', 'password') # or Github.new('username/token', 'api_token') | |
p gh.show_user('username') | |
p gh.update_user('username', { 'location' => 'Redwood City, CA' }) | |
p gh.show_user('username') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment