Class: Apruve::Shipment
- Inherits:
-
ApruveObject
- Object
- ApruveObject
- Apruve::Shipment
- Defined in:
- lib/apruve/resources/shipment.rb
Instance Attribute Summary collapse
-
#amount_cents ⇒ Object
Returns the value of attribute amount_cents.
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#delivered_at ⇒ Object
Returns the value of attribute delivered_at.
-
#id ⇒ Object
Returns the value of attribute id.
-
#invoice_id ⇒ Object
Returns the value of attribute invoice_id.
-
#merchant_notes ⇒ Object
Returns the value of attribute merchant_notes.
-
#merchant_shipment_id ⇒ Object
Returns the value of attribute merchant_shipment_id.
-
#shipment_items ⇒ Object
Returns the value of attribute shipment_items.
-
#shipped_at ⇒ Object
Returns the value of attribute shipped_at.
-
#shipper ⇒ Object
Returns the value of attribute shipper.
-
#shipping_cents ⇒ Object
Returns the value of attribute shipping_cents.
-
#status ⇒ Object
Returns the value of attribute status.
-
#tax_cents ⇒ Object
Returns the value of attribute tax_cents.
-
#tracking_number ⇒ Object
Returns the value of attribute tracking_number.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params) ⇒ Shipment
constructor
A new instance of Shipment.
- #save! ⇒ Object
- #update! ⇒ Object
- #validate ⇒ Object
Methods inherited from ApruveObject
#logger, logger, #to_hash, #to_json
Constructor Details
#initialize(params) ⇒ Shipment
Returns a new instance of Shipment.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/apruve/resources/shipment.rb', line 18 def initialize(params) super # hydrate payment items if appropriate if @shipment_items.nil? @shipment_items = [] elsif @shipment_items.is_a?(Array) && @shipment_items.first.is_a?(Hash) hydrated_items = [] @shipment_items.each do |item| hydrated_items << Apruve::ShipmentItem.new(item) end @shipment_items = hydrated_items end @currency = Apruve.default_currency if currency.nil? end |
Instance Attribute Details
#amount_cents ⇒ Object
Returns the value of attribute amount_cents.
3 4 5 |
# File 'lib/apruve/resources/shipment.rb', line 3 def amount_cents @amount_cents end |
#currency ⇒ Object
Returns the value of attribute currency.
3 4 5 |
# File 'lib/apruve/resources/shipment.rb', line 3 def currency @currency end |
#delivered_at ⇒ Object
Returns the value of attribute delivered_at.
3 4 5 |
# File 'lib/apruve/resources/shipment.rb', line 3 def delivered_at @delivered_at end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/apruve/resources/shipment.rb', line 3 def id @id end |
#invoice_id ⇒ Object
Returns the value of attribute invoice_id.
3 4 5 |
# File 'lib/apruve/resources/shipment.rb', line 3 def invoice_id @invoice_id end |
#merchant_notes ⇒ Object
Returns the value of attribute merchant_notes.
3 4 5 |
# File 'lib/apruve/resources/shipment.rb', line 3 def merchant_notes @merchant_notes end |
#merchant_shipment_id ⇒ Object
Returns the value of attribute merchant_shipment_id.
3 4 5 |
# File 'lib/apruve/resources/shipment.rb', line 3 def merchant_shipment_id @merchant_shipment_id end |
#shipment_items ⇒ Object
Returns the value of attribute shipment_items.
3 4 5 |
# File 'lib/apruve/resources/shipment.rb', line 3 def shipment_items @shipment_items end |
#shipped_at ⇒ Object
Returns the value of attribute shipped_at.
3 4 5 |
# File 'lib/apruve/resources/shipment.rb', line 3 def shipped_at @shipped_at end |
#shipper ⇒ Object
Returns the value of attribute shipper.
3 4 5 |
# File 'lib/apruve/resources/shipment.rb', line 3 def shipper @shipper end |
#shipping_cents ⇒ Object
Returns the value of attribute shipping_cents.
3 4 5 |
# File 'lib/apruve/resources/shipment.rb', line 3 def shipping_cents @shipping_cents end |
#status ⇒ Object
Returns the value of attribute status.
3 4 5 |
# File 'lib/apruve/resources/shipment.rb', line 3 def status @status end |
#tax_cents ⇒ Object
Returns the value of attribute tax_cents.
3 4 5 |
# File 'lib/apruve/resources/shipment.rb', line 3 def tax_cents @tax_cents end |
#tracking_number ⇒ Object
Returns the value of attribute tracking_number.
3 4 5 |
# File 'lib/apruve/resources/shipment.rb', line 3 def tracking_number @tracking_number end |
Class Method Details
.find(invoice_id, id) ⇒ Object
7 8 9 10 |
# File 'lib/apruve/resources/shipment.rb', line 7 def self.find(invoice_id, id) response = Apruve.get("invoices/#{invoice_id}/shipments/#{id}") Shipment.new(response.body) end |
.find_all(invoice_id) ⇒ Object
12 13 14 15 16 |
# File 'lib/apruve/resources/shipment.rb', line 12 def self.find_all(invoice_id) response = Apruve.get("invoices/#{invoice_id}/shipments") logger.debug response.body response.body.map { |shipment| Shipment.new(shipment) } end |
Instance Method Details
#save! ⇒ Object
39 40 41 42 43 |
# File 'lib/apruve/resources/shipment.rb', line 39 def save! validate response = Apruve.post("invoices/#{self.invoice_id}/shipments", self.to_json) self.id = response.body['id'] end |
#update! ⇒ Object
45 46 47 48 |
# File 'lib/apruve/resources/shipment.rb', line 45 def update! validate Apruve.patch("invoices/#{self.invoice_id}/shipments/#{id}", self.to_json) end |
#validate ⇒ Object
33 34 35 36 37 |
# File 'lib/apruve/resources/shipment.rb', line 33 def validate errors = [] errors << 'invoice_id must be set' if invoice_id.nil? raise Apruve::ValidationError.new(errors) if errors.length > 0 end |