pwinty 3.0.7 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/Dockerfile +17 -0
  3. data/.devcontainer/base.Dockerfile +43 -0
  4. data/.devcontainer/devcontainer.json +37 -0
  5. data/Gemfile.lock +65 -43
  6. data/README.md +50 -99
  7. data/lib/pwinty/api_models/order.rb +114 -0
  8. data/lib/pwinty/api_models/order_asset.rb +7 -0
  9. data/lib/pwinty/api_models/order_charge.rb +5 -0
  10. data/lib/pwinty/api_models/order_cost.rb +7 -0
  11. data/lib/pwinty/api_models/order_item.rb +24 -0
  12. data/lib/pwinty/api_models/order_packing_slip.rb +7 -0
  13. data/lib/pwinty/api_models/order_recipient.rb +17 -0
  14. data/lib/pwinty/api_models/order_recipient_address.rb +11 -0
  15. data/lib/pwinty/api_models/order_shipment.rb +16 -0
  16. data/lib/pwinty/api_models/order_shipment_carrier.rb +6 -0
  17. data/lib/pwinty/api_models/order_shipment_fulfillment_location.rb +7 -0
  18. data/lib/pwinty/api_models/order_shipment_item.rb +6 -0
  19. data/lib/pwinty/api_models/order_status.rb +11 -0
  20. data/lib/pwinty/api_models/order_status_auth_details.rb +7 -0
  21. data/lib/pwinty/api_models/order_status_details.rb +10 -0
  22. data/lib/pwinty/api_models/order_status_issue.rb +11 -0
  23. data/lib/pwinty/api_models/order_tracking.rb +6 -0
  24. data/lib/pwinty/api_models/product.rb +19 -0
  25. data/lib/pwinty/api_models/product_dimensions.rb +8 -0
  26. data/lib/pwinty/api_models/product_variant.rb +8 -0
  27. data/lib/pwinty/http_errors.rb +6 -4
  28. data/lib/pwinty/version.rb +1 -1
  29. data/lib/pwinty.rb +10 -11
  30. data/pwinty.gemspec +13 -13
  31. metadata +58 -42
  32. data/lib/pwinty/country.rb +0 -12
  33. data/lib/pwinty/image.rb +0 -24
  34. data/lib/pwinty/order.rb +0 -135
  35. data/lib/pwinty/order_status.rb +0 -17
  36. data/lib/pwinty/photo_status.rb +0 -8
  37. data/lib/pwinty/shipment.rb +0 -14
  38. data/lib/pwinty/shipping_info.rb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6dcf71ee9a54e4f465c63cb14f36b5e381daafdbc7977481348064bad6682f16
4
- data.tar.gz: 0f8ccb3c28d7acd1d9dfbf2fba587079d4462f77dbef597f885ddfca91c5904c
3
+ metadata.gz: 834f6357c9970480b7572f388a1ff47f27a50449b56b09ec9913fecf527e510c
4
+ data.tar.gz: 56552af641deb119beed08897f8f3ca3655554d58cfef1cd838a8f6b250e27c7
5
5
  SHA512:
