newgistics 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64dcab77c965fb14c316ac1c00dc5ac9fac14824
4
- data.tar.gz: 6dc6b36a937c9cb77c8cb62b564d5600ae3f6e28
3
+ metadata.gz: 531b711f00ce955b4cd22a6b2e9e9f33faa50506
4
+ data.tar.gz: 611c887de7ba5cdb4989857218b7bfbfdbf82a01
5
5
  SHA512:
6
- metadata.gz: 4aed4d616111d0261f497d74f0f9d1edc3f333069670b896c60ff1afaf0d4b9a74172fedb335af6676fd8617529c7c087fa6d9abb39f32dde00ba2a8004b946c
7
- data.tar.gz: a4480045ea1b18c1915e929996e39df8c3b485d85ef376f8bb53db0c4e49d682590e82a073186e0f9f2e6f7c5d1ea16dd59c1c8faa0f9293f2c54821f5c781fa
6
+ metadata.gz: 566e377c9306a88b8dd218afc100ccfadaa64d4cb4bb467c0c5e12f927dc815764c9786af3393e8bc916e6cb23e128b169835a3d8586dc10768160858280baf7
7
+ data.tar.gz: 7e131edb758105bae9051d639c52bf56d84011b7da67f0765522d03ad0dd98dd0e755e8cbc59ceb39207ded8e946e7e8e30caf16f169b760842ab616f75b2e60
data/README.md CHANGED
@@ -179,7 +179,16 @@ manifest.save
179
179
 
180
180
  `manifest_attributes` is a `Hash` containing all the attributes for the manifest, the attributes should map one-to-one to the Newgistics API spec.
181
181
 
182
- `manifest.save` will return `true` if the manifest is placed successfully and `false` otherwise, any errors or warnings generated when creating the manifest are available under `manifest.errors` and `manifest.warnings` respectively
182
+ `manifest.save` will return `true` if the manifest is placed successfully and `false` otherwise, any errors or warnings generated when creating the manifest are available under `manifest.errors` and `manifest.warnings` respectively.
183
+
184
+ #### Canceling an existing Manifest in Newgistics
185
+
186
+ ```ruby
187
+ manifest = Newgistics::Manifest.new(id: '123456')
188
+ manifest.cancel
189
+ ```
190
+
191
+ `manifest.cancel` will return `true` if the manifest is canceled successfully and `false` otherwise, any errors or warnings generated when cancelling the manifest are available under `manifest.errors` and `manifest.warnings` respectively. The cancel operation only requires the manifest to have an `id`, while other attributes can be set on the `manifest` object, they aren't required for cancelling it.
183
192
 
184
193
 
185
194
  ## Development
data/lib/newgistics.rb CHANGED
@@ -30,6 +30,7 @@ require "newgistics/requests/post_shipment"
30
30
  require "newgistics/requests/post_inbound_return"
31
31
  require "newgistics/requests/search"
32
32
  require "newgistics/requests/post_manifest"
33
+ require "newgistics/requests/cancel_manifest"
33
34
  require "newgistics/requests/update_shipment_contents"
34
35
  require "newgistics/response_handlers/cancel_shipment"
35
36
  require "newgistics/response_handlers/post_shipment"
@@ -38,6 +39,7 @@ require "newgistics/response_handlers/post_errors"
38
39
  require "newgistics/response_handlers/search"
39
40
  require "newgistics/response_handlers/update_shipment_contents"
40
41
  require "newgistics/response_handlers/post_manifest"
42
+ require "newgistics/response_handlers/cancel_manifest"
41
43
  require "newgistics/manifest_item"
42
44
  require "newgistics/manifest_slip"
43
45
  require "newgistics/manifest"
@@ -9,12 +9,19 @@ module Newgistics
9
9
  attribute :warnings, Array[String], default: []
10
10
 
11
11
  def id
12
- manifest_slip&.manifest_id
12
+ read_slip_attribute(:manifest_id)
13
13
  end
14
14
 
15
15
  def id=(id)
16
- self.manifest_slip ||= ManifestSlip.new
17
- manifest_slip.manifest_id = id
16
+ write_slip_attribute(:manifest_id, id)
17
+ end
18
+
19
+ def status
20
+ read_slip_attribute(:status)
21
+ end
22
+
23
+ def status=(status)
24
+ write_slip_attribute(:status, status)
18
25
  end
19
26
 
20
27
  def save
@@ -22,6 +29,11 @@ module Newgistics
22
29
  errors.empty?
23
30
  end
24
31
 
32
+ def cancel
33
+ Requests::CancelManifest.new(self).perform
34
+ errors.empty?
35
+ end
36
+
25
37
  def self.where(conditions)
26
38
  Query.build(
27
39
  endpoint: '/manifests.aspx',
@@ -32,5 +44,16 @@ module Newgistics
32
44
  def self.element_selector
33
45
  'manifest'
34
46
  end
47
+
48
+ private
49
+
50
+ def read_slip_attribute(attribute)
51
+ manifest_slip&.send(attribute)
52
+ end
53
+
54
+ def write_slip_attribute(attribute, value)
55
+ self.manifest_slip ||= ManifestSlip.new
56
+ manifest_slip.send("#{attribute}=", value)
57
+ end
35
58
  end
36
59
  end
@@ -0,0 +1,30 @@
1
+ module Newgistics
2
+ module Requests
3
+ class CancelManifest
4
+ attr_reader :manifest
5
+
6
+ def initialize(manifest, response_handler: nil)
7
+ @manifest = manifest
8
+ @response_handler = response_handler || default_response_handler
9
+ end
10
+
11
+ def path
12
+ '/cancel_manifest.aspx'
13
+ end
14
+
15
+ def body
16
+ { manifestId: manifest.id, key: Newgistics.configuration.api_key }
17
+ end
18
+
19
+ def perform
20
+ Newgistics.api.get(self, @response_handler)
21
+ end
22
+
23
+ private
24
+
25
+ def default_response_handler
26
+ ResponseHandlers::CancelManifest.new(manifest)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,16 @@
1
+ module Newgistics
2
+ module ResponseHandlers
3
+ class CancelManifest
4
+ attr_reader :manifest
5
+
6
+ def initialize(manifest)
7
+ @manifest = manifest
8
+ end
9
+
10
+ def handle(response)
11
+ PostErrors.new(manifest).handle(response)
12
+ manifest.status = 'CANCELED' if manifest.errors.empty?
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module Newgistics
2
- VERSION = "2.0.2"
2
+ VERSION = "2.1.0"
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.0.2
4
+ version: 2.1.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: 2018-09-25 00:00:00.000000000 Z
12
+ date: 2018-10-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: virtus
@@ -218,12 +218,14 @@ files:
218
218
  - lib/newgistics/order.rb
219
219
  - lib/newgistics/product.rb
220
220
  - lib/newgistics/query.rb
221
+ - lib/newgistics/requests/cancel_manifest.rb
221
222
  - lib/newgistics/requests/cancel_shipment.rb
222
223
  - lib/newgistics/requests/post_inbound_return.rb
223
224
  - lib/newgistics/requests/post_manifest.rb
224
225
  - lib/newgistics/requests/post_shipment.rb
225
226
  - lib/newgistics/requests/search.rb
226
227
  - lib/newgistics/requests/update_shipment_contents.rb
228
+ - lib/newgistics/response_handlers/cancel_manifest.rb
227
229
  - lib/newgistics/response_handlers/cancel_shipment.rb
228
230
  - lib/newgistics/response_handlers/post_errors.rb
229
231
  - lib/newgistics/response_handlers/post_inbound_return.rb