gun_broker 1.4.3 → 1.4.4

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: 1476980635cd1ec420f1a8dcc47d606f0d14880b
4
- data.tar.gz: 68c93bfe39aba2cc4018a7487ff9cf86d71cdde4
3
+ metadata.gz: 347f961fc6d333472e7ed636d8efffc6d32ddcd2
4
+ data.tar.gz: 39281a14096480b8af69bff867da86c924d04df7
5
5
  SHA512:
6
- metadata.gz: db55a3b5837fe047e13a9da6e64b0bf57d28accdf350c9851e30b02260263cbddc67fac434869e1459fc731c27ffbc6a7ec9b6e50eb0aeee35da5c608305c16d
7
- data.tar.gz: 7d949f1b850fb68c85b4f9dac86486ee5a193d7bfc530f6aacf746f56f0b87226ea396eee1158e82da7af048ba7d73e9143cf9dec73a17aa86724a9e5b48ba11
6
+ metadata.gz: 487335ffc8f42a330cd94a9dffd4e0bbc732bc00a4082cdefe894f516a77788f793cffc66a0c32d65f370d3b4e0a71a6d235538549f70378abfb9767fe4aff75
7
+ data.tar.gz: 1d2530240790e86fbf4cc1024997a261f1b953f176d6ea6d3c0e3a6dae5c91fab18a589b9a2360c74350b33708d9bfa4c752c76d92616fb82bcdb22c536d9ae7
@@ -93,6 +93,14 @@ module GunBroker
93
93
  16 => 'Use shipping profile',
94
94
  }
95
95
 
96
+ # The carrier responsible for shipping.
97
+ # The keys of this hash should be sent as the `carrier` param when updating shipping on an Item.
98
+ SHIPPING_CARRIERS = {
99
+ 1 => 'FedEx',
100
+ 2 => 'UPS',
101
+ 3 => 'USPS',
102
+ }
103
+
96
104
  end
97
105
  end
98
106
  end
@@ -1,4 +1,5 @@
1
1
  require 'gun_broker/token_header'
2
+ require 'gun_broker/item/constants'
2
3
 
3
4
  module GunBroker
4
5
  class User
@@ -6,6 +7,7 @@ module GunBroker
6
7
  class OrdersDelegate
7
8
 
8
9
  include GunBroker::TokenHeader
10
+ include GunBroker::Item::Constants
9
11
 
10
12
  # @param user [User] A {User} instance to scope orders by.
11
13
  def initialize(user)
@@ -41,6 +43,33 @@ module GunBroker
41
43
  @sold ||= fetch_orders(:OrdersSold, params)
42
44
  end
43
45
 
46
+ # Submits shipping details for an {Order}.
47
+ # @param (see #submit_shipping!)
48
+ # @return [GunBroker::Order] The updated Order instance or `false` if update fails.
49
+ def submit_shipping(*args)
50
+ submit_shipping!(*args)
51
+ rescue GunBroker::Error
52
+ false
53
+ end
54
+
55
+ # Same as {#submit_shipping} but raises exceptions on error.
56
+ # @param order_id [Integer, String] ID of the Order to update.
57
+ # @param tracking_number [String] The tracking number of the shipment.
58
+ # @param carrier_name [String] The name of the carrier of the shipment.
59
+ # @raise [GunBroker::Error::NotAuthorized] If the {User#token `@user` token} isn't valid.
60
+ # @raise [GunBroker::Error::RequestError] If the Order attributes are not valid or required attributes are missing.
61
+ # @return [GunBroker::Order] The updated Order instance.
62
+ def submit_shipping!(order_id, tracking_number, carrier_name)
63
+ carrier_key = SHIPPING_CARRIERS.find { |k, v| v.casecmp(carrier_name).zero? }.try(:first)
64
+ params = {
65
+ 'TrackingNumber' => tracking_number,
66
+ 'Carrier' => carrier_key,
67
+ }
68
+
69
+ GunBroker::API.put("/Orders/#{order_id}/Shipping", cleanup_nil_params(params), token_header(@user.token))
70
+ find!(order_id)
71
+ end
72
+
44
73
  private
45
74
 
46
75
  def fetch_orders(endpoint, params = {})
@@ -1,3 +1,3 @@
1
1
  module GunBroker
2
- VERSION = "1.4.3"
2
+ VERSION = "1.4.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gun_broker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.3
4
+ version: 1.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dale Campbell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-05 00:00:00.000000000 Z
11
+ date: 2018-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler