Skip to content

Instantly share code, notes, and snippets.

@bootcoder
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save bootcoder/b30b8f479abae007c8be to your computer and use it in GitHub Desktop.

Select an option

Save bootcoder/b30b8f479abae007c8be to your computer and use it in GitHub Desktop.
Demo to show off some HTTParty methods interacting with the Github API
module Github
class Client
include HTTParty
base_uri "https://api.github.com"
def initialize(username, password)
@user_auth = { :username => username, :password => password }
@token_auth = "token 8205ba1597bdb27b197018ea35117d1ef45e588f"
end
def get_user(username)
response = self.class.get(
"/users/#{username}", {
headers: { 'User-Agent' => ENV['USER_AGENT'] }
})
return response.body
end
def emojis
response = self.class.get("/emojis", { headers: { 'User-Agent' => ENV['USER_AGENT'] } })
return response.body
end
def get_org(org_name)
response = self.class.get("/orgs/#{org_name}", { headers: { 'User-Agent' => ENV['USER_AGENT'] } })
return response.body
end
def update_user(api_options)
outbound_data = { hireable: api_options }.to_json
# Both work the same
response = self.class.patch("/user", { headers: { 'User-Agent' => ENV['USER_AGENT'], 'Authorization' => @token }, body: outbound_data })
# response = self.class.patch("/user", { headers: { 'User-Agent' => ENV['USER_AGENT'] }, basic_auth: @auth, body: outbound_data })
return response.body
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment