Class: Breathe::Response
- Inherits:
-
Object
- Object
- Breathe::Response
- Extended by:
- Forwardable
- Defined in:
- lib/breathe/response.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #body ⇒ Object
- #first_page ⇒ Object
-
#initialize(response:, type:) ⇒ Response
constructor
A new instance of Response.
- #last_page ⇒ Object
- #next_page ⇒ Object
- #per_page ⇒ Object
- #previous_page ⇒ Object
- #success? ⇒ Boolean
- #total ⇒ Object
Constructor Details
#initialize(response:, type:) ⇒ Response
Returns a new instance of Response.
8 9 10 11 |
# File 'lib/breathe/response.rb', line 8 def initialize(response:, type:) @response = response @type = type end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
4 5 6 |
# File 'lib/breathe/response.rb', line 4 def response @response end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/breathe/response.rb', line 4 def type @type end |
Instance Method Details
#body ⇒ Object
13 14 15 |
# File 'lib/breathe/response.rb', line 13 def body @body ||= response.data[type] end |
#first_page ⇒ Object
25 26 27 |
# File 'lib/breathe/response.rb', line 25 def first_page get_page(:first) end |
#last_page ⇒ Object
37 38 39 |
# File 'lib/breathe/response.rb', line 37 def last_page get_page(:last) end |
#next_page ⇒ Object
29 30 31 |
# File 'lib/breathe/response.rb', line 29 def next_page get_page(:next) end |
#per_page ⇒ Object
21 22 23 |
# File 'lib/breathe/response.rb', line 21 def per_page response.headers["per-page"].to_i end |
#previous_page ⇒ Object
33 34 35 |
# File 'lib/breathe/response.rb', line 33 def previous_page get_page(:prev) end |
#success? ⇒ Boolean
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/breathe/response.rb', line 41 def success? return true if /^2+/.match?(response.status.to_s) case response.status when 401 raise Breathe::AuthenticationError, "The BreatheHR API returned a 401 error - are you sure you've set the correct API key?" else puts("Unknown Error") puts(response.status) puts(response.body) raise Breathe::UnknownError, "The BreatheHR API returned an unknown error" end end |
#total ⇒ Object
17 18 19 |
# File 'lib/breathe/response.rb', line 17 def total response.headers["total"].to_i end |