Module: BitBucket::Result
- Includes:
- Constants
- Defined in:
- lib/bitbucket_rest_api/result.rb
Constant Summary
Constants included from Constants
Constants::ACCEPT, Constants::ACCEPT_CHARSET, Constants::CACHE_CONTROL, Constants::CONTENT_LENGTH, Constants::CONTENT_TYPE, Constants::DATE, Constants::ETAG, Constants::HEADER_LAST, Constants::HEADER_LINK, Constants::HEADER_NEXT, Constants::LOCATION, Constants::META_FIRST, Constants::META_LAST, Constants::META_NEXT, Constants::META_PREV, Constants::META_REL, Constants::PARAM_PAGE, Constants::PARAM_PER_PAGE, Constants::PARAM_START_PAGE, Constants::QUERY_STR_SEP, Constants::RATELIMIT_LIMIT, Constants::RATELIMIT_REMAINING, Constants::SERVER, Constants::USER_AGENT
Instance Method Summary collapse
-
#body ⇒ Object
Returns raw body.
- #cache_control ⇒ Object
- #content_length ⇒ Object
- #content_type ⇒ Object
- #date ⇒ Object
-
#each_page {|self.body| ... } ⇒ Object
Iterator like each for response pages.
- #etag ⇒ Object
-
#first_page ⇒ Object
Retrives the result of the first page.
-
#has_next_page? ⇒ Boolean
Returns
true
if there is another page in the result set, otherwisefalse
. -
#last_page ⇒ Object
Retrives the result of the last page.
-
#links ⇒ Object
Return page links.
- #loaded? ⇒ Boolean
- #location ⇒ Object
-
#next_page ⇒ Object
Retrives the result of the next page.
-
#page(page_number) ⇒ Object
Retrives a specific result for a page given page number.
-
#prev_page ⇒ Object
(also: #previous_page)
Retrives the result of the previous page.
-
#ratelimit_limit ⇒ Object
TODO Add result counts method to check total items looking at result links.
- #ratelimit_remaining ⇒ Object
-
#reset ⇒ Object
Repopulates objects for new values.
- #server ⇒ Object
- #status ⇒ Object
- #success? ⇒ Boolean
Instance Method Details
#body ⇒ Object
Returns raw body
54 55 56 |
# File 'lib/bitbucket_rest_api/result.rb', line 54 def body loaded? ? @env[:body] : nil end |
#cache_control ⇒ Object
17 18 19 |
# File 'lib/bitbucket_rest_api/result.rb', line 17 def cache_control loaded? ? @env[:response_headers][CACHE_CONTROL] : nil end |
#content_length ⇒ Object
25 26 27 |
# File 'lib/bitbucket_rest_api/result.rb', line 25 def content_length loaded? ? @env[:response_headers][CONTENT_LENGTH] : nil end |
#content_type ⇒ Object
21 22 23 |
# File 'lib/bitbucket_rest_api/result.rb', line 21 def content_type loaded? ? @env[:response_headers][CONTENT_TYPE] : nil end |
#date ⇒ Object
33 34 35 |
# File 'lib/bitbucket_rest_api/result.rb', line 33 def date loaded? ? @env[:response_headers][DATE] : nil end |
#each_page {|self.body| ... } ⇒ Object
Iterator like each for response pages. If there are no pages to iterate over this method will return nothing.
69 70 71 72 73 74 |
# File 'lib/bitbucket_rest_api/result.rb', line 69 def each_page yield self.body while page_iterator.has_next? yield next_page end end |
#etag ⇒ Object
29 30 31 |
# File 'lib/bitbucket_rest_api/result.rb', line 29 def etag loaded? ? @env[:response_headers][ETAG] : nil end |
#first_page ⇒ Object
Retrives the result of the first page. Returns nil
if there is no first page - either because you are already on the first page or there are no pages at all in the result.
79 80 81 82 83 |
# File 'lib/bitbucket_rest_api/result.rb', line 79 def first_page first_request = page_iterator.first self.instance_eval { @env = first_request.env } if first_request self.body end |
#has_next_page? ⇒ Boolean
Returns true
if there is another page in the result set, otherwise false
123 124 125 |
# File 'lib/bitbucket_rest_api/result.rb', line 123 def has_next_page? page_iterator.has_next? end |
#last_page ⇒ Object
Retrives the result of the last page. Returns nil
if there is no last page - either because you are already on the last page, there is only one page or there are no pages at all in the result.
105 106 107 108 109 |
# File 'lib/bitbucket_rest_api/result.rb', line 105 def last_page last_request = page_iterator.last self.instance_eval { @env = last_request.env } if last_request self.body end |
#links ⇒ Object
Return page links
63 64 65 |
# File 'lib/bitbucket_rest_api/result.rb', line 63 def links @@links = BitBucket::PageLinks.new(@env[:response_headers]) end |
#loaded? ⇒ Boolean
58 59 60 |
# File 'lib/bitbucket_rest_api/result.rb', line 58 def loaded? !!@env end |
#location ⇒ Object
37 38 39 |
# File 'lib/bitbucket_rest_api/result.rb', line 37 def location loaded? ? @env[:response_headers][LOCATION] : nil end |
#next_page ⇒ Object
Retrives the result of the next page. Returns nil
if there is no next page or no pages at all.
87 88 89 90 91 |
# File 'lib/bitbucket_rest_api/result.rb', line 87 def next_page next_request = page_iterator.next self.instance_eval { @env = next_request.env } if next_request self.body end |
#page(page_number) ⇒ Object
Retrives a specific result for a page given page number. The page_number
parameter is not validate, hitting a page that does not exist will return BitBucket API error. Consequently, if there is only one page, this method returns nil
115 116 117 118 119 |
# File 'lib/bitbucket_rest_api/result.rb', line 115 def page(page_number) request = page_iterator.get_page(page_number) self.instance_eval { @env = request.env } if request self.body end |
#prev_page ⇒ Object Also known as: previous_page
Retrives the result of the previous page. Returns nil
if there is no previous page or no pages at all.
95 96 97 98 99 |
# File 'lib/bitbucket_rest_api/result.rb', line 95 def prev_page prev_request = page_iterator.prev self.instance_eval { @env = prev_request.env } if prev_request self.body end |
#ratelimit_limit ⇒ Object
TODO Add result counts method to check total items looking at result links
9 10 11 |
# File 'lib/bitbucket_rest_api/result.rb', line 9 def ratelimit_limit loaded? ? @env[:response_headers][RATELIMIT_LIMIT] : nil end |
#ratelimit_remaining ⇒ Object
13 14 15 |
# File 'lib/bitbucket_rest_api/result.rb', line 13 def ratelimit_remaining loaded? ? @env[:response_headers][RATELIMIT_REMAINING] : nil end |
#reset ⇒ Object
Repopulates objects for new values
128 129 130 |
# File 'lib/bitbucket_rest_api/result.rb', line 128 def reset nil end |
#server ⇒ Object
41 42 43 |
# File 'lib/bitbucket_rest_api/result.rb', line 41 def server loaded? ? @env[:response_headers][SERVER] : nil end |
#status ⇒ Object
45 46 47 |
# File 'lib/bitbucket_rest_api/result.rb', line 45 def status loaded? ? @env[:status] : nil end |
#success? ⇒ Boolean
49 50 51 |
# File 'lib/bitbucket_rest_api/result.rb', line 49 def success? (200..299).include? status end |