shipwire 0.0.5 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -3
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -1
  5. data/Gemfile +0 -1
  6. data/README.md +53 -29
  7. data/Rakefile +2 -3
  8. data/lib/generators/shipwire/install/install_generator.rb +13 -0
  9. data/lib/generators/shipwire/install/templates/config/initializers/shipwire.rb +27 -0
  10. data/lib/shipwire.rb +26 -33
  11. data/lib/shipwire/api.rb +7 -0
  12. data/lib/shipwire/configuration.rb +13 -3
  13. data/lib/shipwire/orders.rb +39 -0
  14. data/lib/shipwire/param_converter.rb +39 -0
  15. data/lib/shipwire/products.rb +53 -0
  16. data/lib/shipwire/products/base.rb +9 -0
  17. data/lib/shipwire/products/insert.rb +9 -0
  18. data/lib/shipwire/products/kit.rb +9 -0
  19. data/lib/shipwire/products/virtual_kit.rb +9 -0
  20. data/lib/shipwire/rate.rb +7 -0
  21. data/lib/shipwire/receivings.rb +50 -0
  22. data/lib/shipwire/request.rb +73 -0
  23. data/lib/shipwire/response.rb +79 -0
  24. data/lib/shipwire/returns.rb +35 -0
  25. data/lib/shipwire/secret.rb +20 -0
  26. data/lib/shipwire/stock.rb +7 -0
  27. data/lib/shipwire/utility.rb +22 -0
  28. data/lib/shipwire/version.rb +1 -1
  29. data/lib/shipwire/webhooks.rb +24 -0
  30. data/shipwire.gemspec +12 -15
  31. data/spec/features/access_spec.rb +61 -0
  32. data/spec/features/orders_spec.rb +280 -0
  33. data/spec/features/product_types_spec.rb +219 -0
  34. data/spec/features/products_spec.rb +282 -0
  35. data/spec/features/rate_spec.rb +50 -0
  36. data/spec/features/receivings_spec.rb +333 -0
  37. data/spec/features/returns_spec.rb +239 -0
  38. data/spec/features/secret_spec.rb +57 -0
  39. data/spec/features/stock_spec.rb +41 -0
  40. data/spec/features/webhooks_spec.rb +106 -0
  41. data/spec/spec_helper.rb +33 -12
  42. data/spec/support/shipwire.rb +10 -0
  43. data/spec/support/vcr.rb +9 -0
  44. data/spec/support/vcr_cassettes/credentials_incorrect.yml +47 -0
  45. data/spec/support/vcr_cassettes/credentials_missing.yml +47 -0
  46. data/spec/support/vcr_cassettes/order.yml +48 -0
  47. data/spec/support/vcr_cassettes/order_cancel.yml +54 -0
  48. data/spec/support/vcr_cassettes/order_cancel_fail.yml +47 -0
  49. data/spec/support/vcr_cassettes/order_find.yml +45 -0
  50. data/spec/support/vcr_cassettes/order_find_fail.yml +45 -0
  51. data/spec/support/vcr_cassettes/order_find_with_params.yml +45 -0
  52. data/spec/support/vcr_cassettes/order_holds.yml +50 -0
  53. data/spec/support/vcr_cassettes/order_holds_fail.yml +45 -0
  54. data/spec/support/vcr_cassettes/order_holds_with_params.yml +50 -0
  55. data/spec/support/vcr_cassettes/order_items.yml +45 -0
  56. data/spec/support/vcr_cassettes/order_items_fail.yml +45 -0
  57. data/spec/support/vcr_cassettes/order_returns.yml +47 -0
  58. data/spec/support/vcr_cassettes/order_returns_fail.yml +47 -0
  59. data/spec/support/vcr_cassettes/order_trackings.yml +45 -0
  60. data/spec/support/vcr_cassettes/order_trackings_fail.yml +45 -0
  61. data/spec/support/vcr_cassettes/order_update.yml +48 -0
  62. data/spec/support/vcr_cassettes/order_update_fail.yml +50 -0
  63. data/spec/support/vcr_cassettes/order_update_with_params.yml +48 -0
  64. data/spec/support/vcr_cassettes/order_with_warnings.yml +96 -0
  65. data/spec/support/vcr_cassettes/orders_list.yml +47 -0
  66. data/spec/support/vcr_cassettes/orders_list_with_params.yml +47 -0
  67. data/spec/support/vcr_cassettes/product.yml +48 -0
  68. data/spec/support/vcr_cassettes/product_base.yml +48 -0
  69. data/spec/support/vcr_cassettes/product_base_find.yml +48 -0
  70. data/spec/support/vcr_cassettes/product_base_find_fail.yml +47 -0
  71. data/spec/support/vcr_cassettes/product_base_retire_id.yml +47 -0
  72. data/spec/support/vcr_cassettes/product_base_retire_nonexistent.yml +47 -0
  73. data/spec/support/vcr_cassettes/product_base_update.yml +48 -0
  74. data/spec/support/vcr_cassettes/product_base_update_fail.yml +48 -0
  75. data/spec/support/vcr_cassettes/product_create_fail_with_invalid_classification.yml +51 -0
  76. data/spec/support/vcr_cassettes/product_find.yml +48 -0
  77. data/spec/support/vcr_cassettes/product_find_fail.yml +47 -0
  78. data/spec/support/vcr_cassettes/product_insert.yml +50 -0
  79. data/spec/support/vcr_cassettes/product_insert_find.yml +48 -0
  80. data/spec/support/vcr_cassettes/product_insert_find_fail.yml +47 -0
  81. data/spec/support/vcr_cassettes/product_insert_retire_id.yml +47 -0
  82. data/spec/support/vcr_cassettes/product_insert_retire_nonexistent.yml +47 -0
  83. data/spec/support/vcr_cassettes/product_insert_update.yml +49 -0
  84. data/spec/support/vcr_cassettes/product_insert_update_fail.yml +48 -0
  85. data/spec/support/vcr_cassettes/product_kit.yml +48 -0
  86. data/spec/support/vcr_cassettes/product_kit_find.yml +48 -0
  87. data/spec/support/vcr_cassettes/product_kit_find_fail.yml +47 -0
  88. data/spec/support/vcr_cassettes/product_kit_retire_id.yml +47 -0
  89. data/spec/support/vcr_cassettes/product_kit_retire_nonexistent.yml +47 -0
  90. data/spec/support/vcr_cassettes/product_kit_update.yml +48 -0
  91. data/spec/support/vcr_cassettes/product_kit_update_fail.yml +47 -0
  92. data/spec/support/vcr_cassettes/product_multiple_create_fail.yml +102 -0
  93. data/spec/support/vcr_cassettes/product_multiple_create_success.yml +100 -0
  94. data/spec/support/vcr_cassettes/product_retire_id.yml +47 -0
  95. data/spec/support/vcr_cassettes/product_retire_nonexistent.yml +47 -0
  96. data/spec/support/vcr_cassettes/product_update.yml +48 -0
  97. data/spec/support/vcr_cassettes/product_update_fail.yml +48 -0
  98. data/spec/support/vcr_cassettes/product_virtual_kit.yml +48 -0
  99. data/spec/support/vcr_cassettes/product_virtual_kit_find.yml +48 -0
  100. data/spec/support/vcr_cassettes/product_virtual_kit_find_fail.yml +47 -0
  101. data/spec/support/vcr_cassettes/product_virtual_kit_retire_id.yml +47 -0
  102. data/spec/support/vcr_cassettes/product_virtual_kit_retire_nonexistent.yml +47 -0
  103. data/spec/support/vcr_cassettes/product_virtual_kit_update.yml +49 -0
  104. data/spec/support/vcr_cassettes/product_virtual_kit_update_fail.yml +47 -0
  105. data/spec/support/vcr_cassettes/products_base_list.yml +49 -0
  106. data/spec/support/vcr_cassettes/products_base_list_with_params.yml +49 -0
  107. data/spec/support/vcr_cassettes/products_insert_list.yml +47 -0
  108. data/spec/support/vcr_cassettes/products_insert_list_with_params.yml +47 -0
  109. data/spec/support/vcr_cassettes/products_kit_list.yml +47 -0
  110. data/spec/support/vcr_cassettes/products_kit_list_with_params.yml +47 -0
  111. data/spec/support/vcr_cassettes/products_list.yml +49 -0
  112. data/spec/support/vcr_cassettes/products_list_with_params.yml +49 -0
  113. data/spec/support/vcr_cassettes/products_virtual_kit_list.yml +47 -0
  114. data/spec/support/vcr_cassettes/products_virtual_kit_list_with_params.yml +47 -0
  115. data/spec/support/vcr_cassettes/rate_find.yml +53 -0
  116. data/spec/support/vcr_cassettes/rate_find_fail.yml +50 -0
  117. data/spec/support/vcr_cassettes/receiving.yml +53 -0
  118. data/spec/support/vcr_cassettes/receiving_cancel.yml +98 -0
  119. data/spec/support/vcr_cassettes/receiving_cancel_label.yml +47 -0
  120. data/spec/support/vcr_cassettes/receiving_cancel_label_nonexistent.yml +47 -0
  121. data/spec/support/vcr_cassettes/receiving_find.yml +46 -0
  122. data/spec/support/vcr_cassettes/receiving_find_fail.yml +45 -0
  123. data/spec/support/vcr_cassettes/receiving_find_with_params.yml +48 -0
  124. data/spec/support/vcr_cassettes/receiving_holds.yml +47 -0
  125. data/spec/support/vcr_cassettes/receiving_holds_fail.yml +45 -0
  126. data/spec/support/vcr_cassettes/receiving_holds_with_params.yml +47 -0
  127. data/spec/support/vcr_cassettes/receiving_instructions_recipients.yml +45 -0
  128. data/spec/support/vcr_cassettes/receiving_instructions_recipients_fail.yml +45 -0
  129. data/spec/support/vcr_cassettes/receiving_items.yml +45 -0
  130. data/spec/support/vcr_cassettes/receiving_items_fail.yml +45 -0
  131. data/spec/support/vcr_cassettes/receiving_shipments.yml +45 -0
  132. data/spec/support/vcr_cassettes/receiving_shipments_fail.yml +45 -0
  133. data/spec/support/vcr_cassettes/receiving_tracking.yml +45 -0
  134. data/spec/support/vcr_cassettes/receiving_tracking_fail.yml +45 -0
  135. data/spec/support/vcr_cassettes/receiving_update.yml +53 -0
  136. data/spec/support/vcr_cassettes/receiving_update_fail.yml +49 -0
  137. data/spec/support/vcr_cassettes/receiving_update_with_params.yml +55 -0
  138. data/spec/support/vcr_cassettes/receivings_list.yml +53 -0
  139. data/spec/support/vcr_cassettes/receivings_list_with_params.yml +46 -0
  140. data/spec/support/vcr_cassettes/return.yml +98 -0
  141. data/spec/support/vcr_cassettes/return_cancel.yml +55 -0
  142. data/spec/support/vcr_cassettes/return_cancel_fail.yml +47 -0
  143. data/spec/support/vcr_cassettes/return_find.yml +47 -0
  144. data/spec/support/vcr_cassettes/return_find_fail.yml +45 -0
  145. data/spec/support/vcr_cassettes/return_find_with_params.yml +47 -0
  146. data/spec/support/vcr_cassettes/return_holds.yml +45 -0
  147. data/spec/support/vcr_cassettes/return_holds_fail.yml +45 -0
  148. data/spec/support/vcr_cassettes/return_holds_with_params.yml +45 -0
  149. data/spec/support/vcr_cassettes/return_items.yml +45 -0
  150. data/spec/support/vcr_cassettes/return_items_fail.yml +45 -0
  151. data/spec/support/vcr_cassettes/return_labels.yml +45 -0
  152. data/spec/support/vcr_cassettes/return_labels_fail.yml +45 -0
  153. data/spec/support/vcr_cassettes/return_trackings.yml +45 -0
  154. data/spec/support/vcr_cassettes/return_trackings_fail.yml +45 -0
  155. data/spec/support/vcr_cassettes/returns_list.yml +47 -0
  156. data/spec/support/vcr_cassettes/returns_list_with_params.yml +47 -0
  157. data/spec/support/vcr_cassettes/secret.yml +47 -0
  158. data/spec/support/vcr_cassettes/secret_find.yml +45 -0
  159. data/spec/support/vcr_cassettes/secret_find_fail.yml +43 -0
  160. data/spec/support/vcr_cassettes/secret_list.yml +45 -0
  161. data/spec/support/vcr_cassettes/secret_remove.yml +45 -0
  162. data/spec/support/vcr_cassettes/stock_with_params.yml +45 -0
  163. data/spec/support/vcr_cassettes/stock_with_params_no_sku.yml +45 -0
  164. data/spec/support/vcr_cassettes/stock_without_params.yml +45 -0
  165. data/spec/support/vcr_cassettes/webhook.yml +47 -0
  166. data/spec/support/vcr_cassettes/webhooks_create_insecure.yml +50 -0
  167. data/spec/support/vcr_cassettes/webhooks_find.yml +47 -0
  168. data/spec/support/vcr_cassettes/webhooks_find_fail.yml +47 -0
  169. data/spec/support/vcr_cassettes/webhooks_list.yml +47 -0
  170. data/spec/support/vcr_cassettes/webhooks_remove.yml +47 -0
  171. data/spec/support/vcr_cassettes/webhooks_update.yml +47 -0
  172. data/spec/support/vcr_cassettes/webhooks_update_fail.yml +49 -0
  173. data/spec/unit/shipwire/response_spec.rb +46 -0
  174. metadata +354 -80
  175. data/.env +0 -4
  176. data/.env.example +0 -4
  177. data/Gemfile.lock +0 -69
  178. data/lib/shipwire/fulfillment.rb +0 -100
  179. data/lib/shipwire/inventory.rb +0 -72
  180. data/lib/shipwire/service_request.rb +0 -42
  181. data/lib/shipwire/shipping_rate.rb +0 -121
  182. data/lib/shipwire/tracking.rb +0 -101
  183. data/spec/shipwire/fulfillment_spec.rb +0 -36
  184. data/spec/shipwire/inventory_spec.rb +0 -25
  185. data/spec/shipwire/shipping_rate_spec.rb +0 -62
  186. data/spec/shipwire/tracking_spec.rb +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 390d86197ecf6da646f89f4a122ec6b2ce7bda5b
