Class: PurolatorRuby::CreateShipmentRequest
- Inherits:
-
Object
- Object
- PurolatorRuby::CreateShipmentRequest
- Defined in:
- lib/purolator_ruby/create_shipment_request.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#payload_opts ⇒ Object
readonly
Returns the value of attribute payload_opts.
Instance Method Summary collapse
-
#initialize(options) ⇒ CreateShipmentRequest
constructor
A new instance of CreateShipmentRequest.
- #send ⇒ Object
- #send! ⇒ Object
Constructor Details
#initialize(options) ⇒ CreateShipmentRequest
Returns a new instance of CreateShipmentRequest.
35 36 37 38 |
# File 'lib/purolator_ruby/create_shipment_request.rb', line 35 def initialize() @client = .fetch(:client) @payload_opts = .except(:client).merge(account_number: client.account_number, billing_number: client.billing_number) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
33 34 35 |
# File 'lib/purolator_ruby/create_shipment_request.rb', line 33 def client @client end |
#payload_opts ⇒ Object (readonly)
Returns the value of attribute payload_opts.
33 34 35 |
# File 'lib/purolator_ruby/create_shipment_request.rb', line 33 def payload_opts @payload_opts end |
Instance Method Details
#send ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/purolator_ruby/create_shipment_request.rb', line 48 def send payload = shipment_payload if payload.valid? shipment_pin = client.call(:create_shipment, message: payload.to_h) .body .fetch(:create_shipment_response) .fetch(:shipment_pin) .fetch(:value) CreateShipmentResponse.new(:ok, shipment_pin, payload, nil) else CreateShipmentResponse.new(:error, nil, payload, payload.errors) end end |
#send! ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/purolator_ruby/create_shipment_request.rb', line 40 def send! send.tap do |resp| if resp.status == :error raise ArgumentError, resp.payload.errors.join(' ') end end end |