shipwire 0.0.5 → 2.0.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 +4 -4
- data/.gitignore +3 -3
- data/.rspec +2 -0
- data/.ruby-version +1 -1
- data/Gemfile +0 -1
- data/README.md +53 -29
- data/Rakefile +2 -3
- data/lib/generators/shipwire/install/install_generator.rb +13 -0
- data/lib/generators/shipwire/install/templates/config/initializers/shipwire.rb +27 -0
- data/lib/shipwire.rb +26 -33
- data/lib/shipwire/api.rb +7 -0
- data/lib/shipwire/configuration.rb +13 -3
- data/lib/shipwire/orders.rb +39 -0
- data/lib/shipwire/param_converter.rb +39 -0
- data/lib/shipwire/products.rb +53 -0
- data/lib/shipwire/products/base.rb +9 -0
- data/lib/shipwire/products/insert.rb +9 -0
- data/lib/shipwire/products/kit.rb +9 -0
- data/lib/shipwire/products/virtual_kit.rb +9 -0
- data/lib/shipwire/rate.rb +7 -0
- data/lib/shipwire/receivings.rb +50 -0
- data/lib/shipwire/request.rb +73 -0
- data/lib/shipwire/response.rb +79 -0
- data/lib/shipwire/returns.rb +35 -0
- data/lib/shipwire/secret.rb +20 -0
- data/lib/shipwire/stock.rb +7 -0
- data/lib/shipwire/utility.rb +22 -0
- data/lib/shipwire/version.rb +1 -1
- data/lib/shipwire/webhooks.rb +24 -0
- data/shipwire.gemspec +12 -15
- data/spec/features/access_spec.rb +61 -0
- data/spec/features/orders_spec.rb +280 -0
- data/spec/features/product_types_spec.rb +219 -0
- data/spec/features/products_spec.rb +282 -0
- data/spec/features/rate_spec.rb +50 -0
- data/spec/features/receivings_spec.rb +333 -0
- data/spec/features/returns_spec.rb +239 -0
- data/spec/features/secret_spec.rb +57 -0
- data/spec/features/stock_spec.rb +41 -0
- data/spec/features/webhooks_spec.rb +106 -0
- data/spec/spec_helper.rb +33 -12
- data/spec/support/shipwire.rb +10 -0
- data/spec/support/vcr.rb +9 -0
- data/spec/support/vcr_cassettes/credentials_incorrect.yml +47 -0
- data/spec/support/vcr_cassettes/credentials_missing.yml +47 -0
- data/spec/support/vcr_cassettes/order.yml +48 -0
- data/spec/support/vcr_cassettes/order_cancel.yml +54 -0
- data/spec/support/vcr_cassettes/order_cancel_fail.yml +47 -0
- data/spec/support/vcr_cassettes/order_find.yml +45 -0
- data/spec/support/vcr_cassettes/order_find_fail.yml +45 -0
- data/spec/support/vcr_cassettes/order_find_with_params.yml +45 -0
- data/spec/support/vcr_cassettes/order_holds.yml +50 -0
- data/spec/support/vcr_cassettes/order_holds_fail.yml +45 -0
- data/spec/support/vcr_cassettes/order_holds_with_params.yml +50 -0
- data/spec/support/vcr_cassettes/order_items.yml +45 -0
- data/spec/support/vcr_cassettes/order_items_fail.yml +45 -0
- data/spec/support/vcr_cassettes/order_returns.yml +47 -0
- data/spec/support/vcr_cassettes/order_returns_fail.yml +47 -0
- data/spec/support/vcr_cassettes/order_trackings.yml +45 -0
- data/spec/support/vcr_cassettes/order_trackings_fail.yml +45 -0
- data/spec/support/vcr_cassettes/order_update.yml +48 -0
- data/spec/support/vcr_cassettes/order_update_fail.yml +50 -0
- data/spec/support/vcr_cassettes/order_update_with_params.yml +48 -0
- data/spec/support/vcr_cassettes/order_with_warnings.yml +96 -0
- data/spec/support/vcr_cassettes/orders_list.yml +47 -0
- data/spec/support/vcr_cassettes/orders_list_with_params.yml +47 -0
- data/spec/support/vcr_cassettes/product.yml +48 -0
- data/spec/support/vcr_cassettes/product_base.yml +48 -0
- data/spec/support/vcr_cassettes/product_base_find.yml +48 -0
- data/spec/support/vcr_cassettes/product_base_find_fail.yml +47 -0
- data/spec/support/vcr_cassettes/product_base_retire_id.yml +47 -0
- data/spec/support/vcr_cassettes/product_base_retire_nonexistent.yml +47 -0
- data/spec/support/vcr_cassettes/product_base_update.yml +48 -0
- data/spec/support/vcr_cassettes/product_base_update_fail.yml +48 -0
- data/spec/support/vcr_cassettes/product_create_fail_with_invalid_classification.yml +51 -0
- data/spec/support/vcr_cassettes/product_find.yml +48 -0
- data/spec/support/vcr_cassettes/product_find_fail.yml +47 -0
- data/spec/support/vcr_cassettes/product_insert.yml +50 -0
- data/spec/support/vcr_cassettes/product_insert_find.yml +48 -0
- data/spec/support/vcr_cassettes/product_insert_find_fail.yml +47 -0
- data/spec/support/vcr_cassettes/product_insert_retire_id.yml +47 -0
- data/spec/support/vcr_cassettes/product_insert_retire_nonexistent.yml +47 -0
- data/spec/support/vcr_cassettes/product_insert_update.yml +49 -0
- data/spec/support/vcr_cassettes/product_insert_update_fail.yml +48 -0
- data/spec/support/vcr_cassettes/product_kit.yml +48 -0
- data/spec/support/vcr_cassettes/product_kit_find.yml +48 -0
- data/spec/support/vcr_cassettes/product_kit_find_fail.yml +47 -0
- data/spec/support/vcr_cassettes/product_kit_retire_id.yml +47 -0
- data/spec/support/vcr_cassettes/product_kit_retire_nonexistent.yml +47 -0
- data/spec/support/vcr_cassettes/product_kit_update.yml +48 -0
- data/spec/support/vcr_cassettes/product_kit_update_fail.yml +47 -0
- data/spec/support/vcr_cassettes/product_multiple_create_fail.yml +102 -0
- data/spec/support/vcr_cassettes/product_multiple_create_success.yml +100 -0
- data/spec/support/vcr_cassettes/product_retire_id.yml +47 -0
- data/spec/support/vcr_cassettes/product_retire_nonexistent.yml +47 -0
- data/spec/support/vcr_cassettes/product_update.yml +48 -0
- data/spec/support/vcr_cassettes/product_update_fail.yml +48 -0
- data/spec/support/vcr_cassettes/product_virtual_kit.yml +48 -0
- data/spec/support/vcr_cassettes/product_virtual_kit_find.yml +48 -0
- data/spec/support/vcr_cassettes/product_virtual_kit_find_fail.yml +47 -0
- data/spec/support/vcr_cassettes/product_virtual_kit_retire_id.yml +47 -0
- data/spec/support/vcr_cassettes/product_virtual_kit_retire_nonexistent.yml +47 -0
- data/spec/support/vcr_cassettes/product_virtual_kit_update.yml +49 -0
- data/spec/support/vcr_cassettes/product_virtual_kit_update_fail.yml +47 -0
- data/spec/support/vcr_cassettes/products_base_list.yml +49 -0
- data/spec/support/vcr_cassettes/products_base_list_with_params.yml +49 -0
- data/spec/support/vcr_cassettes/products_insert_list.yml +47 -0
- data/spec/support/vcr_cassettes/products_insert_list_with_params.yml +47 -0
- data/spec/support/vcr_cassettes/products_kit_list.yml +47 -0
- data/spec/support/vcr_cassettes/products_kit_list_with_params.yml +47 -0
- data/spec/support/vcr_cassettes/products_list.yml +49 -0
- data/spec/support/vcr_cassettes/products_list_with_params.yml +49 -0
- data/spec/support/vcr_cassettes/products_virtual_kit_list.yml +47 -0
- data/spec/support/vcr_cassettes/products_virtual_kit_list_with_params.yml +47 -0
- data/spec/support/vcr_cassettes/rate_find.yml +53 -0
- data/spec/support/vcr_cassettes/rate_find_fail.yml +50 -0
- data/spec/support/vcr_cassettes/receiving.yml +53 -0
- data/spec/support/vcr_cassettes/receiving_cancel.yml +98 -0
- data/spec/support/vcr_cassettes/receiving_cancel_label.yml +47 -0
- data/spec/support/vcr_cassettes/receiving_cancel_label_nonexistent.yml +47 -0
- data/spec/support/vcr_cassettes/receiving_find.yml +46 -0
- data/spec/support/vcr_cassettes/receiving_find_fail.yml +45 -0
- data/spec/support/vcr_cassettes/receiving_find_with_params.yml +48 -0
- data/spec/support/vcr_cassettes/receiving_holds.yml +47 -0
- data/spec/support/vcr_cassettes/receiving_holds_fail.yml +45 -0
- data/spec/support/vcr_cassettes/receiving_holds_with_params.yml +47 -0
- data/spec/support/vcr_cassettes/receiving_instructions_recipients.yml +45 -0
- data/spec/support/vcr_cassettes/receiving_instructions_recipients_fail.yml +45 -0
- data/spec/support/vcr_cassettes/receiving_items.yml +45 -0
- data/spec/support/vcr_cassettes/receiving_items_fail.yml +45 -0
- data/spec/support/vcr_cassettes/receiving_shipments.yml +45 -0
- data/spec/support/vcr_cassettes/receiving_shipments_fail.yml +45 -0
- data/spec/support/vcr_cassettes/receiving_tracking.yml +45 -0
- data/spec/support/vcr_cassettes/receiving_tracking_fail.yml +45 -0
- data/spec/support/vcr_cassettes/receiving_update.yml +53 -0
- data/spec/support/vcr_cassettes/receiving_update_fail.yml +49 -0
- data/spec/support/vcr_cassettes/receiving_update_with_params.yml +55 -0
- data/spec/support/vcr_cassettes/receivings_list.yml +53 -0
- data/spec/support/vcr_cassettes/receivings_list_with_params.yml +46 -0
- data/spec/support/vcr_cassettes/return.yml +98 -0
- data/spec/support/vcr_cassettes/return_cancel.yml +55 -0
- data/spec/support/vcr_cassettes/return_cancel_fail.yml +47 -0
- data/spec/support/vcr_cassettes/return_find.yml +47 -0
- data/spec/support/vcr_cassettes/return_find_fail.yml +45 -0
- data/spec/support/vcr_cassettes/return_find_with_params.yml +47 -0
- data/spec/support/vcr_cassettes/return_holds.yml +45 -0
- data/spec/support/vcr_cassettes/return_holds_fail.yml +45 -0
- data/spec/support/vcr_cassettes/return_holds_with_params.yml +45 -0
- data/spec/support/vcr_cassettes/return_items.yml +45 -0
- data/spec/support/vcr_cassettes/return_items_fail.yml +45 -0
- data/spec/support/vcr_cassettes/return_labels.yml +45 -0
- data/spec/support/vcr_cassettes/return_labels_fail.yml +45 -0
- data/spec/support/vcr_cassettes/return_trackings.yml +45 -0
- data/spec/support/vcr_cassettes/return_trackings_fail.yml +45 -0
- data/spec/support/vcr_cassettes/returns_list.yml +47 -0
- data/spec/support/vcr_cassettes/returns_list_with_params.yml +47 -0
- data/spec/support/vcr_cassettes/secret.yml +47 -0
- data/spec/support/vcr_cassettes/secret_find.yml +45 -0
- data/spec/support/vcr_cassettes/secret_find_fail.yml +43 -0
- data/spec/support/vcr_cassettes/secret_list.yml +45 -0
- data/spec/support/vcr_cassettes/secret_remove.yml +45 -0
- data/spec/support/vcr_cassettes/stock_with_params.yml +45 -0
- data/spec/support/vcr_cassettes/stock_with_params_no_sku.yml +45 -0
- data/spec/support/vcr_cassettes/stock_without_params.yml +45 -0
- data/spec/support/vcr_cassettes/webhook.yml +47 -0
- data/spec/support/vcr_cassettes/webhooks_create_insecure.yml +50 -0
- data/spec/support/vcr_cassettes/webhooks_find.yml +47 -0
- data/spec/support/vcr_cassettes/webhooks_find_fail.yml +47 -0
- data/spec/support/vcr_cassettes/webhooks_list.yml +47 -0
- data/spec/support/vcr_cassettes/webhooks_remove.yml +47 -0
- data/spec/support/vcr_cassettes/webhooks_update.yml +47 -0
- data/spec/support/vcr_cassettes/webhooks_update_fail.yml +49 -0
- data/spec/unit/shipwire/response_spec.rb +46 -0
- metadata +354 -80
- data/.env +0 -4
- data/.env.example +0 -4
- data/Gemfile.lock +0 -69
- data/lib/shipwire/fulfillment.rb +0 -100
- data/lib/shipwire/inventory.rb +0 -72
- data/lib/shipwire/service_request.rb +0 -42
- data/lib/shipwire/shipping_rate.rb +0 -121
- data/lib/shipwire/tracking.rb +0 -101
- data/spec/shipwire/fulfillment_spec.rb +0 -36
- data/spec/shipwire/inventory_spec.rb +0 -25
- data/spec/shipwire/shipping_rate_spec.rb +0 -62
- data/spec/shipwire/tracking_spec.rb +0 -20
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4e7c0ef34187f0e40074393f657184943067e12a
|
|
4
|
+
data.tar.gz: 526b213f274a53d38f09da6c3d4d84719fb30081
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 65c8fcb56b8f080aaeeac6114a65dbecc02d6ae6b5f4bd36545c92db6e630542a27f9abfb728beeba132c4bd28d30baa144bf2cc10446c4a06f1b7c941593a5d
|
|
7
|
+
data.tar.gz: 27e0b51bc593d2f95e561a2b5c6d365abf3db9ac4a8f2271f5433180f36895d0707e0a0c8b3b58456d92e1a36a771a459f46daaea7a74ec7fdbcd08e0e962b3d
|
data/.gitignore
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
*.rbc
|
|
2
2
|
capybara-*.html
|
|
3
|
-
.rspec
|
|
4
3
|
/log
|
|
5
4
|
/tmp
|
|
6
5
|
/db/*.sqlite3
|
|
@@ -17,8 +16,9 @@ config/secrets.yml
|
|
|
17
16
|
/.bundle
|
|
18
17
|
/vendor/bundle
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
Gemfile.lock
|
|
20
|
+
|
|
21
|
+
rspec.log
|
|
22
22
|
|
|
23
23
|
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
|
24
24
|
.rvmrc
|
data/.rspec
ADDED
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
2.1.2
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -1,59 +1,83 @@
|
|
|
1
|
-
Shipwire
|
|
2
|
-
========
|
|
1
|
+
# Shipwire
|
|
3
2
|
|
|
4
|
-
Ruby gem to integrate with Shipwire's
|
|
3
|
+
Ruby gem to integrate with Shipwire's API.
|
|
5
4
|
|
|
6
5
|
## Installation
|
|
7
6
|
|
|
7
|
+
Install locally with
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
gem install shipwire
|
|
11
|
+
```
|
|
12
|
+
|
|
8
13
|
Add this line to your application's Gemfile:
|
|
9
14
|
|
|
10
|
-
|
|
15
|
+
```
|
|
16
|
+
gem 'shipwire'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
> Note: The master branch is not guaranteed to be in a fully functioning state. It is unwise to use this branch in a production environment.
|
|
20
|
+
|
|
21
|
+
Run the bundle command:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
bundle install
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
If you are using Rails, run the generator:
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
rails g shipwire:install
|
|
31
|
+
```
|
|
11
32
|
|
|
12
|
-
|
|
33
|
+
## Configuration
|
|
13
34
|
|
|
14
|
-
|
|
35
|
+
Basic configuration
|
|
15
36
|
|
|
16
|
-
|
|
37
|
+
```
|
|
38
|
+
Shipwire.configure do |config|
|
|
39
|
+
config.username = "<%= ENV['SHIPWIRE_USERNAME'] %>"
|
|
40
|
+
config.password = "<%= ENV['SHIPWIRE_PASSWORD'] %>"
|
|
41
|
+
end
|
|
42
|
+
```
|
|
17
43
|
|
|
18
|
-
|
|
44
|
+
`username` - (required) Shipwire username (email address) used for basic auth login to Shipwire
|
|
19
45
|
|
|
20
|
-
|
|
46
|
+
`password` - (required) Shipwire password used for basic auth login to Shipwire.
|
|
21
47
|
|
|
22
|
-
|
|
48
|
+
`open_timeout` - Read timeout in seconds. Default is `2`.
|
|
23
49
|
|
|
24
|
-
|
|
50
|
+
`timeout` - Open/read timeout in seconds. Default is `5`.
|
|
25
51
|
|
|
26
|
-
|
|
52
|
+
`endpoint` - Endpoint base URL to use for requests. Default is `https://api.shipwire.com`.
|
|
27
53
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
SHIPWIRE_PASSWORD
|
|
31
|
-
|
|
32
|
-
SHIPWIRE_SERVER
|
|
33
|
-
|
|
34
|
-
SHIPWIRE_ENDPOINT
|
|
54
|
+
`logger` - Log requests to STDOUT. Default is `false`.
|
|
35
55
|
|
|
36
|
-
|
|
56
|
+
> Note: There is a difference between an account registered from [https://www.shipwire.com/](https://www.shipwire.com/) and one registered from [https://beta.shipwire.com/](https://beta.shipwire.com/). If you create an account from [https://www.shipwire.com/](https://www.shipwire.com/) and then request data from the beta URL, the API will throw errors about an invalid account. Accounts are only valid from that registration point.
|
|
37
57
|
|
|
38
|
-
|
|
58
|
+
## Testing
|
|
39
59
|
|
|
40
|
-
|
|
60
|
+
Tests are using a throwaway Shipwire Beta account that is only meant for testing. A personal Shipwire Beta account of your own is not required.
|
|
41
61
|
|
|
42
|
-
|
|
62
|
+
Tests require a product named `TEST-PRODUCT` and `TEST-PRODUCT2` to function properly.
|
|
43
63
|
|
|
44
|
-
|
|
64
|
+
```
|
|
65
|
+
bundle exec rake spec
|
|
66
|
+
```
|
|
45
67
|
|
|
46
|
-
|
|
68
|
+
or
|
|
47
69
|
|
|
48
|
-
|
|
70
|
+
```
|
|
71
|
+
bundle exec rspec spec
|
|
72
|
+
```
|
|
49
73
|
|
|
50
|
-
|
|
74
|
+
## Contributions
|
|
51
75
|
|
|
52
|
-
|
|
76
|
+
If making contributions to this gem, make sure you write tests for any new functionality. Contributions will be rejected if there are no tests or tests do not pass.
|
|
53
77
|
|
|
54
78
|
## Contributing
|
|
55
79
|
|
|
56
|
-
1. Fork it ( https://github.com/
|
|
80
|
+
1. Fork it ( https://github.com/billr578/shipwire/fork )
|
|
57
81
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
58
82
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
59
83
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Rakefile
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Shipwire
|
|
2
|
+
module Generators
|
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
5
|
+
|
|
6
|
+
def copy_initializer_file
|
|
7
|
+
file = 'config/initializers/shipwire.rb'
|
|
8
|
+
|
|
9
|
+
copy_file(file, file)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Shipwire.configure do |config|
|
|
2
|
+
# Note there is a difference between an account registered from
|
|
3
|
+
# https://www.shipwire.com/ and one registered from https://beta.shipwire.com/
|
|
4
|
+
#
|
|
5
|
+
# If you create an account from https://www.shipwire.com/ and then request
|
|
6
|
+
# data from the beta URL, the API will throw errors about an invalid account.
|
|
7
|
+
|
|
8
|
+
#############################################################################
|
|
9
|
+
|
|
10
|
+
# Shipwire username (email address) used for basic auth login to Shipwire
|
|
11
|
+
config.username = "<%= ENV['SHIPWIRE_USERNAME'] %>"
|
|
12
|
+
|
|
13
|
+
# Shipwire password used for basic auth login to Shipwire.
|
|
14
|
+
config.password = "<%= ENV['SHIPWIRE_PASSWORD'] %>"
|
|
15
|
+
|
|
16
|
+
# Read timeout Integer in seconds. Default is 2 seconds
|
|
17
|
+
# config.open_timeout = 2
|
|
18
|
+
|
|
19
|
+
# Open/read timeout Integer in seconds. Default is 5 seconds
|
|
20
|
+
# config.timeout = 5
|
|
21
|
+
|
|
22
|
+
# Endpoint base URL to use for requests. Default is 'https://api.shipwire.com'
|
|
23
|
+
# config.endpoint = 'https://api.shipwire.com'
|
|
24
|
+
|
|
25
|
+
# Enable logging to the console. Default is false
|
|
26
|
+
# config.logger = false
|
|
27
|
+
end
|
data/lib/shipwire.rb
CHANGED
|
@@ -1,47 +1,40 @@
|
|
|
1
|
+
require 'deep_merge/rails_compat'
|
|
2
|
+
require 'faraday'
|
|
3
|
+
require 'faraday_middleware'
|
|
4
|
+
require 'recursive_open_struct'
|
|
5
|
+
|
|
1
6
|
require 'shipwire/version'
|
|
7
|
+
require 'shipwire/api'
|
|
2
8
|
require 'shipwire/configuration'
|
|
3
|
-
|
|
4
|
-
require 'shipwire/
|
|
5
|
-
require 'shipwire/
|
|
6
|
-
require 'shipwire/
|
|
7
|
-
|
|
8
|
-
require 'shipwire/
|
|
9
|
+
require 'shipwire/param_converter'
|
|
10
|
+
require 'shipwire/request'
|
|
11
|
+
require 'shipwire/response'
|
|
12
|
+
require 'shipwire/utility'
|
|
13
|
+
|
|
14
|
+
require 'shipwire/orders'
|
|
15
|
+
require 'shipwire/products'
|
|
16
|
+
require 'shipwire/rate'
|
|
17
|
+
require 'shipwire/receivings'
|
|
18
|
+
require 'shipwire/returns'
|
|
19
|
+
require 'shipwire/secret'
|
|
20
|
+
require 'shipwire/stock'
|
|
21
|
+
require 'shipwire/webhooks'
|
|
22
|
+
|
|
23
|
+
require 'shipwire/products/base'
|
|
24
|
+
require 'shipwire/products/insert'
|
|
25
|
+
require 'shipwire/products/kit'
|
|
26
|
+
require 'shipwire/products/virtual_kit'
|
|
9
27
|
|
|
10
28
|
module Shipwire
|
|
11
29
|
class << self
|
|
12
30
|
attr_accessor :configuration
|
|
13
31
|
|
|
14
|
-
def configure
|
|
15
|
-
|
|
32
|
+
def configure
|
|
33
|
+
yield(configuration)
|
|
16
34
|
end
|
|
17
35
|
|
|
18
36
|
def configuration
|
|
19
37
|
@configuration ||= Configuration.new
|
|
20
38
|
end
|
|
21
|
-
|
|
22
|
-
def endpoint
|
|
23
|
-
configuration.nil? ? nil : configuration.endpoint
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def username
|
|
27
|
-
configuration.nil? ? nil : configuration.username
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def password
|
|
31
|
-
configuration.nil? ? nil : configuration.password
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def server
|
|
35
|
-
configuration.nil? ? nil : configuration.server
|
|
36
|
-
end
|
|
37
39
|
end
|
|
38
|
-
|
|
39
|
-
class Error < Exception; end
|
|
40
|
-
class ApiEndpointNotSet < Error; end
|
|
41
|
-
class ApiUsernameNotSet < Error; end
|
|
42
|
-
class ApiPasswordNotSet < Error; end
|
|
43
|
-
class ApiServerNotSet < Error; end
|
|
44
|
-
class ServerErrorEncountered < Error; end
|
|
45
|
-
class AccessDenied < Error; end
|
|
46
|
-
class TrackingError < Error; end
|
|
47
40
|
end
|
data/lib/shipwire/api.rb
ADDED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
module Shipwire
|
|
2
2
|
class Configuration
|
|
3
|
-
attr_accessor :
|
|
3
|
+
attr_accessor :username,
|
|
4
|
+
:password,
|
|
5
|
+
:open_timeout,
|
|
6
|
+
:timeout,
|
|
7
|
+
:endpoint,
|
|
8
|
+
:logger
|
|
4
9
|
|
|
5
|
-
def initialize
|
|
6
|
-
|
|
10
|
+
def initialize
|
|
11
|
+
@username = nil
|
|
12
|
+
@password = nil
|
|
13
|
+
@open_timeout = 2
|
|
14
|
+
@timeout = 5
|
|
15
|
+
@endpoint = "https://api.shipwire.com"
|
|
16
|
+
@logger = false
|
|
7
17
|
end
|
|
8
18
|
end
|
|
9
19
|
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module Shipwire
|
|
2
|
+
class Orders < Api
|
|
3
|
+
def list(params = {})
|
|
4
|
+
request(:get, 'orders', params: params)
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def create(body)
|
|
8
|
+
request(:post, 'orders', body: body)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def find(id, params = {})
|
|
12
|
+
request(:get, "orders/#{id}/trackings", params: params)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def update(id, body, params = {})
|
|
16
|
+
request(:put, "orders/#{id}", body: body, params: params)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def cancel(id)
|
|
20
|
+
request(:post, "orders/#{id}/cancel")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def holds(id, params = {})
|
|
24
|
+
request(:get, "orders/#{id}/holds", params: params)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def items(id)
|
|
28
|
+
request(:get, "orders/#{id}/items")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def returns(id)
|
|
32
|
+
request(:get, "orders/#{id}/returns")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def trackings(id)
|
|
36
|
+
request(:get, "orders/#{id}/trackings")
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module Shipwire
|
|
2
|
+
class ParamConverter
|
|
3
|
+
attr_reader :params
|
|
4
|
+
|
|
5
|
+
def initialize(params)
|
|
6
|
+
if params.is_a?(Array)
|
|
7
|
+
@params = params.each_with_object([]) do |item, hsh|
|
|
8
|
+
hsh << recursively_struct(item)
|
|
9
|
+
end
|
|
10
|
+
else
|
|
11
|
+
@params = recursively_struct(params)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def to_h
|
|
16
|
+
if params.is_a?(Array)
|
|
17
|
+
params.each_with_object([]) do |item, hsh|
|
|
18
|
+
hsh << with_object(item)
|
|
19
|
+
end
|
|
20
|
+
else
|
|
21
|
+
with_object(params)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def recursively_struct(item)
|
|
28
|
+
RecursiveOpenStruct.new(item, recurse_over_arrays: true).to_h
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def with_object(item)
|
|
32
|
+
item.each_with_object({}) do |(original_key, value), hsh|
|
|
33
|
+
key = Utility.camelize(original_key.to_s, :lower).to_sym
|
|
34
|
+
|
|
35
|
+
hsh[key] = value.is_a?(Hash) ? with_object(value) : value
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module Shipwire
|
|
2
|
+
class Products < Api
|
|
3
|
+
def list(params = {})
|
|
4
|
+
request(:get, 'products', params: params_runner(params))
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def create(body)
|
|
8
|
+
request(:post, 'products', body: body_runner(body))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def find(id)
|
|
12
|
+
request(:get, "products/#{id}")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def update(id, body)
|
|
16
|
+
request(:put, "products/#{id}", body: body_runner(body))
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def retire(id)
|
|
20
|
+
request(:post, 'products/retire', body: retire_object(id))
|
|
21
|
+
end
|
|
22
|
+
alias_method :remove, :retire
|
|
23
|
+
alias_method :delete, :retire
|
|
24
|
+
|
|
25
|
+
protected
|
|
26
|
+
|
|
27
|
+
def product_classification
|
|
28
|
+
{}
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def params_runner(params)
|
|
34
|
+
with_product_classification(params)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def body_runner(body)
|
|
38
|
+
[body].flatten.each_with_object([]) do |item, pl|
|
|
39
|
+
pl << with_product_classification(item)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def with_product_classification(body)
|
|
44
|
+
body.merge(product_classification)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def retire_object(obj)
|
|
48
|
+
retire_array = obj.is_a?(Array) ? obj : Utility.split_to_integers(obj)
|
|
49
|
+
|
|
50
|
+
{ ids: retire_array }
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|