Sha256: bf01aeb8345b135d247be63b60b93430a3c89f4e2b5bcc28b287fe2453fb1840

Contents?: true

Size: 1.29 KB

Versions: 3

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module FriendlyShipping
  # Represents an HTTP request sent to a carrier API.
  class Request
    # @return [String] the HTTP request URL
    attr_reader :url

    # @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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
friendly_shipping-0.10.1 lib/friendly_shipping/request.rb
friendly_shipping-0.10.0 lib/friendly_shipping/request.rb
friendly_shipping-0.9.0 lib/friendly_shipping/request.rb