class Breathe::Response
Attributes
response[R]
type[R]
Public Class Methods
new(response:, type:)
click to toggle source
# File lib/breathe/response.rb, line 8 def initialize(response:, type:) @response = response @type = type end
Public Instance Methods
body()
click to toggle source
# File lib/breathe/response.rb, line 13 def body @body ||= response.data[type] end
first_page()
click to toggle source
# File lib/breathe/response.rb, line 25 def first_page get_page(:first) end
last_page()
click to toggle source
# File lib/breathe/response.rb, line 37 def last_page get_page(:last) end
next_page()
click to toggle source
# File lib/breathe/response.rb, line 29 def next_page get_page(:next) end
per_page()
click to toggle source
# File lib/breathe/response.rb, line 21 def per_page response.headers["per-page"].to_i end
previous_page()
click to toggle source
# File lib/breathe/response.rb, line 33 def previous_page get_page(:prev) end
success?()
click to toggle source
# 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 raise Breathe::UnknownError, "The BreatheHR API returned an unknown error" end end
total()
click to toggle source
# File lib/breathe/response.rb, line 17 def total response.headers["total"].to_i end
Private Instance Methods
get_page(rel_type)
click to toggle source
# File lib/breathe/response.rb, line 54 def get_page(rel_type) self.class.new(response: response.rels[rel_type].get, type: type) if response.rels[rel_type] end