module Github::Client

Constants

MAX_PER_PAGE

Public Instance Methods

access_token() click to toggle source
# File lib/rest-core/client/github.rb, line 62
def access_token
  data['access_token']
end
access_token=(token) click to toggle source
# File lib/rest-core/client/github.rb, line 66
def access_token= token
  data['access_token'] = token
end
all(path, query={}) { |r| ... } click to toggle source
# File lib/rest-core/client/github.rb, line 93
def all path, query={}, opts={}
  q = {:per_page => MAX_PER_PAGE}.merge(query)
  r = get(path, q, opts.merge(RESPONSE_KEY => PROMISE, ASYNC => true)).
    then{ |response|
      body = response[RESPONSE_BODY] + page_range(response).map{ |page|
        get(path, q.merge(:page => page),
            opts.merge(RESPONSE_KEY => RESPONSE_BODY))
      }.inject([], &:+)
      response.merge(RESPONSE_BODY => body)
    }.future_response

  if block_given?
    yield(r[response_key(opts)])
    self
  else
    r[response_key(opts)]
  end
end
authorize!(payload={}) { |data = r| ... } click to toggle source
# File lib/rest-core/client/github.rb, line 76
def authorize! payload={}, query={}, opts={}
  p = {:client_id => client_id, :client_secret => client_secret}.
       merge(payload)
  args = ['https://github.com/login/oauth/access_token',
          p, query, {:access_token => false}.merge(opts)]

  if block_given?
    post(*args){ |r| yield(self.data = r) }
  else
    self.data = post(*args)
  end
end
authorize_url(query={}) click to toggle source
# File lib/rest-core/client/github.rb, line 70
def authorize_url query={}, opts={}
  url('https://github.com/login/oauth/authorize',
      {:client_id => client_id}.merge(query),
      {:access_token => false}.merge(opts))
end
authorized?() click to toggle source
# File lib/rest-core/client/github.rb, line 89
def authorized?
  !!access_token
end
me(query={}) click to toggle source
# File lib/rest-core/client/github.rb, line 58
def me query={}, opts={}, &cb
  get('user', query, opts, &cb)
end

Private Instance Methods

default_data() click to toggle source
# File lib/rest-core/client/github.rb, line 113
def default_data
  {}
end
page_range(response) click to toggle source
# File lib/rest-core/client/github.rb, line 117
def page_range response
  from = (parse_current_page(response) || 1).to_i + 1
  to   = (parse_last_page(response) || from - 1).to_i
  if from <= to
    from..to
  else
    []
  end
end
parse_current_page(response) click to toggle source
# File lib/rest-core/client/github.rb, line 127
def parse_current_page response
  RC::ParseQuery.parse_query(URI.parse(response[REQUEST_URI]).query)['page']
end
parse_last_page(response) click to toggle source
# File lib/rest-core/client/github.rb, line 131
def parse_last_page response
  return unless link = response[RESPONSE_HEADERS]['LINK']
  ls = RC::ParseLink.parse_link(link)
  return unless last_link = ls['last']
  RC::ParseQuery.parse_query(URI.parse(last_link['uri']).query)['page']
end