4
- data.tar.gz: 5045260cd97ef4beeca3ff155afd44b457d14696
3
+ metadata.gz: 4e7c0ef34187f0e40074393f657184943067e12a
4
+ data.tar.gz: 526b213f274a53d38f09da6c3d4d84719fb30081
5
5
  SHA512:
6
- metadata.gz: 52d11f15184c2f13719d341ab306ad8ad6fc78aacbd47eb74c061d2d899345939eb3d55dd1b11ff6db03c1955716e72ad20062748d20a368c709b5f24879a45d
7
- data.tar.gz: 1de44e2d241d6d1ebbe75ea14661784c84493a4e6e74a68dc4fa01c099576aedcbeb59ee9674fb3bf08cd9f91672bda560226d4e70e229fac2c27be6704f79dc
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
- # these should all be checked in to normalise the environment:
21
- # Gemfile.lock, .ruby-version, .ruby-gemset
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
@@ -0,0 +1,2 @@
1
+ --color
2
+ --order defined
@@ -1 +1 @@
1
- ruby-2.1.2
1
+ 2.1.2
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in hubbah.gemspec
4
3
  gemspec
data/README.md CHANGED
@@ -1,59 +1,83 @@
1
- Shipwire
2
- ========
1
+ # Shipwire
3
2
 
