newgistics 2.3.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c0335cf92de05483074262a2aa46718a9b233cd
4
- data.tar.gz: 338ae379bbc0bad06091476890e6a8a80562f986
3
+ metadata.gz: b9c1f08cf89a001dd497f70997128e207d4fccc3
4
+ data.tar.gz: ffbf57d283b076a5fdfcd2b3859deb6e77260c48
5
5
  SHA512:
6
- metadata.gz: b2e93ae697d6d3625c6f5f562e6502d1c18f78e65fd5045419bc2686acee06440ee3e7bd3f9870669e4173c0af98bd336e1a4de48a97d4b2c7c384f4c98584dc
7
- data.tar.gz: 7c369439d2f000e045e38a683783490b7edf9d60f44134ed758fbae2d9a2a44a684f0b903b9954926ce16aa9029b32cc5b7b6e4a98955a749632ddb676f64e84
6
+ metadata.gz: ef9f20d382e4e78ffecadf41c99fd618a4c23cf9976b2b08b34c7b87fd5f27da0dc7b21b9a908a75c5737a17ca09752a9254defeb2df7bf7e3c9d152fa394ae5
7
+ data.tar.gz: b79656c7ab47c26c4ddb5401f8e67d5bda8fca6ddf6a2780f48e69190b4ab6ca3641d0794128c61ecadf6db22348e79149f0ca3e3e024c0533d25f05e4bc91c5
data/README.md CHANGED
@@ -71,6 +71,16 @@ shipment_update.save
71
71
 
72
72
  `shipment_update.save` will return `true` if the order is updated successfully and `false` otherwise, any errors or warnings generated when updating the shipment are available under `shipment_update.errors` and `shipment_update.warnings` respectively. `shipment_update.success` or also `shipment_update.success?` will also be updated to the corresponding value.
73
73
 
74
+ #### Updating a shipment's address in Newgistics
75
+ ```ruby
76
+ address_update = Newgistics::ShipmentAddressUpdate.new(update_attributes)
77
+ address_update.save
78
+ ```
79
+
80
+ `update_attributes` is a `Hash` with the updates you want to perform on the shipment, for a list of available attributes you can look at the [Newgistics::ShipmentAddressUpdate model](lib/newgistics/shipment_address_update.rb)
81
+
82
+ `address_update.save` will return `true` if the shipment is updated successfully and `false` otherwise, any errors or warnings generated when updating the shipment are available under `address_update.errors` and `address_update.warnings` respectively. `address_update.success` or also `address_update.success?` will also be updated to the corresponding value.
83
+
74
84
  #### Cancelling a shipment/order on Newgistics
