pwinty 3.0.5 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.devcontainer/Dockerfile +17 -0
- data/.devcontainer/base.Dockerfile +43 -0
- data/.devcontainer/devcontainer.json +37 -0
- data/.rubocop.yml +8 -0
- data/.travis.yml +1 -1
- data/Gemfile.lock +82 -63
- data/README.md +50 -99
- data/lib/pwinty/api_models/order.rb +114 -0
- data/lib/pwinty/api_models/order_asset.rb +7 -0
- data/lib/pwinty/api_models/order_charge.rb +5 -0
- data/lib/pwinty/api_models/order_cost.rb +7 -0
- data/lib/pwinty/api_models/order_item.rb +24 -0
- data/lib/pwinty/api_models/order_packing_slip.rb +7 -0
- data/lib/pwinty/api_models/order_recipient.rb +17 -0
- data/lib/pwinty/api_models/order_recipient_address.rb +11 -0
- data/lib/pwinty/api_models/order_shipment.rb +16 -0
- data/lib/pwinty/api_models/order_shipment_carrier.rb +6 -0
- data/lib/pwinty/api_models/order_shipment_fulfillment_location.rb +7 -0
- data/lib/pwinty/api_models/order_shipment_item.rb +6 -0
- data/lib/pwinty/api_models/order_status.rb +11 -0
- data/lib/pwinty/api_models/order_status_auth_details.rb +7 -0
- data/lib/pwinty/api_models/order_status_details.rb +10 -0
- data/lib/pwinty/api_models/order_status_issue.rb +11 -0
- data/lib/pwinty/api_models/order_tracking.rb +6 -0
- data/lib/pwinty/api_models/product.rb +19 -0
- data/lib/pwinty/api_models/product_dimensions.rb +8 -0
- data/lib/pwinty/api_models/product_variant.rb +8 -0
- data/lib/pwinty/base.rb +6 -6
- data/lib/pwinty/http_errors.rb +13 -11
- data/lib/pwinty/version.rb +1 -1
- data/lib/pwinty.rb +48 -49
- data/pwinty.gemspec +13 -13
- metadata +56 -39
- data/lib/pwinty/country.rb +0 -12
- data/lib/pwinty/image.rb +0 -24
- data/lib/pwinty/order.rb +0 -126
- data/lib/pwinty/order_status.rb +0 -17
- data/lib/pwinty/photo_status.rb +0 -8
- data/lib/pwinty/shipment.rb +0 -14
- data/lib/pwinty/shipping_info.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 834f6357c9970480b7572f388a1ff47f27a50449b56b09ec9913fecf527e510c
|
4
|
+
data.tar.gz: 56552af641deb119beed08897f8f3ca3655554d58cfef1cd838a8f6b250e27c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
@@ -3,7 +3,7 @@ language: ruby
|
|
3
3
|
cache: bundler
|
4
4
|
rvm:
|
5
5
|
- 2.5.5
|
6
|
-
before_install: gem install bundler -v
|
6
|
+
before_install: gem install bundler -v 2.2.10
|
7
7
|
before_script:
|
8
8
|
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64
|
9
9
|
> ./cc-test-reporter
|
data/Gemfile.lock
CHANGED
@@ -1,99 +1,118 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pwinty (
|
4
|
+
pwinty (4.0.0)
|
5
5
|
dry-struct (~> 1.0)
|
6
|
-
dry-struct-setters (~> 0.
|
7
|
-
faraday (~> 0
|
8
|
-
faraday_middleware (~>
|
9
|
-
json (~> 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
|
-
addressable (2.
|
14
|
+
addressable (2.8.0)
|
15
15
|
public_suffix (>= 2.0.2, < 5.0)
|
16
|
-
concurrent-ruby (1.1.
|
17
|
-
crack (0.4.
|
18
|
-
|
19
|
-
diff-lcs (1.
|
20
|
-
docile (1.
|
21
|
-
dotenv (2.7.
|
22
|
-
dry-configurable (0.
|
16
|
+
concurrent-ruby (1.1.10)
|
17
|
+
crack (0.4.5)
|
18
|
+
rexml
|
19
|
+
diff-lcs (1.5.0)
|
20
|
+
docile (1.4.0)
|
21
|
+
dotenv (2.7.6)
|
22
|
+
dry-configurable (0.15.0)
|
23
23
|
concurrent-ruby (~> 1.0)
|
24
|
-
dry-core (~> 0.
|
25
|
-
|
26
|
-
dry-container (0.7.2)
|
24
|
+
dry-core (~> 0.6)
|
25
|
+
dry-container (0.9.0)
|
27
26
|
concurrent-ruby (~> 1.0)
|
28
|
-
dry-configurable (~> 0.
|
29
|
-
dry-core (0.
|
27
|
+
dry-configurable (~> 0.13, >= 0.13.0)
|
28
|
+
dry-core (0.7.1)
|
30
29
|
concurrent-ruby (~> 1.0)
|
31
|
-
dry-
|
32
|
-
dry-
|
33
|
-
dry-logic (1.0.6)
|
30
|
+
dry-inflector (0.2.1)
|
31
|
+
dry-logic (1.2.0)
|
34
32
|
concurrent-ruby (~> 1.0)
|
35
|
-
dry-core (~> 0.
|
36
|
-
|
37
|
-
|
38
|
-
dry-
|
39
|
-
dry-equalizer (~> 0.3)
|
40
|
-
dry-types (~> 1.3)
|
33
|
+
dry-core (~> 0.5, >= 0.5)
|
34
|
+
dry-struct (1.4.0)
|
35
|
+
dry-core (~> 0.5, >= 0.5)
|
36
|
+
dry-types (~> 1.5)
|
41
37
|
ice_nine (~> 0.11)
|
42
|
-
dry-struct-setters (0.
|
43
|
-
dry-struct (>=
|
44
|
-
dry-types (1.
|
38
|
+
dry-struct-setters (0.4.0)
|
39
|
+
dry-struct (>= 1.4.0)
|
40
|
+
dry-types (1.5.1)
|
45
41
|
concurrent-ruby (~> 1.0)
|
46
42
|
dry-container (~> 0.3)
|
47
|
-
dry-core (~> 0.
|
48
|
-
dry-equalizer (~> 0.3)
|
43
|
+
dry-core (~> 0.5, >= 0.5)
|
49
44
|
dry-inflector (~> 0.1, >= 0.1.2)
|
50
45
|
dry-logic (~> 1.0, >= 1.0.2)
|
51
|
-
faraday (
|
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)
|
52
63
|
multipart-post (>= 1.2, < 3)
|
53
|
-
|
54
|
-
|
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)
|
55
71
|
hashdiff (1.0.1)
|
56
72
|
ice_nine (0.11.2)
|
57
|
-
json (2.
|
73
|
+
json (2.6.1)
|
58
74
|
multipart-post (2.1.1)
|
59
|
-
public_suffix (4.0.
|
60
|
-
rake (13.0.
|
61
|
-
|
62
|
-
|
63
|
-
rspec-
|
64
|
-
rspec-
|
65
|
-
|
66
|
-
|
67
|
-
|
75
|
+
public_suffix (4.0.7)
|
76
|
+
rake (13.0.6)
|
77
|
+
rexml (3.2.5)
|
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)
|
68
85
|
diff-lcs (>= 1.2.0, < 2.0)
|
69
|
-
rspec-support (~> 3.
|
70
|
-
rspec-mocks (3.
|
86
|
+
rspec-support (~> 3.11.0)
|
87
|
+
rspec-mocks (3.11.1)
|
71
88
|
diff-lcs (>= 1.2.0, < 2.0)
|
72
|
-
rspec-support (~> 3.
|
73
|
-
rspec-support (3.
|
74
|
-
|
75
|
-
simplecov (0.
|
89
|
+
rspec-support (~> 3.11.0)
|
90
|
+
rspec-support (3.11.0)
|
91
|
+
ruby2_keywords (0.0.5)
|
92
|
+
simplecov (0.21.2)
|
76
93
|
docile (~> 1.1)
|
77
94
|
simplecov-html (~> 0.11)
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
95
|
+
simplecov_json_formatter (~> 0.1)
|
96
|
+
simplecov-html (0.12.3)
|
97
|
+
simplecov_json_formatter (0.1.4)
|
98
|
+
vcr (6.1.0)
|
99
|
+
webmock (3.14.0)
|
100
|
+
addressable (>= 2.8.0)
|
82
101
|
crack (>= 0.3.2)
|
83
102
|
hashdiff (>= 0.4.0, < 2.0.0)
|
84
103
|
|
85
104
|
PLATFORMS
|
86
|
-
|
105
|
+
aarch64-linux
|
87
106
|
|
88
107
|
DEPENDENCIES
|
89
|
-
bundler
|
108
|
+
bundler
|
90
109
|
dotenv (~> 2.7.5)
|
91
110
|
pwinty!
|
92
|
-
rake
|
93
|
-
rspec
|
94
|
-
simplecov (~> 0.
|
95
|
-
vcr (~>
|
96
|
-
webmock (~> 3.
|
111
|
+
rake
|
112
|
+
rspec
|
113
|
+
simplecov (~> 0.21)
|
114
|
+
vcr (~> 6.0)
|
115
|
+
webmock (~> 3.14)
|
97
116
|
|
98
117
|
BUNDLED WITH
|
99
|
-
|
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
|
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
|
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'
|
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.
|
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.
|
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
|
69
|
-
|
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://
|
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.
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|
-
|
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.
|
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
|
-
|
113
|
-
status = order.submission_status
|
114
|
-
```
|
112
|
+
### Cancel an order
|
115
113
|
|
116
|
-
|
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
|
-
|
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
|
-
|
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.
|
159
|
-
|
160
|
-
|
161
|
-
|
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(
|
179
|
-
order.
|
180
|
-
>>> 500
|
135
|
+
order = Pwinty::Order.find('ord_1234')
|
136
|
+
order.shipments
|
181
137
|
|
182
|
-
order.
|
183
|
-
>>>
|
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
|
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
|
-
|
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
|