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

Instance Method Details

#bodyObject

Returns raw body



53
54
55
# File 'lib/bitbucket_rest_api/result.rb', line 53

def body
  loaded? ? @env[:body] : nil
end

#cache_controlObject



16
17
18
# File 'lib/bitbucket_rest_api/result.rb', line 16

def cache_control
  loaded? ? @env[:response_headers][CACHE_CONTROL] : nil
end

#content_lengthObject



24
25
26
# File 'lib/bitbucket_rest_api/result.rb', line 24

def content_length
  loaded? ? @env[:response_headers][CONTENT_LENGTH] : nil
end

#content_typeObject



20
21
22
# File 'lib/bitbucket_rest_api/result.rb', line 20

def content_type
  loaded? ? @env[:response_headers][CONTENT_TYPE] : nil
end

#dateObject



32
33
34
# File 'lib/bitbucket_rest_api/result.rb', line 32

def date
  loaded? ? @env[:response_headers][DATE] : nil
end

#each_page {|body| ... } ⇒ Object

Iterator like each for response pages. If there are no pages to iterate over this method will return nothing.

Yields:



68
69
70
71
# File 'lib/bitbucket_rest_api/result.rb', line 68

def each_page
  yield body
  yield next_page while page_iterator.has_next?
end

#etagObject



28
29
30
# File 'lib/bitbucket_rest_api/result.rb', line 28

def etag
  loaded? ? @env[:response_headers][ETAG] : nil
end

#first_pageObject

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.



76
77
78
79
80
# File 'lib/bitbucket_rest_api/result.rb', line 76

def first_page
  first_request = page_iterator.first
  instance_eval { @env = first_request.env } if first_request
  body
end

#has_next_page?Boolean

Returns true if there is another page in the result set, otherwise false

Returns:

  • (Boolean)


120
121
122
# File 'lib/bitbucket_rest_api/result.rb', line 120

def has_next_page?
  page_iterator.has_next?
end

#last_pageObject

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.



102
103
104
105
106
# File 'lib/bitbucket_rest_api/result.rb', line 102

def last_page
  last_request = page_iterator.last
  instance_eval { @env = last_request.env } if last_request
  body
end

Return page links



62
63
64
# File 'lib/bitbucket_rest_api/result.rb', line 62

def links
  @@links = BitBucket::PageLinks.new(@env[:response_headers])
end

#loaded?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/bitbucket_rest_api/result.rb', line 57

def loaded?
  !!@env
end

#locationObject



36
37
38
# File 'lib/bitbucket_rest_api/result.rb', line 36

def location
  loaded? ? @env[:response_headers][LOCATION] : nil
end

#next_pageObject

Retrives the result of the next page. Returns nil if there is no next page or no pages at all.



84
85
86
87
88
# File 'lib/bitbucket_rest_api/result.rb', line 84

def next_page
  next_request = page_iterator.next
  instance_eval { @env = next_request.env } if next_request
  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



112
113
114
115
116
# File 'lib/bitbucket_rest_api/result.rb', line 112

def page(page_number)
  request = page_iterator.get_page(page_number)
  instance_eval { @env = request.env } if request
  body
end

#prev_pageObject 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.



92
93
94
95
96
# File 'lib/bitbucket_rest_api/result.rb', line 92

def prev_page
  prev_request = page_iterator.prev
  instance_eval { @env = prev_request.env } if prev_request
  body
end

#ratelimit_limitObject

TODO: Add result counts method to check total items looking at result links



8
9
10
# File 'lib/bitbucket_rest_api/result.rb', line 8

def ratelimit_limit
  loaded? ? @env[:response_headers][RATELIMIT_LIMIT] : nil
end

#ratelimit_remainingObject



12
13
14
# File 'lib/bitbucket_rest_api/result.rb', line 12

def ratelimit_remaining
  loaded? ? @env[:response_headers][RATELIMIT_REMAINING] : nil
end

#resetObject

Repopulates objects for new values



125
126
127
# File 'lib/bitbucket_rest_api/result.rb', line 125

def reset
  nil
end

#serverObject



40
41
42
# File 'lib/bitbucket_rest_api/result.rb', line 40

def server
  loaded? ? @env[:response_headers][SERVER] : nil
end

#statusObject



44
45
46
# File 'lib/bitbucket_rest_api/result.rb', line 44

def status
  loaded? ? @env[:status] : nil
end

#success?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/bitbucket_rest_api/result.rb', line 48

def success?
  (200..299).include? status
end