class VzaarApi::Lib::ApiResponse
Attributes
response[R]
Public Class Methods
new(response)
click to toggle source
# File lib/vzaar_api/lib/api_response.rb, line 7 def initialize(response) @response = response end
Public Instance Methods
data()
click to toggle source
# File lib/vzaar_api/lib/api_response.rb, line 11 def data json[:data] end
error()
click to toggle source
# File lib/vzaar_api/lib/api_response.rb, line 19 def error simple_errors.join('; ') end
meta()
click to toggle source
# File lib/vzaar_api/lib/api_response.rb, line 15 def meta json[:meta] end
ok?()
click to toggle source
# File lib/vzaar_api/lib/api_response.rb, line 23 def ok? response.ok? end
rate_limit()
click to toggle source
# File lib/vzaar_api/lib/api_response.rb, line 27 def rate_limit rate_limit_value 'X-RateLimit-Limit' end
rate_limit_remaining()
click to toggle source
# File lib/vzaar_api/lib/api_response.rb, line 31 def rate_limit_remaining rate_limit_value 'X-RateLimit-Remaining' end
rate_limit_reset()
click to toggle source
# File lib/vzaar_api/lib/api_response.rb, line 35 def rate_limit_reset rate_limit_value 'X-RateLimit-Reset' end
Private Instance Methods
json()
click to toggle source
# File lib/vzaar_api/lib/api_response.rb, line 53 def json @json ||= JSON.parse(response.body, symbolize_names: true) rescue JSON::ParserError raise Error.new('Invalid JSON response from API') end
rate_limit_value(header)
click to toggle source
# File lib/vzaar_api/lib/api_response.rb, line 41 def rate_limit_value(header) if limit = response.headers[header] limit.to_i else nil end end
simple_errors()
click to toggle source
# File lib/vzaar_api/lib/api_response.rb, line 49 def simple_errors json[:errors].map { |e| [e[:message], e[:detail]].join(': ') } end