Skip to content

Instantly share code, notes, and snippets.

@elikem
Forked from juno/github-api-practice.rb
Created March 11, 2014 06:40
Show Gist options
  • Select an option

  • Save elikem/9480707 to your computer and use it in GitHub Desktop.

Select an option

Save elikem/9480707 to your computer and use it in GitHub Desktop.
Github API Practice
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