Class: GitHubBub::Response

Inherits:
Excon::Response
  • Object
show all
Defined in:
lib/git_hub_bub/response.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(response) ⇒ Object



4
5
6
# File 'lib/git_hub_bub/response.rb', line 4

def self.create(response)
  self.new(response.data)
end

Instance Method Details

#first_page?Boolean

Returns:

  • (Boolean)


44
45
46
47
# File 'lib/git_hub_bub/response.rb', line 44

def first_page?
  return true if first_url.nil?
  return false
end

#first_urlObject



33
34
35
# File 'lib/git_hub_bub/response.rb', line 33

def first_url
  pagination['first_url']
end


54
55
56
# File 'lib/git_hub_bub/response.rb', line 54

def header_links
  (headers['link'] || headers['Link'] || "").split(',')
end

#json_bodyObject



8
9
10
# File 'lib/git_hub_bub/response.rb', line 8

def json_body
 ::JSON.parse(self.body)
end

#last_page?Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
# File 'lib/git_hub_bub/response.rb', line 37

def last_page?
  return true if next_url.nil?
  last_page_number = page_number_from_url(last_url)
  next_page_number = page_number_from_url(next_url)
  return next_page_number > last_page_number
end

#last_urlObject



29
30
31
# File 'lib/git_hub_bub/response.rb', line 29

def last_url
  pagination['last_url']
end

#next_urlObject



20
21
22
# File 'lib/git_hub_bub/response.rb', line 20

def next_url
  pagination['next_url']
end

#page_number_from_url(url) ⇒ Object



49
50
51
52
# File 'lib/git_hub_bub/response.rb', line 49

def page_number_from_url(url)
  query = ::URI.parse(url).query
  ::CGI.parse(query)["page"].first.to_i
end

#paginationObject



12
13
14
# File 'lib/git_hub_bub/response.rb', line 12

def pagination
  @pagination ||= parse_pagination
end

#parse_paginationObject



58
59
60
61
62
63
64
# File 'lib/git_hub_bub/response.rb', line 58

def parse_pagination
  header_links.each_with_object({}) do |element, hash|
    key   = element[/rel=["'](.*)['"]/, 1]
    value = element[/<(.*)>/, 1]
    hash["#{key}_url"] = value
  end
end

#parsed_responseObject



16
17
18
# File 'lib/git_hub_bub/response.rb', line 16

def parsed_response
 response.body.inspect
end

#prev_urlObject Also known as: previous_url



24
25
26
# File 'lib/git_hub_bub/response.rb', line 24

def prev_url
  pagination['prev_url']
end