Skip to content

Instantly share code, notes, and snippets.

@juno
Created January 22, 2011 12:49
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save juno/791101 to your computer and use it in GitHub Desktop.
Save juno/791101 to your computer and use it in GitHub Desktop.
w/HTTParty
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