lib/friendly_shipping/response.rb in friendly_shipping-0.8.1 vs lib/friendly_shipping/response.rb in friendly_shipping-0.9.0

- old
+ new

@@ -1,41 +1,56 @@ # frozen_string_literal: true module FriendlyShipping + # Represents an HTTP response received from a carrier API. class Response - attr_reader :status, :body, :headers + # @return [Integer] the HTTP response status code + attr_reader :status - # @param [Integer] status The HTTP response status code - # @param [String] body The HTTP response body - # @param [Hash] headers The HTTP response headers + # @return [String] the HTTP response body + attr_reader :body + + # @return [Hash] the HTTP response headers + attr_reader :headers + + # @param status [Integer] the HTTP response status code + # @param body [String] the HTTP response body + # @param headers [Hash] the HTTP response headers def initialize(status:, body:, headers:) @status = status @body = body @headers = headers || {} end alias_method :code, :status - # @param [RestClient::Response] response - # @return [FriendlyShipping::Response] + # Constructs a new {Response} from a `RestClient::Response` object. + # @param response [RestClient::Response] the response to use + # @return [Response] def self.new_from_rest_client_response(response) new(status: response&.code, body: response&.body, headers: response&.headers) end + # Returns true if the given object shares the same class and attributes with this response. # @param [Object] other + # @return [Boolean] def ==(other) other.class == self.class && other.attributes == attributes end alias_method :eql?, :== + # Returns this response's attributes as a hash. + # @return [Hash] def hash attributes.hash end protected + # Returns the status, body, and headers from this response. + # @return [Array] def attributes [status, body, headers] end end end