6
- metadata.gz: 4cd4afa3d875a3bb268ce2278c638187707a7b65d2629feac438ecb53637cb66c91afb22efbed66947520349bde4a3626a8e8aa2e39933e1fac973d29b0a4537
7
- data.tar.gz: 7c99cc760d7ae010dbeb3c166418b8ccaef6b3a8ca69f6baffb7a5b692f2eb5a3f8c1b4100a9445f104e46f13eddc3e6302cee6fe696e44f9f01dc67e7b184c8
6
+ metadata.gz: 8d24ae448259424a7d1e51c02e508b5ee0f05d2a06bb346390c0cb9fc5a4c2803ff8458a1dc32bf797ac3ba413050b09203dfde80a6dde94c7a995d24bb3eec8
7
+ data.tar.gz: 1fb7637795fe4ad025089c77ac62a6fc1596b6c7517227752c3680081fdad75b71678a9ce3c42fc6840852ba857b17498db22dec96b8c6e08a59e8c462cbedb0
@@ -0,0 +1,17 @@
1
+ # [Choice] Ruby version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.1, 3.0, 2, 2.7, 2.6, 3-bullseye, 3.1-bullseye, 3.0-bullseye, 2-bullseye, 2.7-bullseye, 2.6-bullseye, 3-buster, 3.1-buster, 3.0-buster, 2-buster, 2.7-buster, 2.6-buster
2
+ ARG VARIANT=2-bullseye
3
+ FROM mcr.microsoft.com/vscode/devcontainers/ruby:0-${VARIANT}
4
+
5
+ # [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
6
+ ARG NODE_VERSION="none"
7
+ RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
8
+
9
+ # [Optional] Uncomment this section to install additional OS packages.
10
+ # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
11
+ # && apt-get -y install --no-install-recommends <your-package-list-here>
12
+
13
+ # [Optional] Uncomment this line to install additional gems.
14
+ # RUN gem install <your-gem-names-here>
15
+
16
+ # [Optional] Uncomment this line to install global node packages.
17
+ # RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
@@ -0,0 +1,43 @@
1
+ # [Choice] Ruby version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.1, 3.0, 2, 2.7, 2.6, 3-bullseye, 3.1-bullseye, 3.0-bullseye, 2-bullseye, 2.7-bullseye, 2.6-bullseye, 3-buster, 3.1-buster, 3.0-buster, 2-buster, 2.7-buster, 2.6-buster
2
+ ARG VARIANT=2-bullseye
3
+ FROM ruby:${VARIANT}
4
+
5
+ # Copy library scripts to execute
6
+ COPY library-scripts/*.sh library-scripts/*.env /tmp/library-scripts/
7
+
8
+ # [Option] Install zsh
9
+ ARG INSTALL_ZSH="true"
10
+ # [Option] Upgrade OS packages to their latest versions
11
+ ARG UPGRADE_PACKAGES="true"
12
+ # Install needed packages and setup non-root user. Use a separate RUN statement to add your own dependencies.
13
+ ARG USERNAME=vscode
14
+ ARG USER_UID=1000
15
+ ARG USER_GID=$USER_UID
16
+ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
17
+ # Remove imagemagick due to https://security-tracker.debian.org/tracker/CVE-2019-10131
18
+ && apt-get purge -y imagemagick imagemagick-6-common \
19
+ # Install common packages, non-root user, rvm, core build tools
20
+ && bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" "true" "true" \
21
+ && bash /tmp/library-scripts/ruby-debian.sh "none" "${USERNAME}" "true" "true" \
22
+ && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*
23
+
24
+ # [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
25
+ ARG NODE_VERSION="none"
26
+ ENV NVM_DIR=/usr/local/share/nvm
27
+ ENV NVM_SYMLINK_CURRENT=true \
28
+ PATH=${NVM_DIR}/current/bin:${PATH}
29
+ RUN bash /tmp/library-scripts/node-debian.sh "${NVM_DIR}" "${NODE_VERSION}" "${USERNAME}" \
30
+ && apt-get clean -y && rm -rf /var/lib/apt/lists/*
31
+
32
+ # Remove library scripts for final image
33
+ RUN rm -rf /tmp/library-scripts
34
+
35
+ # [Optional] Uncomment this section to install additional OS packages.
36
+ # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
37
+ # && apt-get -y install --no-install-recommends <your-package-list-here>
38
+
39
+ # [Optional] Uncomment this line to install additional gems.
40
+ # RUN gem install <your-gem-names-here>
41
+
42
+ # [Optional] Uncomment this line to install global node packages.
43
+ # RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
@@ -0,0 +1,37 @@
1
+ // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2
+ // https://github.com/microsoft/vscode-dev-containers/tree/v0.231.6/containers/ruby
3
+ {
4
+ "name": "Ruby",
5
+ "build": {
6
+ "dockerfile": "Dockerfile",
7
+ "args": {
8
+ // Update 'VARIANT' to pick a Ruby version: 3, 3.1, 3.0, 2, 2.7, 2.6
9
+ // Append -bullseye or -buster to pin to an OS version.
10
+ // Use -bullseye variants on local on arm64/Apple Silicon.
11
+ "VARIANT": "3-bullseye",
12
+ // Options
13
+ "NODE_VERSION": "lts/*"
14
+ }
15
+ },
16
+
17
+ // Set *default* container specific settings.json values on container create.
18
+ "settings": {},
19
+
20
+ // Add the IDs of extensions you want installed when the container is created.
21
+ "extensions": [
22
+ "rebornix.Ruby"
23
+ ],
24
+
25
+ // Use 'forwardPorts' to make a list of ports inside the container available locally.
26
+ // "forwardPorts": [],
27
+
28
+ // Use 'postCreateCommand' to run commands after the container is created.
29
+ // "postCreateCommand": "ruby --version",
30
+
31
+ // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
32
+ "remoteUser": "vscode",
33
+ "features": {
34
+ "git": "os-provided"
35
+ }
36
+
37
+ }
data/Gemfile.lock CHANGED
@@ -1,33 +1,33 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pwinty (3.0.7)
4
+ pwinty (4.0.0)
5
5
  dry-struct (~> 1.0)
6
- dry-struct-setters (~> 0.2)
7
- faraday (~> 0.15)
8
- faraday_middleware (~> 0.13)
9
- json (~> 2.2)
6
+ dry-struct-setters (~> 0.4)
7
+ faraday (~> 1.0)
8
+ faraday_middleware (~> 1.2)
9
+ json (~> 2.6)
10
10
 
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
14
  addressable (2.8.0)
15
15
  public_suffix (>= 2.0.2, < 5.0)
16
- concurrent-ruby (1.1.9)
16
+ concurrent-ruby (1.1.10)
17
17
  crack (0.4.5)
18
18
  rexml
19
- diff-lcs (1.4.4)
19
+ diff-lcs (1.5.0)
20
20
  docile (1.4.0)
21
21
  dotenv (2.7.6)
22
- dry-configurable (0.12.1)
22
+ dry-configurable (0.15.0)
23
23
  concurrent-ruby (~> 1.0)
24
- dry-core (~> 0.5, >= 0.5.0)
25
- dry-container (0.7.2)
24
+ dry-core (~> 0.6)
25
+ dry-container (0.9.0)
26
26
  concurrent-ruby (~> 1.0)
27
- dry-configurable (~> 0.1, >= 0.1.3)
28
- dry-core (0.6.0)
27
+ dry-configurable (~> 0.13, >= 0.13.0)
28
+ dry-core (0.7.1)
29
29
  concurrent-ruby (~> 1.0)
30
- dry-inflector (0.2.0)
30
+ dry-inflector (0.2.1)
31
31
  dry-logic (1.2.0)
32
32
  concurrent-ruby (~> 1.0)
33
33
  dry-core (~> 0.5, >= 0.5)
@@ -35,62 +35,84 @@ GEM
35
35
  dry-core (~> 0.5, >= 0.5)
36
36
  dry-types (~> 1.5)
37
37
  ice_nine (~> 0.11)
38
- dry-struct-setters (0.3.0)
39
- dry-struct (>= 1.0.0)
38
+ dry-struct-setters (0.4.0)
39
+ dry-struct (>= 1.4.0)
40
40
  dry-types (1.5.1)
41
41
  concurrent-ruby (~> 1.0)
42
42
  dry-container (~> 0.3)
43
43
  dry-core (~> 0.5, >= 0.5)
44
44
  dry-inflector (~> 0.1, >= 0.1.2)
45
45
  dry-logic (~> 1.0, >= 1.0.2)
46
- faraday (0.17.4)
46
+ faraday (1.10.0)
47
+ faraday-em_http (~> 1.0)
48
+ faraday-em_synchrony (~> 1.0)
49
+ faraday-excon (~> 1.1)
50
+ faraday-httpclient (~> 1.0)
51
+ faraday-multipart (~> 1.0)
52
+ faraday-net_http (~> 1.0)
53
+ faraday-net_http_persistent (~> 1.0)
54
+ faraday-patron (~> 1.0)
55
+ faraday-rack (~> 1.0)
56
+ faraday-retry (~> 1.0)
57
+ ruby2_keywords (>= 0.0.4)
58
+ faraday-em_http (1.0.0)
59
+ faraday-em_synchrony (1.0.0)
60
+ faraday-excon (1.1.0)
61
+ faraday-httpclient (1.0.1)
62
+ faraday-multipart (1.0.3)
47
63
  multipart-post (>= 1.2, < 3)
48
- faraday_middleware (0.14.0)
49
- faraday (>= 0.7.4, < 1.0)
64
+ faraday-net_http (1.0.1)
65
+ faraday-net_http_persistent (1.2.0)
66
+ faraday-patron (1.0.0)
67
+ faraday-rack (1.0.0)
68
+ faraday-retry (1.0.3)
69
+ faraday_middleware (1.2.0)
70
+ faraday (~> 1.0)
50
71
  hashdiff (1.0.1)
51
72
  ice_nine (0.11.2)
52
- json (2.5.1)
73
+ json (2.6.1)
53
74
  multipart-post (2.1.1)
54
- public_suffix (4.0.6)
75
+ public_suffix (4.0.7)
55
76
  rake (13.0.6)
56
77
  rexml (3.2.5)
57
- rspec (3.10.0)
58
- rspec-core (~> 3.10.0)
59
- rspec-expectations (~> 3.10.0)
60
- rspec-mocks (~> 3.10.0)
61
- rspec-core (3.10.1)
62
- rspec-support (~> 3.10.0)
63
- rspec-expectations (3.10.1)
78
+ rspec (3.11.0)
79
+ rspec-core (~> 3.11.0)
80
+ rspec-expectations (~> 3.11.0)
81
+ rspec-mocks (~> 3.11.0)
82
+ rspec-core (3.11.0)
83
+ rspec-support (~> 3.11.0)
84
+ rspec-expectations (3.11.0)
64
85
  diff-lcs (>= 1.2.0, < 2.0)
65
- rspec-support (~> 3.10.0)
66
- rspec-mocks (3.10.2)
86
+ rspec-support (~> 3.11.0)
87
+ rspec-mocks (3.11.1)
67
88
  diff-lcs (>= 1.2.0, < 2.0)
68
- rspec-support (~> 3.10.0)
69
- rspec-support (3.10.2)
89
+ rspec-support (~> 3.11.0)
90
+ rspec-support (3.11.0)
91
+ ruby2_keywords (0.0.5)
70
92
  simplecov (0.21.2)
71
93
  docile (~> 1.1)
72
94
  simplecov-html (~> 0.11)
73
95
  simplecov_json_formatter (~> 0.1)
74
96
  simplecov-html (0.12.3)
75
- simplecov_json_formatter (0.1.3)
76
- vcr (5.1.0)
77
- webmock (3.13.0)
78
- addressable (>= 2.3.6)
97
+ simplecov_json_formatter (0.1.4)
98
+ vcr (6.1.0)
99
+ webmock (3.14.0)
100
+ addressable (>= 2.8.0)
79
101
  crack (>= 0.3.2)
80
102
  hashdiff (>= 0.4.0, < 2.0.0)
81
103
 
82
104
  PLATFORMS
83
- x86_64-darwin-18
105
+ aarch64-linux
84
106
 
85
107
  DEPENDENCIES
86
- bundler (~> 2.2.10)
108
+ bundler
87
109
  dotenv (~> 2.7.5)
88
110
  pwinty!
89
- rake (~> 13.0)
90
- rspec (~> 3.0)
91
- simplecov (~> 0.17)
92
- vcr (~> 5.0)
93
- webmock (~> 3.6)
111
+ rake
112
+ rspec
113
+ simplecov (~> 0.21)
114
+ vcr (~> 6.0)
115
+ webmock (~> 3.14)
94
116
 
95
117
  BUNDLED WITH
96
- 2.2.23
118
+ 2.3.7
data/README.md CHANGED
@@ -7,10 +7,10 @@
7
7
  [![Known Vulnerabilities](https://snyk.io//test/github/tomharvey/pwinty3-rb/badge.svg?targetFile=Gemfile.lock)](https://snyk.io//test/github/tomharvey/pwinty3-rb?targetFile=Gemfile.lock)
8
8
 
9
9
 
10
- This wraps the Pwinty API at version 3 and aims to make your ruby life easier
10
+ This wraps the Prodigi Pwinty API at version 4 and aims to make your ruby life easier
11
11
  when interacting with the API.
12
12
 
13
- See http://pwinty.com and https://pwinty.com/api for more details around the
13
+ See https://www.prodigi.com and https://www.prodigi.com/print-api/docs/ for more details around the
14
14
  core service.
15
15
 
16
16
  ## Installation
@@ -18,7 +18,7 @@ core service.
18
18
  Add this line to your application's Gemfile:
19
19
 
20
20
  ``` ruby
21
- gem 'pwinty', '~>3'
21
+ gem 'pwinty', '~>4'
22
22
  ```
23
23
 
24
24
  And then execute:
@@ -37,7 +37,7 @@ app.
37
37
 
38
38
  #### Authentication
39
39
  To authenticate requests you must get your merchant ID and API Key from the
40
- [Integration Settings in the Pwinty Dashboard](https://beta-dashboard.pwinty.com/settings/integrations).
40
+ [Integration Settings in the Pwinty Sandbox Dashboard](https://sandbox-beta-dashboard.pwinty.com/settings/integrations).
41
41
 
42
42
  These values must be set as the Environment Variables
43
43
  `PWINTY_MERCHANT_ID` and `PWINTY_API_KEY`
@@ -50,7 +50,7 @@ Pwinty::API_KEY = 'your api key'
50
50
 
51
51
  #### Production vs Sandbox
52
52
  The Pwinty API provides a sandbox endpoint to test and develop against at
53
- `https://sandbox.pwinty.com`. This is the default
53
+ `https://api.sandbox.prodigi.com`. This is the default
54
54
  endpoint used by this library.
55
55
 
56
56
  When you are ready to switch to the production endpoint, set the
@@ -58,116 +58,73 @@ Environment Variable `PWINTY_BASE_URL` or declare the
58
58
  constant in your app:
59
59
 
60
60
  ``` ruby
61
- Pwinty::BASE_URL = 'https://api.pwinty.com' # Without a trailing slash
61
+ Pwinty::BASE_URL = 'https://api.prodigi.com' # Without a trailing slash
62
62
  ```
63
63
 
64
64
  ## Usage
65
65
 
66
- ### Create an Order
66
+ ### Create and submit an Order
67
67
 
68
- These are the minimum variables you need to send to the API to register your
69
- order, you'll want to add more or update later.
68
+ These are the minimum variables you need to create an order and submit it for printing.
69
+
70
+ This method will return a `Pwinty::Order` object.
70
71
 
71
72
  See the `lib/pwinty/order.rb` file or the
72
- [API documentation](https://pwinty.com/api/#orders-create)
73
+ [API documentation](https://www.prodigi.com/print-api/docs/reference/#create-order)
73
74
  to understand the full list of attributes to send.
74
75
 
75
76
  ``` ruby
76
- order = Pwinty::Order.create(
77
- recipientName: "FirstName LastName",
78
- countryCode: "US",
79
- preferredShippingMethod: "Budget"
77
+ order = Pwinty::Order.new(
78
+ shippingMethod: "Budget",
79
+ recipient: {
80
+ name: "Tom Harvey",
81
+ },
82
+ items: [
83
+ {
84
+ sku: "GLOBAL-PHO-4X6-PRO",
85
+ copies: 1,
86
+ assets: [
87
+ {url: 'https://example.com/image.jpg'}
88
+ ],
89
+ attributes: {finish: 'lustre'},
90
+ }
91
+ ]
80
92
  )
81
- ```
82
93
 
83
- This create method will return a `Pwinty::Order` object.
94
+ submitted_order = order.submit
95
+
96
+ p submitted_order
97
+ >>> "ord_1234"
98
+ ```
84
99
 
85
100
  ### Get an existing Order from the API
86
101
 
87
102
  Once an order is created you can retreive it from the API to further manage it,
88
103
  or if it has been submitted you can see the latest production and shipping details.
89
104
 
90
- ``` ruby
91
- order = Pwinty::Order.find(1) # Pass the ID returned when you created the Order
92
- ```
93
-
94
105
  This method will return a `Pwinty::Order` object.
95
106
 
96
- ### Update an Order
97
-
98
- Using the `order` object created in the above, we can update this using:
99
-
100
107
  ``` ruby
101
- order.update(
102
- address1: 'Street Name',
103
- )
108
+ order = Pwinty::Order.find('ord_1234') # Pass the ID returned when you created the Order
104
109
  ```
105
110
 
106
- This update method will update the `Pwinty::Order` object.
107
-
108
- ### Validate an Order
109
-
110
- Before submitting you might want to validate the order and check all is well.
111
111
 
112
- ``` ruby
113
- status = order.submission_status
114
- ```
112
+ ### Cancel an order
115
113
 
116
- This will return a `Pwinty::OrderStatus` object. See the
117
- [API documentation](https://pwinty.com/api/#orders-validate)
118
- for more details of the shape of this reponse. But, you'll at least want the
119
- `status.isValid` method for a boolean
120
- check to see if it can be submitted.
114
+ Orders which are not being processed can be cancelled.
121
115
 
122
- ### Add an Image to your Order
123
-
124
- Add a single image by passing a hash to:
125
-
126
- ``` ruby
127
- order.add_image(
128
- sku: "GLOBAL-PHO-4X6-PRO",
129
- url: "http://example.com/mytestphoto.jpg",
130
- copies: 1,
131
- )
132
- ```
133
-
134
- or you can add multiple images by passing a list of hashes to the pluralised method:
135
-
136
- ``` ruby
137
- order.add_images([
138
- {
139
- sku: "GLOBAL-PHO-4X6-PRO",
140
- url: "http://example.com/myTestPhoto.jpg",
141
- copies: 1,
142
- }, {
143
- sku: "GLOBAL-PHO-10X12-PRO",
144
- url: "http://example.com/myLargeTestPhoto.jpg",
145
- copies: 1,
146
- }
147
- ])
148
- ```
149
-
150
- On completion there will be a list of `Pwinty::Image` objects associated with `order.images`
151
-
152
-
153
- ### Submit, Cancel or Hold an order
116
+ This method will return a `Pwinty::Order` object.
154
117
 
155
- Before you submit you should run Validate and ensure there are no errors.
118
+ See https://www.prodigi.com/print-api/docs/reference/#order-actions for more on the actions
119
+ you can take on an order and at which point in an order lifecycle you can take them.
156
120
 
157
121
  ``` ruby
158
- order.submit
159
- >>> true
160
-
161
- order.cancel
162
- >>> true
163
-
164
- order.hold
165
- >>> true
122
+ order = Pwinty::Order.find('ord_1234')
123
+ cancelled_order = order.cancel
124
+ p cancelled_order.status.stage
125
+ >>> "Cancelled"
166
126
  ```
167
127
 
168
- These methods will either submit your order for processing, or cancel/hold the
169
- processing. Each will return a boolean.
170
-
171
128
  ### Check the shipment status of a submitted Order
172
129
 
173
130
  Once created you can use the `find` method to get the most up to date info about an Order.
@@ -175,12 +132,11 @@ Following submission, this will contain a shippingInfo with a price for shipping
175
132
  a list of `Pwinty::Shipment` objects
176
133
 
177
134
  ``` ruby
178
- order = Pwinty::Order.find(1)
179
- order.shippingInfo.price
180
- >>> 500
135
+ order = Pwinty::Order.find('ord_1234')
136
+ order.shipments
181
137
 
182
- order.shippingInfo.shipments[0]
183
- >>> #<Pwinty::Shipment shipmentId="1" isTracked=true trackingNumber="XYZ123456ABC" ...
138
+ order.shipments[0].dispatchDate
139
+ >>> '2022-04-29T00:00:00"
184
140
  ```
185
141
 
186
142
  ### List your orders
@@ -188,22 +144,17 @@ order.shippingInfo.shipments[0]
188
144
  ``` ruby
189
145
  orders = Pwinty::Order.list
190
146
  ```
191
- **N.B - This will get all of your orders - this can take some time. By default, it will request the orders from Pwinty in batches of 50; so 500 orders will take 10 requests to complete.**
147
+ **N.B - This will get all of your orders - this can take some time. By default, it will request the orders from Pwinty in batches of 10; so 500 orders will take 50 requests to complete.**
192
148
 
193
149
  Will return an array of `Pwinty::Order` objects.
194
150
 
195
- ### Count your orders
196
-
197
- ``` ruby
198
- count = Pwinty::Order.count
199
- ```
200
- Will return an integer of the number of orders you have.
201
-
202
-
203
151
 
204
152
  ## Development
205
153
 
206
- After checking out the repo, run `bundle` to install dependencies.
154
+ There is a VSCode devcontainer included, so reopen the repo in a devcontainer if you want
155
+ a quick way to setup your ruby environment. This defaults to using ruby v3
156
+
157
+ After checking out the repo, or opening in a devcontainer, run `bundle` to install dependencies.
207
158
 
208
159
  Then, run `rake` to run the tests.
209
160
 
@@ -0,0 +1,114 @@
1
+ require 'dry/struct/with_setters'
2
+
3
+ require "pwinty/api_models/order_asset"
4
+ require "pwinty/api_models/order_charge"
5
+ require "pwinty/api_models/order_cost"
6
+ require "pwinty/api_models/order_item"
7
+ require "pwinty/api_models/order_packing_slip"
8
+ require "pwinty/api_models/order_recipient"
9
+ require "pwinty/api_models/order_shipment"
10
+ require "pwinty/api_models/order_status"
11
+
12
+ module Pwinty
13
+
14
+ DEFAULT_PAGE_SIZE = 10
15
+
16
+ class Order < Pwinty::Base
17
+ """https://www.prodigi.com/print-api/docs/reference/#order-object"""
18
+ attribute? :id, Types::String.optional
19
+ attribute? :created, Types::String.optional
20
+ attribute? :callbackUrl, Types::String.optional
21
+ attribute? :merchantReference, Types::String.optional
22
+ attribute? :shippingMethod, Types::String.optional
23
+ attribute? :idempotencyKey, Types::String.optional
24
+ attribute? :status, Pwinty::OrderStatus.optional
25
+ attribute? :charges, Types::Array.of(Pwinty::OrderCharge).optional
26
+ attribute? :shipments, Types::Array.of(Pwinty::OrderShipment).optional
27
+ attribute? :recipient, Pwinty::OrderRecipient.default(Pwinty::OrderRecipient.new)
28
+ attribute? :items, Types::Array.of(Pwinty::OrderItem).default([])
29
+ attribute? :packingSlip, Pwinty::OrderPackingSlip.optional
30
+ attribute? :metadata, Types::Hash.optional
31
+
32
+ def self.find(id)
33
+ response = Pwinty.conn.get("orders/#{id}")
34
+ new(response.body['order'])
35
+ end
36
+
37
+ def self.list(page_size: DEFAULT_PAGE_SIZE, limit: 0)
38
+ """ Get all of the orders - this can take a while!
39
+
40
+ Page size maximum is 100.
41
+ Limit of 0 will get all of them.
42
+ """
43
+ all_orders = list_each_page(page_size: page_size, limit: limit)
44
+ Pwinty.collate_results(all_orders, self)
45
+ end
46
+
47
+ def self.list_each_page(page_size: DEFAULT_PAGE_SIZE, limit: 0)
48
+ all_orders = []
49
+ page_start = 0
50
+ has_more = true
51
+ limit_reached = false
52
+ while has_more and not limit_reached
53
+ response = Pwinty.conn.get("orders?top=#{page_size}&skip=#{page_start}")
54
+ all_orders = all_orders + response.body['orders']
55
+ page_start += page_size
56
+ limit_reached = Pwinty::is_limit_reached(all_orders.count, limit: limit)
57
+ has_more = response.body['hasMore']
58
+ end
59
+ all_orders
60
+ end
61
+
62
+ def add_image image
63
+ self.items << Pwinty::OrderItem.new(
64
+ sku: image[:sku],
65
+ copies: image[:copies],
66
+ assets: [Pwinty::OrderAsset.new(
67
+ url: image[:url],
68
+ )]
69
+ )
70
+ end
71
+
72
+ def serializable
73
+ order_attrs = Hash.new
74
+ order_attrs.update(self.attributes)
75
+
76
+ order_attrs[:items] = []
77
+ for item in self.items
78
+ order_attrs[:items] << item.serializable
79
+ end
80
+
81
+ order_attrs[:recipient] = self.recipient.serializable
82
+ order_attrs
83
+ end
84
+
85
+ def submit
86
+ """Send the order to Prodigi."""
87
+ response = Pwinty.conn.post("orders", self.serializable)
88
+ new(response.body['order'])
89
+ end
90
+
91
+ def cancel
92
+ """Cancel the order.
93
+ https://www.prodigi.com/print-api/docs/reference/#cancel-an-order
94
+ """
95
+ response = Pwinty.conn.post("orders/#{self.id}/actions/cancel")
96
+ outcome = response.body['outcome']
97
+ case outcome
98
+ when 'failedToCancel'; raise Pwinty::Error, response.body
99
+ when 'actionNotAvailable'; raise Pwinty::OrderActionUnavailable, response.body
100
+ end
101
+
102
+ new(response.body['order'])
103
+ end
104
+
105
+ end
106
+
107
+ protected
108
+
109
+ def self.is_limit_reached(number_of_records, limit: 0)
110
+ return false if limit === 0
111
+ return number_of_records >= limit
112
+ end
113
+
114
+ end
@@ -0,0 +1,7 @@
1
+ module Pwinty
2
+ class OrderAsset < Pwinty::Base
3
+ """https://www.prodigi.com/print-api/docs/reference/#order-object-asset"""
4
+ attribute? :printArea, Types::String.default('default')
5
+ attribute? :url, Types::String
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Pwinty
2
+ class OrderCharge < Pwinty::Base
3
+ """https://www.prodigi.com/print-api/docs/reference/#order-object-charge"""
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module Pwinty
2
+ class OrderCost < Pwinty::Base
3
+ """https://www.prodigi.com/print-api/docs/reference/#order-object-cost"""
4
+ attribute? :amount, Types::String.optional
5
+ attribute? :currency, Types::String.optional
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ module Pwinty
2
+ class OrderItem < Pwinty::Base
3
+ """https://www.prodigi.com/print-api/docs/reference/#order-object-item"""
4
+ attribute? :id, Types::String.optional
5
+ attribute? :merchantReference, Types::String.optional
6
+ attribute? :sku, Types::String
7
+ attribute? :copies, Types::Integer
8
+ attribute? :sizing, Types::String.default('fillPrintArea')
9
+ attribute? :assets, Types::Array.of(Pwinty::OrderAsset)
10
+ attribute? :attributes, Types::Hash
11
+
12
+ def serializable
13
+ item_attrs = Hash.new
14
+ item_attrs.update(self.attributes)
15
+ item_attrs[:assets] = []
16
+ for asset in self.assets
17
+ item_attrs[:assets] << asset.attributes
18
+ end
19
+ item_attrs
20
+ end
21
+
22
+ end
23
+
24
+ end