Skip to content

Instantly share code, notes, and snippets.

@jkatz
Forked from anthonycintron/GithubAPI.rb
Created July 23, 2010 02:46

Revisions

  1. jkatz revised this gist Jul 23, 2010. 1 changed file with 28 additions and 18 deletions.
    46 changes: 28 additions & 18 deletions GithubAPI.rb
    Original file line number Diff line number Diff line change
    @@ -2,29 +2,39 @@
    require 'json'

    class GithubAPI
    HOST = "github.com"
    API = "/api/v2"

    attr_accessor :format
    attr_reader :response, :user

    attr_reader :response, :host, :api, :format

    def initialize
    @host = "github.com"
    @api = "/api/v2"
    @format = "json"
    def initialize(username, token, params={})
    @username, @token = username, token
    @format = params[:format] || "json"
    end
    def get_user_info (user_name, password, token)
    connect "#{api}/#{format}/user/show/", user_name, password, token

    def api
    API
    end

    def get_all_commit_history (value)

    def get_user_info(username, token)
    path = [api,format,'user','show'].join('/')
    connect(path, username, token)
    end



    private
    def connect (command, user_name, password, token)
    Net::HTTP.start(@host) do |http|
    req = Net::HTTP::Get.new("#{command}#{user_name}?token='#{token}'")
    req.basic_auth user_name, password
    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
  2. @anthonycintron anthonycintron renamed this gist Jul 23, 2010. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @anthonycintron anthonycintron created this gist Jul 23, 2010.
    32 changes: 32 additions & 0 deletions GithubAPI
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    require 'net/http'
    require 'json'

    class GithubAPI

    attr_reader :response, :host, :api, :format

    def initialize
    @host = "github.com"
    @api = "/api/v2"
    @format = "json"
    end

    def get_user_info (user_name, password, token)
    connect "#{api}/#{format}/user/show/", user_name, password, token
    end

    def get_all_commit_history (value)
    end



    private
    def connect (command, user_name, password, token)
    Net::HTTP.start(@host) do |http|
    req = Net::HTTP::Get.new("#{command}#{user_name}?token='#{token}'")
    req.basic_auth user_name, password
    @response = http.request(req)
    @user = JSON.parse(@response.body)
    end
    end
    end