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
9 10 11 12 13 14 |
# File 'lib/purolator_ruby/create_shipment_request.rb', line 9 def initialize() @client = .fetch(:client) _opts = .dup _opts.delete(:client) @payload_opts = _opts.merge(account_number: client.account_number, billing_number: client.billing_number) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/purolator_ruby/create_shipment_request.rb', line 7 def client @client end |
#payload_opts ⇒ Object (readonly)
Returns the value of attribute payload_opts.
7 8 9 |
# File 'lib/purolator_ruby/create_shipment_request.rb', line 7 def payload_opts @payload_opts end |
Instance Method Details
#send ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/purolator_ruby/create_shipment_request.rb', line 24 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
16 17 18 19 20 21 22 |
# File 'lib/purolator_ruby/create_shipment_request.rb', line 16 def send! send.tap do |resp| if resp.status == :error raise ArgumentError, resp.payload.errors.join(' ') end end end |