75
85
  ```ruby
76
86
  shipment_cancellation = Newgistics::ShipmentCancellation.new(shipment_id: SHIPMENT_ID)
@@ -25,6 +25,7 @@ require "newgistics/query"
25
25
  require "newgistics/errors"
26
26
  require "newgistics/string_helper"
27
27
  require "newgistics/shipment_cancellation"
28
+ require "newgistics/shipment_address_update"
28
29
  require "newgistics/shipment_update"
29
30
  require "newgistics/warehouse"
30
31
  require "newgistics/requests/cancel_shipment"
@@ -33,12 +34,14 @@ require "newgistics/requests/post_inbound_return"
33
34
  require "newgistics/requests/search"
34
35
  require "newgistics/requests/post_manifest"
35
36
  require "newgistics/requests/cancel_manifest"
37
+ require "newgistics/requests/update_shipment_address"
36
38
  require "newgistics/requests/update_shipment_contents"
37
39
  require "newgistics/response_handlers/cancel_shipment"
38
40
  require "newgistics/response_handlers/post_shipment"
39
41
  require "newgistics/response_handlers/post_inbound_return"
40
42
  require "newgistics/response_handlers/post_errors"
41
43
  require "newgistics/response_handlers/search"
44
+ require "newgistics/response_handlers/update_shipment_address"
42
45
  require "newgistics/response_handlers/update_shipment_contents"
43
46
  require "newgistics/response_handlers/post_manifest"
44
47
  require "newgistics/response_handlers/cancel_manifest"
@@ -0,0 +1,69 @@
1
+ module Newgistics
2
+ module Requests
3
+ class UpdateShipmentAddress
4
+ attr_reader :shipment_address_update, :response_handler
5
+
6
+ def initialize(shipment_address_update, response_handler: nil)
7
+ @shipment_address_update = shipment_address_update
8
+ @response_handler = response_handler || default_response_handler
9
+ end
10
+
11
+ def path
12
+ '/update_shipment_address.aspx'
13
+ end
14
+
15
+ def body
16
+ xml_builder.to_xml
17
+ end
18
+
19
+ def perform
20
+ Newgistics.api.post(self, response_handler)
21
+ end
22
+
23
+ private
24
+
25
+ def default_response_handler
26
+ ResponseHandlers::UpdateShipmentAddress.new(shipment_address_update)
27
+ end
28
+
29
+ def xml_builder
30
+ Nokogiri::XML::Builder.new do |xml|
31
+ shipment_address_update_xml(xml)
32
+ end
33
+ end
34
+
35
+ def shipment_address_update_xml(xml)
36
+ xml.updateShipment(shipment_address_update_attributes) do
37
+ xml.FirstName shipment_address_update.first_name
38
+ xml.LastName shipment_address_update.last_name
39
+ xml.Company shipment_address_update.company
40
+ xml.Address1 shipment_address_update.address1
41
+ xml.Address2 shipment_address_update.address2
42
+ xml.City shipment_address_update.city
43
+ xml.State shipment_address_update.state
44
+ xml.PostalCode shipment_address_update.postal_code
45
+ xml.Country shipment_address_update.country
46
+ xml.Email shipment_address_update.email
47
+ xml.Phone shipment_address_update.phone
48
+ xml.Fax shipment_address_update.fax
49
+ xml.IsResidential shipment_address_update.is_residential
50
+ xml.Status shipment_address_update.status
51
+ xml.StatusNotes shipment_address_update.status_notes
52
+ xml.ShipMethod shipment_address_update.ship_method
53
+ end
54
+ end
55
+
56
+ def api_key
57
+ Newgistics.configuration.api_key
58
+ end
59
+
60
+ def shipment_address_update_attributes
61
+ {
62
+ apiKey: api_key,
63
+ id: shipment_address_update.id,
64
+ orderID: shipment_address_update.order_id
65
+ }.reject { |_k, v| v.nil? || v.empty? }
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,25 @@
1
+ module Newgistics
2
+ module ResponseHandlers
3
+ class UpdateShipmentAddress
4
+ attr_reader :shipment_address_update
5
+
6
+ def initialize(shipment_address_update)
7
+ @shipment_address_update = shipment_address_update
8
+ end
9
+
10
+ def handle(response)
11
+ PostErrors.new(shipment_address_update).handle(response)
12
+ if shipment_address_update.errors.empty?
13
+ handle_successful_response(response)
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def handle_successful_response(response)
20
+ xml = Nokogiri::XML(response.body)
21
+ shipment_address_update.success = xml.at_css('success').text
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,39 @@
1
+ module Newgistics
2
+ class ShipmentAddressUpdate
3
+ include Newgistics::Model
4
+
5
+ attribute :id, String
6
+ attribute :order_id, String
7
+
8
+ attribute :company, String
9
+ attribute :first_name, String
10
+ attribute :last_name, String
11
+ attribute :address1, String
12
+ attribute :address2, String
13
+ attribute :city, String
14
+ attribute :state, String
15
+ attribute :postal_code, String
16
+ attribute :country, String
17
+ attribute :email, String
18
+ attribute :phone, String
19
+ attribute :fax, String
20
+ attribute :is_residential, Boolean
21
+
22
+ attribute :status, String
23
+ attribute :status_notes, String
24
+ attribute :ship_method, String
25
+
26
+ attribute :success, Boolean
27
+ attribute :errors, Array[String], default: []
28
+ attribute :warnings, Array[String], default: []
29
+
30
+ def success?
31
+ !!success
32
+ end
33
+
34
+ def save
35
+ Requests::UpdateShipmentAddress.new(self).perform
36
+ errors.empty? && success?
37
+ end
38
+ end
39
+ end
@@ -1,3 +1,3 @@
1
1
  module Newgistics
2
- VERSION = "2.3.0"
2
+ VERSION = "2.4.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: newgistics
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Martinez
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-01-10 00:00:00.000000000 Z
12
+ date: 2019-05-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: virtus
@@ -226,6 +226,7 @@ files:
226
226
  - lib/newgistics/requests/post_manifest.rb
227
227
  - lib/newgistics/requests/post_shipment.rb
228
228
  - lib/newgistics/requests/search.rb
229
+ - lib/newgistics/requests/update_shipment_address.rb
229
230
  - lib/newgistics/requests/update_shipment_contents.rb
230
231
  - lib/newgistics/response_handlers/cancel_manifest.rb
231
232
  - lib/newgistics/response_handlers/cancel_shipment.rb
@@ -234,9 +235,11 @@ files:
234
235
  - lib/newgistics/response_handlers/post_manifest.rb
235
236
  - lib/newgistics/response_handlers/post_shipment.rb
236
237
  - lib/newgistics/response_handlers/search.rb
238
+ - lib/newgistics/response_handlers/update_shipment_address.rb
237
239
  - lib/newgistics/response_handlers/update_shipment_contents.rb
238
240
  - lib/newgistics/return.rb
239
241
  - lib/newgistics/shipment.rb
242
+ - lib/newgistics/shipment_address_update.rb
240
243
  - lib/newgistics/shipment_cancellation.rb
241
244
  - lib/newgistics/shipment_update.rb
242
245
  - lib/newgistics/string_helper.rb