4
- Ruby gem to integrate with Shipwire's fulfillment API.
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
- `gem 'shipwire'`
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
- And then execute:
33
+ ## Configuration
13
34
 
14
- `$ bundle`
35
+ Basic configuration
15
36
 
16
- You can install it locally as:
37
+ ```
38
+ Shipwire.configure do |config|
39
+ config.username = "<%= ENV['SHIPWIRE_USERNAME'] %>"
40
+ config.password = "<%= ENV['SHIPWIRE_PASSWORD'] %>"
41
+ end
42
+ ```
17
43
 
18
- `$ gem install shipwire`
44
+ `username` - (required) Shipwire username (email address) used for basic auth login to Shipwire
19
45
 
20
- ## Getting Started
46
+ `password` - (required) Shipwire password used for basic auth login to Shipwire.
21
47
 
22
- Get a Shipwire sandbox account for development & testing:
48
+ `open_timeout` - Read timeout in seconds. Default is `2`.
23
49
 
24
- `http://beta.shipwire.com/`
50
+ `timeout` - Open/read timeout in seconds. Default is `5`.
25
51
 
26
- Your credentials, endpoint, and sever environment variables need to be set:
52
+ `endpoint` - Endpoint base URL to use for requests. Default is `https://api.shipwire.com`.
27
53
 
28
- SHIPWIRE_USERNAME
29
-
30
- SHIPWIRE_PASSWORD
31
-
32
- SHIPWIRE_SERVER
33
-
34
- SHIPWIRE_ENDPOINT
54
+ `logger` - Log requests to STDOUT. Default is `false`.
35
55
 
36
- SHIPWIRE_SERVER is either `Test` or `Production`. SHIPWIRE_ENDPOINT is one of their API hosts:
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
- `https://api.shipwire.com/exec/`
58
+ ## Testing
39
59
 
40
- Or
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
- `https://api.beta.shipwire.com/exec/`
62
+ Tests require a product named `TEST-PRODUCT` and `TEST-PRODUCT2` to function properly.
43
63
 
44
- Use `api.beta` for any development or testing.
64
+ ```
65
+ bundle exec rake spec
66
+ ```
45
67
 
46
- ## Running Tests
68
+ or
47
69
 
48
- 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.
70
+ ```
71
+ bundle exec rspec spec
72
+ ```
49
73
 
50
- #### Shipping Quotes
74
+ ## Contributions
51
75
 
52
- Shipwire relies on product SKUs being present to return a shipping quote. In your Sandbox environment, create a test product with SKU `123456` to get quote tests to pass.
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/[my-github-username]/shipwire/fork )
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
@@ -1,7 +1,6 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
2
 
3
3
  require 'rspec/core/rake_task'
4
4
 
5
5
  RSpec::Core::RakeTask.new(:spec)
6
-
7
- task :default => :spec
6
+ task default: :spec
@@ -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
@@ -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/service_request'
5
- require 'shipwire/fulfillment'
6
- require 'shipwire/shipping_rate'
7
- require 'shipwire/tracking'
8
- require 'shipwire/inventory'
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(&block)
15
- @configuration = Configuration.new(&block)
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
@@ -0,0 +1,7 @@
1
+ module Shipwire
2
+ class Api
3
+ def request(method, path, body: {}, params: {})
4
+ Request.send(method: method, path: path, body: body, params: params)
5
+ end
6
+ end
7
+ end
@@ -1,9 +1,19 @@
1
1
  module Shipwire
2
2
  class Configuration
3
- attr_accessor :endpoint, :username, :password, :server
3
+ attr_accessor :username,
4
+ :password,
5
+ :open_timeout,
6
+ :timeout,
7
+ :endpoint,
8
+ :logger
4
9
 
5
- def initialize(&block)
6
- block.call(self)
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