Class: Usps::Client

Inherits:
Object
  • Object
show all
Includes:
Api::Endpoints, Faraday::Connection, Faraday::Request
Defined in:
lib/usps/client.rb

Constant Summary

Constants included from Api::Endpoints

Api::Endpoints::ACTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Api::Endpoints::ZipCodeLookup

#zip_code_lookup

Methods included from Api::Endpoints::Verify

#verify

Methods included from Api::Endpoints::USPSReturnsLabel

#usps_returns_label

Methods included from Api::Endpoints::TrackV2

#track_v2

Methods included from Api::Endpoints::SundayHolidayAvailability

#sunday_holiday_availability

Methods included from Api::Endpoints::SCAN

#scan

Methods included from Api::Endpoints::RateV4

#rate_v4

Methods included from Api::Endpoints::PTSTPod

#ptst_pod

Methods included from Api::Endpoints::PTSRre

#pts_rre

Methods included from Api::Endpoints::PTSPod

#pts_pod

Methods included from Api::Endpoints::PTSEmail

#pts_email

Methods included from Api::Endpoints::IntlRateV2

#intl_rate_v2

Methods included from Api::Endpoints::HFPFacilityInfo

#hfp_facility_info

Methods included from Api::Endpoints::EVSICancel

#e_vsi_cancel

Methods included from Api::Endpoints::EVSGXGGetLabel

#e_vsgxg_get_label

Methods included from Api::Endpoints::EVSPriorityMailIntl

#e_vs_priority_mail_intl

Methods included from Api::Endpoints::EVSFirstClassMailIntl

#e_vs_first_class_mail_intl

Methods included from Api::Endpoints::EVSExpressMailIntl

#e_vs_express_mail_intl

Methods included from Api::Endpoints::CityStateLookup

#city_state_lookup

Methods included from Api::Endpoints::CarrierPickupSchedule

#carrier_pickup_schedule

Methods included from Faraday::Request

#delete, #get, #post, #put

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
16
17
# File 'lib/usps/client.rb', line 10

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

Class Method Details

.configObject



32
33
34
# File 'lib/usps/client.rb', line 32

def config
  Config
end

.configureObject



28
29
30
# File 'lib/usps/client.rb', line 28

def configure
  block_given? ? yield(Config) : Config
end

Instance Method Details

#build_request(action, options) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/usps/client.rb', line 19

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