class GitNetworkitis::Getter

Constants

LOCAL_KEYS

Attributes

local_options[RW]
query_options[RW]
url[RW]

Public Class Methods

new(url, options={}) click to toggle source
# File lib/gitnetworkitis/getter.rb, line 11
def initialize(url, options={})
  @url = url
  scrub_local_options options
  @query_options = options
end

Public Instance Methods

get() click to toggle source
# File lib/gitnetworkitis/getter.rb, line 17
def get
  local_options[:batch] ? batched_get : single_get
end

Private Instance Methods

batched_get() click to toggle source
# File lib/gitnetworkitis/getter.rb, line 36
def batched_get
  resps = []
  links = {next: url}
  first_batch = true
  while links[:next] do
    self.url = links[:next]
    resp = single_get first_batch
    resps << resp
    first_batch = false
    links = build_links_from_headers resp.headers['link']
  end
  BatchResponse.new resps
end
scrub_local_options(options={}) click to toggle source
# File lib/gitnetworkitis/getter.rb, line 22
def scrub_local_options(options={})
  @local_options = LOCAL_KEYS.inject({}) {|opts, key| opts[key] = options.delete(key); opts }
  @local_options[:batch] = true unless @local_options[:since].nil?
end
single_get(use_query_options=true) click to toggle source
# File lib/gitnetworkitis/getter.rb, line 27
def single_get(use_query_options=true)
  ret = use_query_options ? Getter.get(url, query: query_options) : Getter.get(url)
  if ret.response.code == "200"
    return ret
  else
    raise "Unable to find Github Repository"
  end
end