Class: DJI::DHL::Shipment

Inherits:
Object
  • Object
show all
Defined in:
lib/dji/dhl/shipment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeShipment

Returns a new instance of Shipment.



18
19
20
# File 'lib/dji/dhl/shipment.rb', line 18

def initialize
  @checkpoints = []
end

Instance Attribute Details

#checkpointsObject

Returns the value of attribute checkpoints.



15
16
17
# File 'lib/dji/dhl/shipment.rb', line 15

def checkpoints
  @checkpoints
end

#delivery_codeObject

Returns the value of attribute delivery_code.



11
12
13
# File 'lib/dji/dhl/shipment.rb', line 11

def delivery_code
  @delivery_code
end

#delivery_statusObject

Returns the value of attribute delivery_status.



11
12
13
# File 'lib/dji/dhl/shipment.rb', line 11

def delivery_status
  @delivery_status
end

#destinationObject

Returns the value of attribute destination.



12
13
14
# File 'lib/dji/dhl/shipment.rb', line 12

def destination
  @destination
end

#destination_cityObject

Returns the value of attribute destination_city.



14
15
16
# File 'lib/dji/dhl/shipment.rb', line 14

def destination_city
  @destination_city
end

#destination_countryObject

Returns the value of attribute destination_country.



14
15
16
# File 'lib/dji/dhl/shipment.rb', line 14

def destination_country
  @destination_country
end

#destination_regionObject

Returns the value of attribute destination_region.



14
15
16
# File 'lib/dji/dhl/shipment.rb', line 14

def destination_region
  @destination_region
end

#estimated_delivery_dateObject

Returns the value of attribute estimated_delivery_date.



16
17
18
# File 'lib/dji/dhl/shipment.rb', line 16

def estimated_delivery_date
  @estimated_delivery_date
end

#estimated_delivery_productObject

Returns the value of attribute estimated_delivery_product.



16
17
18
# File 'lib/dji/dhl/shipment.rb', line 16

def estimated_delivery_product
  @estimated_delivery_product
end

#originObject

Returns the value of attribute origin.



12
13
14
# File 'lib/dji/dhl/shipment.rb', line 12

def origin
  @origin
end

#origin_cityObject

Returns the value of attribute origin_city.



13
14
15
# File 'lib/dji/dhl/shipment.rb', line 13

def origin_city
  @origin_city
end

#origin_countryObject

Returns the value of attribute origin_country.



13
14
15
# File 'lib/dji/dhl/shipment.rb', line 13

def origin_country
  @origin_country
end

#origin_regionObject

Returns the value of attribute origin_region.



13
14
15
# File 'lib/dji/dhl/shipment.rb', line 13

def origin_region
  @origin_region
end

#waybillObject

Returns the value of attribute waybill.



10
11
12
# File 'lib/dji/dhl/shipment.rb', line 10

def waybill
  @waybill
end

Class Method Details

.new_from_item(item) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/dji/dhl/shipment.rb', line 39

def new_from_item(item)
  puts item.inspect
  shipment                 = Shipment.new
  shipment.waybill         = item['id']
  if item['delivery'].present?
    shipment.delivery_code   = item['delivery']['code']
    shipment.delivery_status = item['delivery']['status']
  end
  shipment.destination     = item['destination']['value']
  shipment.origin          = item['origin']['value']
  if item['edd'].present?
    shipment.estimated_delivery_date = Date.parse(item['edd']['date'])
    shipment.estimated_delivery_product = item['edd']['product']
  end

  item['checkpoints'].each do |item|
    checkpoint = Checkpoint.new_from_item(item)
    shipment.checkpoints << checkpoint
  end

  shipment
end

Instance Method Details

#delivered_atObject



22
23
24
25
# File 'lib/dji/dhl/shipment.rb', line 22

def delivered_at
  puts checkpoints.first.inspect
  checkpoints.first.datetime if delivery_status == 'delivered'
end