Sha256: 220652189e1475a5e31d9731313df4ff4d1c9911e7c42302284f90be2501e1bc

Contents?: true

Size: 948 Bytes

Versions: 5

Compression:

Stored size: 948 Bytes

Contents

# frozen_string_literal: true
module Usps
  class Client
    include Faraday::Connection
    include Faraday::Request
    include Api::Endpoints

    attr_accessor(*Config::ATTRIBUTES)

    def initialize(options = {})
      Usps::Config::ATTRIBUTES.each do |key|
        send("#{key}=", options.fetch(key, Usps.config.send(key)))
      end
      @logger ||= Usps::Config.logger || Usps::Logger.default
      @token ||= Usps.config.token
      @user_id ||= Usps.config.user_id
    end

    def build_request(action, options)
      xml = Builder::XmlMarkup.new(indent: 2)
      # xml.instruct!(:xml, version: '1.0', encoding: 'utf-8')
      xml.tag!("#{Usps::Api::Endpoints::ACTIONS[action]}Request", USERID: user_id) do
        send("build_#{action}_request", xml, options)
      end
    end

    class << self
      def configure
        block_given? ? yield(Config) : Config
      end

      def config
        Config
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
usps-ruby-client-0.2.0 lib/usps/client.rb
usps-ruby-client-0.1.3 lib/usps/client.rb
usps-ruby-client-0.1.2 lib/usps/client.rb
usps-ruby-client-0.1.1 lib/usps/client.rb
usps-ruby-client-0.1.0 lib/usps/client.rb