Class: DHL::Ecommerce::Manifest
- Defined in:
- lib/dhl/ecommerce/manifest.rb
Instance Attribute Summary collapse
-
#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
Methods inherited from Base
Constructor Details
This class inherits a constructor from DHL::Ecommerce::Base
Instance Attribute Details
#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
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 44 45 46 47 |
# File 'lib/dhl/ecommerce/manifest.rb', line 19 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.ImpbList 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 :get, "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
#file ⇒ Object
15 16 17 |
# File 'lib/dhl/ecommerce/manifest.rb', line 15 def file @base64_decoded_file ||= StringIO.new(Base64.decode64(@file)) end |