class Postmen::Response
This class parses the HTTP response and checks if it was successfull.
Public Instance Methods
Returns current API rate limit
# File lib/postmen/response.rb, line 48 def api_rate_limit Integer(headers['X-RateLimit-Limit']) end
Returns Unix timestamp when rate limit will be reset. @return [Integer] timestamp
# File lib/postmen/response.rb, line 54 def api_rate_limit_reset Integer(headers['X-RateLimit-Reset']) end
Return time when rate limit will be reset. @return [Time]
# File lib/postmen/response.rb, line 60 def api_rate_limit_reset_at Time.at(api_rate_limit_reset) end
Holds the data @see docs.postmen.com/#data API Documentation @return [Hash]
# File lib/postmen/response.rb, line 22 def data @data ||= parsed_response[:data] end
Holds the meta data @see docs.postmen.com/#meta API Documentation @return [Hash]
# File lib/postmen/response.rb, line 15 def meta @meta ||= parsed_response[:meta] end
Parses response. Ensures that rate limit was not exceeded, and checks if resource was found
# File lib/postmen/response.rb, line 7 def parse_response! ensure_rate_limit! ensure_resource_found! end
Parses the json response @return [Hash]
# File lib/postmen/response.rb, line 28 def parsed_response @parsed_response ||= JSON.parse(body, symbolize_names: true) end
Checks if rate limit was exceeded
# File lib/postmen/response.rb, line 38 def rate_limit_exceeded? code == 429 end
Returns number of remaining API calls
# File lib/postmen/response.rb, line 43 def remaining_api_calls Integer(headers['X-RateLimit-Remaining']) end
Checks if response were successfull
# File lib/postmen/response.rb, line 33 def success? meta[:code] == 200 end
Private Instance Methods
Guard method, checking if rate limit was not exceeded @api private
# File lib/postmen/response.rb, line 68 def ensure_rate_limit! raise RateLimitExceeded, self if rate_limit_exceeded? end
Guard method, checking if resource was found. @api private
# File lib/postmen/response.rb, line 74 def ensure_resource_found! raise ResourceNotFound, self if meta[:code] == 4153 end