Class: DHL::Ecommerce::Manifest
- Defined in:
- lib/dhl/ecommerce/manifest.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#location_id ⇒ Object
Returns the value of attribute location_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Manifest
constructor
A new instance of Manifest.
- #location ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Manifest
Returns a new instance of Manifest.
45 46 47 48 49 50 51 |
# File 'lib/dhl/ecommerce/manifest.rb', line 45 def initialize(attributes = {}) super attributes unless attributes.empty? @file = StringIO.new(Base64.decode64(attributes[:file])) if attributes[:file] unless attributes[:file].is_a? StringIO end end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
4 5 6 |
# File 'lib/dhl/ecommerce/manifest.rb', line 4 def file @file end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/dhl/ecommerce/manifest.rb', line 4 def id @id end |
#location_id ⇒ Object
Returns the value of attribute location_id.
4 5 6 |
# File 'lib/dhl/ecommerce/manifest.rb', line 4 def location_id @location_id end |
Class Method Details
.create(labels) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dhl/ecommerce/manifest.rb', line 15 def self.create(labels) labels.group_by(&:location_id).each.collect do |location_id, location_labels| closeout_id = DHL::Ecommerce.request :get, "https://api.dhlglobalmail.com/v1/{DHL::Ecommerce::Location.resource_name.downcase}s/#{location_id}/closeout/id" location_labels.each_slice(500) do |slice_labels| xml = Builder::XmlMarkup.new xml.instruct! :xml, version: "1.1", encoding: "UTF-8" xml.ImbpList do slice_labels.each do |label| xml.Impb do xml.Construct label.impb.construct xml.Value label.impb.value end end end DHL::Ecommerce.request :post, "https://api.dhlglobalmail.com/v1/{DHL::Ecommerce::Location.resource_name.downcase}s/#{location_id}/closeout/#{closeout_id}" do |request| request.body xml.target! end end response = DHL::Ecommerce.request :post, "https://api.dhlglobalmail.com/v1/{DHL::Ecommerce::Location.resource_name.downcase}s/#{location_id}/closeout/#{closeout_id}" response[:manifest_list][:manifest] = [response[:manifest_list][:manifest]] unless response[:manifest_list][:manifest].is_a? Array response[:manifest_list][:manifest].each.collect do |attributes| new attributes.merge(location_id: location_id) end end.flatten end |
Instance Method Details
#location ⇒ Object
11 12 13 |
# File 'lib/dhl/ecommerce/manifest.rb', line 11 def location @location ||= DHL::Ecommerce::Location.find location_id end |