Class: GitHubBub::Response
- Inherits:
-
Excon::Response
- Object
- Excon::Response
- GitHubBub::Response
- Defined in:
- lib/git_hub_bub/response.rb
Class Method Summary collapse
Instance Method Summary collapse
- #first_page? ⇒ Boolean
- #first_url ⇒ Object
- #header_links ⇒ Object
- #json_body ⇒ Object
- #last_page? ⇒ Boolean
- #last_url ⇒ Object
- #next_url ⇒ Object
- #page_number_from_url(url) ⇒ Object
- #pagination ⇒ Object
- #parse_pagination ⇒ Object
- #parsed_response ⇒ Object
- #prev_url ⇒ Object (also: #previous_url)
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
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_url ⇒ Object
33 34 35 |
# File 'lib/git_hub_bub/response.rb', line 33 def first_url pagination['first_url'] end |
#header_links ⇒ Object
54 55 56 |
# File 'lib/git_hub_bub/response.rb', line 54 def header_links (headers['link'] || headers['Link'] || "").split(',') end |
#json_body ⇒ Object
8 9 10 |
# File 'lib/git_hub_bub/response.rb', line 8 def json_body ::JSON.parse(self.body) end |
#last_page? ⇒ 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_url ⇒ Object
29 30 31 |
# File 'lib/git_hub_bub/response.rb', line 29 def last_url pagination['last_url'] end |
#next_url ⇒ Object
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 |
#pagination ⇒ Object
12 13 14 |
# File 'lib/git_hub_bub/response.rb', line 12 def pagination @pagination ||= parse_pagination end |
#parse_pagination ⇒ Object
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_response ⇒ Object
16 17 18 |
# File 'lib/git_hub_bub/response.rb', line 16 def parsed_response response.body.inspect end |
#prev_url ⇒ Object Also known as: previous_url
24 25 26 |
# File 'lib/git_hub_bub/response.rb', line 24 def prev_url pagination['prev_url'] end |