Skip to content

Instantly share code, notes, and snippets.

@anthonycintron
Forked from jkatz/GithubAPI.rb
Created July 23, 2010 12:00
Show Gist options
  • Save anthonycintron/487351 to your computer and use it in GitHub Desktop.
Save anthonycintron/487351 to your computer and use it in GitHub Desktop.
require 'net/http'
require 'json'
class GithubAPI
HOST = "github.com"
API = "/api/v2"
attr_accessor :format
attr_reader :response, :user
def initialize(username, token, params={})
@username, @token = username, token
@format = params[:format] || "json"
end
def api
API
end
def get_user_info()
path = [api,format,'user','show'].join('/')
connect(path, username, token)
end
def get_all_commit_history(value)
end
def host
HOST
end
private
def connect(path, username, token)
params = { :token => token, :login => username }
query = params.map { |k,v| "#{k}=#{v}" }.join('&')
Net::HTTP.start(host) do |http|
req = Net::HTTP::Get.new("#{path}?#{query}")
@response = http.request(req)
@user = JSON.parse(@response.body)
end
end
end
@anthonycintron
Copy link
Author

I edited 'params.map'. k=v was hard coded, so I made it a dynamic value.

@jkatz
Copy link

jkatz commented Jul 23, 2010

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment