lib/friendly_shipping/request.rb in friendly_shipping-0.8.1 vs lib/friendly_shipping/request.rb in friendly_shipping-0.9.0
- old
+ new
@@ -1,25 +1,41 @@
# frozen_string_literal: true
module FriendlyShipping
+ # Represents an HTTP request sent to a carrier API.
class Request
- attr_reader :url, :http_method, :body, :headers, :debug
+ # @return [String] the HTTP request URL
+ attr_reader :url
- # @param [String] url The HTTP request URL
- # @param [String] http_method The HTTP request method
- # @param [String] body The HTTP request body
- # @param [String] readable_body Human-readable HTTP request body
- # @param [Hash] headers The HTTP request headers
- # @param [Boolean] debug Whether to debug the request
+ # @return [String] the HTTP request method
+ attr_reader :http_method
+
+ # @return [String] the HTTP request body
+ attr_reader :body
+
+ # @return [String] human-readable HTTP request body
+ attr_reader :headers
+
+ # @return [Boolean] whether to attach debugging information to the response
+ attr_reader :debug
+
+ # @param url [String] the HTTP request URL
+ # @param http_method [String] the HTTP request method
+ # @param body [String] the HTTP request body
+ # @param readable_body [String] human-readable HTTP request body
+ # @param headers [Hash] the HTTP request headers
+ # @param debug [Boolean] whether to attach debugging information to the response
def initialize(url:, http_method: nil, body: nil, readable_body: nil, headers: {}, debug: false)
@url = url
@http_method = http_method
@body = body
@readable_body = readable_body
@headers = headers
@debug = debug
end
+ # Returns the HTTP request body.
+ # @return [String] human-readable HTTP request body
def readable_body
@readable_body.presence || @body
end
end
end