pwinty 3.0.3 → 3.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env.sample +2 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +8 -0
- data/.travis.yml +1 -1
- data/Gemfile.lock +52 -53
- data/README.md +14 -6
- data/lib/pwinty.rb +42 -42
- data/lib/pwinty/base.rb +6 -6
- data/lib/pwinty/country.rb +8 -8
- data/lib/pwinty/http_errors.rb +11 -11
- data/lib/pwinty/image.rb +21 -21
- data/lib/pwinty/order.rb +127 -110
- data/lib/pwinty/order_status.rb +11 -11
- data/lib/pwinty/photo_status.rb +5 -5
- data/lib/pwinty/shipment.rb +11 -11
- data/lib/pwinty/shipping_info.rb +4 -4
- data/lib/pwinty/version.rb +1 -1
- data/pwinty.gemspec +3 -2
- metadata +25 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6dcf71ee9a54e4f465c63cb14f36b5e381daafdbc7977481348064bad6682f16
|
4
|
+
data.tar.gz: 0f8ccb3c28d7acd1d9dfbf2fba587079d4462f77dbef597f885ddfca91c5904c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cd4afa3d875a3bb268ce2278c638187707a7b65d2629feac438ecb53637cb66c91afb22efbed66947520349bde4a3626a8e8aa2e39933e1fac973d29b0a4537
|
7
|
+
data.tar.gz: 7c99cc760d7ae010dbeb3c166418b8ccaef6b3a8ca69f6baffb7a5b692f2eb5a3f8c1b4100a9445f104e46f13eddc3e6302cee6fe696e44f9f01dc67e7b184c8
|
data/.env.sample
ADDED
data/.gitignore
CHANGED
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,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pwinty (3.0.
|
4
|
+
pwinty (3.0.7)
|
5
5
|
dry-struct (~> 1.0)
|
6
6
|
dry-struct-setters (~> 0.2)
|
7
7
|
faraday (~> 0.15)
|
@@ -11,87 +11,86 @@ PATH
|
|
11
11
|
GEM
|
12
12
|
remote: https://rubygems.org/
|
13
13
|
specs:
|
14
|
-
addressable (2.
|
15
|
-
public_suffix (>= 2.0.2, <
|
16
|
-
concurrent-ruby (1.1.
|
17
|
-
crack (0.4.
|
18
|
-
|
19
|
-
diff-lcs (1.
|
20
|
-
docile (1.
|
21
|
-
|
14
|
+
addressable (2.8.0)
|
15
|
+
public_suffix (>= 2.0.2, < 5.0)
|
16
|
+
concurrent-ruby (1.1.9)
|
17
|
+
crack (0.4.5)
|
18
|
+
rexml
|
19
|
+
diff-lcs (1.4.4)
|
20
|
+
docile (1.4.0)
|
21
|
+
dotenv (2.7.6)
|
22
|
+
dry-configurable (0.12.1)
|
22
23
|
concurrent-ruby (~> 1.0)
|
23
|
-
dry-core (~> 0.
|
24
|
+
dry-core (~> 0.5, >= 0.5.0)
|
24
25
|
dry-container (0.7.2)
|
25
26
|
concurrent-ruby (~> 1.0)
|
26
27
|
dry-configurable (~> 0.1, >= 0.1.3)
|
27
|
-
dry-core (0.
|
28
|
+
dry-core (0.6.0)
|
28
29
|
concurrent-ruby (~> 1.0)
|
29
|
-
dry-
|
30
|
-
dry-
|
31
|
-
dry-logic (1.0.3)
|
30
|
+
dry-inflector (0.2.0)
|
31
|
+
dry-logic (1.2.0)
|
32
32
|
concurrent-ruby (~> 1.0)
|
33
|
-
dry-core (~> 0.
|
34
|
-
|
35
|
-
|
36
|
-
dry-
|
37
|
-
dry-equalizer (~> 0.2)
|
38
|
-
dry-types (~> 1.0)
|
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)
|
39
37
|
ice_nine (~> 0.11)
|
40
|
-
dry-struct-setters (0.
|
41
|
-
dry-struct (>= 0.
|
42
|
-
dry-types (1.
|
38
|
+
dry-struct-setters (0.3.0)
|
39
|
+
dry-struct (>= 1.0.0)
|
40
|
+
dry-types (1.5.1)
|
43
41
|
concurrent-ruby (~> 1.0)
|
44
42
|
dry-container (~> 0.3)
|
45
|
-
dry-core (~> 0.
|
46
|
-
dry-equalizer (~> 0.2, >= 0.2.2)
|
43
|
+
dry-core (~> 0.5, >= 0.5)
|
47
44
|
dry-inflector (~> 0.1, >= 0.1.2)
|
48
45
|
dry-logic (~> 1.0, >= 1.0.2)
|
49
|
-
faraday (0.
|
46
|
+
faraday (0.17.4)
|
50
47
|
multipart-post (>= 1.2, < 3)
|
51
|
-
faraday_middleware (0.
|
48
|
+
faraday_middleware (0.14.0)
|
52
49
|
faraday (>= 0.7.4, < 1.0)
|
53
|
-
hashdiff (1.0.
|
50
|
+
hashdiff (1.0.1)
|
54
51
|
ice_nine (0.11.2)
|
55
|
-
json (2.
|
52
|
+
json (2.5.1)
|
56
53
|
multipart-post (2.1.1)
|
57
|
-
public_suffix (
|
58
|
-
rake (
|
59
|
-
|
60
|
-
|
61
|
-
rspec-
|
62
|
-
rspec-
|
63
|
-
|
64
|
-
|
65
|
-
|
54
|
+
public_suffix (4.0.6)
|
55
|
+
rake (13.0.6)
|
56
|
+
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)
|
66
64
|
diff-lcs (>= 1.2.0, < 2.0)
|
67
|
-
rspec-support (~> 3.
|
68
|
-
rspec-mocks (3.
|
65
|
+
rspec-support (~> 3.10.0)
|
66
|
+
rspec-mocks (3.10.2)
|
69
67
|
diff-lcs (>= 1.2.0, < 2.0)
|
70
|
-
rspec-support (~> 3.
|
71
|
-
rspec-support (3.
|
72
|
-
|
73
|
-
simplecov (0.17.0)
|
68
|
+
rspec-support (~> 3.10.0)
|
69
|
+
rspec-support (3.10.2)
|
70
|
+
simplecov (0.21.2)
|
74
71
|
docile (~> 1.1)
|
75
|
-
|
76
|
-
|
77
|
-
simplecov-html (0.
|
78
|
-
|
79
|
-
|
72
|
+
simplecov-html (~> 0.11)
|
73
|
+
simplecov_json_formatter (~> 0.1)
|
74
|
+
simplecov-html (0.12.3)
|
75
|
+
simplecov_json_formatter (0.1.3)
|
76
|
+
vcr (5.1.0)
|
77
|
+
webmock (3.13.0)
|
80
78
|
addressable (>= 2.3.6)
|
81
79
|
crack (>= 0.3.2)
|
82
80
|
hashdiff (>= 0.4.0, < 2.0.0)
|
83
81
|
|
84
82
|
PLATFORMS
|
85
|
-
|
83
|
+
x86_64-darwin-18
|
86
84
|
|
87
85
|
DEPENDENCIES
|
88
|
-
bundler (~>
|
86
|
+
bundler (~> 2.2.10)
|
87
|
+
dotenv (~> 2.7.5)
|
89
88
|
pwinty!
|
90
|
-
rake (~>
|
89
|
+
rake (~> 13.0)
|
91
90
|
rspec (~> 3.0)
|
92
91
|
simplecov (~> 0.17)
|
93
92
|
vcr (~> 5.0)
|
94
93
|
webmock (~> 3.6)
|
95
94
|
|
96
95
|
BUNDLED WITH
|
97
|
-
|
96
|
+
2.2.23
|
data/README.md
CHANGED
@@ -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', '~>3'
|
22
22
|
```
|
23
23
|
|
24
24
|
And then execute:
|
@@ -188,8 +188,7 @@ order.shippingInfo.shipments[0]
|
|
188
188
|
``` ruby
|
189
189
|
orders = Pwinty::Order.list
|
190
190
|
```
|
191
|
-
**N.B -
|
192
|
-
So you can only get the latest 100 results at this moment.**
|
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.**
|
193
192
|
|
194
193
|
Will return an array of `Pwinty::Order` objects.
|
195
194
|
|
@@ -204,13 +203,22 @@ Will return an integer of the number of orders you have.
|
|
204
203
|
|
205
204
|
## Development
|
206
205
|
|
207
|
-
After checking out the repo, run `bundle` to install dependencies.
|
208
|
-
|
206
|
+
After checking out the repo, run `bundle` to install dependencies.
|
207
|
+
|
208
|
+
Then, run `rake` to run the tests.
|
209
|
+
|
210
|
+
You can also run `bin/console` for an interactive
|
209
211
|
prompt that will allow you to experiment.
|
210
212
|
|
211
|
-
The tests use VCRs to mock the responses from Pwinty's API.
|
213
|
+
The tests use VCRs to mock the responses from Pwinty's API. See the
|
214
|
+
spec/vcrs directory for some example responses from the Pwinty API
|
215
|
+
which are used in the existing tests.
|
212
216
|
|
213
217
|
To install this gem onto your local machine, run `bundle exec rake install`.
|
218
|
+
|
219
|
+
You can create a `.env` file based on the provided `.env.sample` to hold your Pwinty sandbox credentials.
|
220
|
+
|
221
|
+
#### For project owners only:
|
214
222
|
To release a new version, update the version number in `version.rb`, and then
|
215
223
|
run `bundle exec rake release`, which will create a git tag for the version,
|
216
224
|
push git commits and tags, and push the `.gem` file to
|
data/lib/pwinty.rb
CHANGED
@@ -13,50 +13,50 @@ require "pwinty/shipping_info"
|
|
13
13
|
require "pwinty/version"
|
14
14
|
|
15
15
|
module Pwinty
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
16
|
+
class Error < StandardError; end
|
17
|
+
class AuthenticationError < Pwinty::Error; end
|
18
|
+
class OrderNotFound < Pwinty::Error; end
|
19
|
+
class StateIsInvalid < Pwinty::Error; end
|
20
|
+
|
21
|
+
MERCHANT_ID = ENV['PWINTY_MERCHANT_ID']
|
22
|
+
API_KEY = ENV['PWINTY_API_KEY']
|
23
|
+
BASE_URL = ENV['PWINTY_BASE_URL'] || 'https://sandbox.pwinty.com'
|
24
|
+
API_VERSION = 'v3.0'
|
25
|
+
|
26
|
+
class << self
|
27
|
+
attr_accessor :logger
|
28
|
+
def logger
|
29
|
+
@logger ||= Logger.new($stdout).tap do |log|
|
30
|
+
log.progname = self.name
|
31
|
+
end
|
33
32
|
end
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.url
|
36
|
+
"#{Pwinty::BASE_URL}/#{Pwinty::API_VERSION}/"
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.headers
|
40
|
+
{
|
41
|
+
'X-Pwinty-MerchantId' => Pwinty::MERCHANT_ID,
|
42
|
+
'X-Pwinty-REST-API-Key' => Pwinty::API_KEY,
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.conn
|
47
|
+
Faraday.new(url: url, headers: headers) do |config|
|
48
|
+
config.request :json
|
49
|
+
config.response :json
|
50
|
+
config.use Pwinty::HttpErrors
|
51
|
+
config.adapter Faraday.default_adapter
|
53
52
|
end
|
53
|
+
end
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
60
|
-
collection
|
55
|
+
def self.collate_results(response_data, targetted_class)
|
56
|
+
collection = []
|
57
|
+
response_data.each do |individual_attr|
|
58
|
+
collection << targetted_class.new(individual_attr)
|
61
59
|
end
|
60
|
+
collection
|
61
|
+
end
|
62
62
|
end
|
data/lib/pwinty/base.rb
CHANGED
@@ -2,11 +2,11 @@ require 'dry-struct'
|
|
2
2
|
|
3
3
|
module Pwinty
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
module Types
|
6
|
+
include Dry::Types()
|
7
|
+
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
class Base < Dry::Struct
|
10
|
+
transform_keys(&:to_sym)
|
11
|
+
end
|
12
12
|
end
|
data/lib/pwinty/country.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module Pwinty
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
class Country < Pwinty::Base
|
4
|
+
attribute :name, Types::String
|
5
|
+
attribute :isoCode, Types::String
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
def self.list
|
8
|
+
response = Pwinty.conn.get("countries")
|
9
|
+
Pwinty.collate_results(response.body['data'], self)
|
10
|
+
end
|
11
|
+
end
|
12
12
|
end
|
data/lib/pwinty/http_errors.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module Pwinty
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
2
|
+
class HttpErrors < Faraday::Response::Middleware
|
3
|
+
def on_complete(env)
|
4
|
+
msg = env[:body]
|
5
|
+
case env[:status]
|
6
|
+
when 401; raise Pwinty::AuthenticationError, msg
|
7
|
+
when 403; raise Pwinty::StateIsInvalid, msg
|
8
|
+
when 404; raise Pwinty::NotFound, msg
|
9
|
+
when 500; raise Pwinty::Error, msg
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
13
|
end
|
data/lib/pwinty/image.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
module Pwinty
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
3
|
+
class Image < Pwinty::Base
|
4
|
+
attribute :id, Types::Integer
|
5
|
+
attribute :url, Types::String
|
6
|
+
attribute :status, Types::String
|
7
|
+
attribute :copies, Types::Integer
|
8
|
+
attribute :sizing, Types::String
|
9
|
+
attribute :price, Types::Integer
|
10
|
+
attribute :priceToUser, Types::Integer.optional
|
11
|
+
attribute :md5Hash, Types::String.optional
|
12
|
+
attribute :previewUrl, Types::String.optional
|
13
|
+
attribute :thumbnailUrl, Types::String.optional
|
14
|
+
attribute :sku, Types::String
|
15
|
+
attribute :attributes, Types::Hash.schema(
|
16
|
+
substrateWeight?: Types::String.optional,
|
17
|
+
frame?: Types::String.optional,
|
18
|
+
edge?: Types::String.optional,
|
19
|
+
paperType?: Types::String.optional,
|
20
|
+
frameColour?: Types::String.optional,
|
21
|
+
).optional
|
22
|
+
attribute :errorMessage, Types::String.optional
|
23
|
+
end
|
24
24
|
end
|
data/lib/pwinty/order.rb
CHANGED
@@ -3,116 +3,133 @@ require 'dry/struct/with_setters'
|
|
3
3
|
require "pwinty/shipping_info"
|
4
4
|
|
5
5
|
module Pwinty
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
def submit
|
84
|
-
self.update_status 'Submitted'
|
85
|
-
end
|
86
|
-
|
87
|
-
def cancel
|
88
|
-
self.update_status 'Cancelled'
|
89
|
-
end
|
90
|
-
|
91
|
-
def hold
|
92
|
-
self.update_status 'AwaitingPayment'
|
93
|
-
end
|
94
|
-
|
95
|
-
def add_image image
|
96
|
-
images = add_images([image])
|
97
|
-
self.images
|
98
|
-
end
|
99
|
-
|
100
|
-
def add_images images
|
101
|
-
response = Pwinty.conn.post("orders/#{self.id}/images/batch", images)
|
102
|
-
images = Pwinty.collate_results(response.body['data']['items'], Pwinty::Image)
|
103
|
-
self.images = self.images + images
|
104
|
-
end
|
105
|
-
|
106
|
-
protected
|
107
|
-
|
108
|
-
def update_status status
|
109
|
-
response = Pwinty.conn.post("orders/#{self.id}/status", {status: status})
|
110
|
-
success = response.status == 200
|
111
|
-
unless success
|
112
|
-
Pwinty.logger.warn response.body['statusTxt']
|
113
|
-
end
|
114
|
-
success
|
115
|
-
end
|
6
|
+
class Order < Pwinty::Base
|
7
|
+
include Dry::Struct::Setters
|
8
|
+
include Dry::Struct::Setters::MassAssignment
|
9
|
+
|
10
|
+
attribute :id, Types::Integer
|
11
|
+
attribute :address1, Types::String.optional
|
12
|
+
attribute :address2, Types::String.optional
|
13
|
+
attribute :postalOrZipCode, Types::String.optional
|
14
|
+
attribute :countryCode, Types::String
|
15
|
+
attribute :addressTownOrCity, Types::String.optional
|
16
|
+
attribute :recipientName, Types::String.optional
|
17
|
+
attribute :stateOrCounty, Types::String.optional
|
18
|
+
attribute :status, Types::String
|
19
|
+
attribute :payment, Types::String
|
20
|
+
attribute? :packingSlipUrl, Types::String.optional
|
21
|
+
attribute :paymentUrl, Types::String.optional
|
22
|
+
attribute :price, Types::Integer
|
23
|
+
attribute :shippingInfo, Pwinty::ShippingInfo
|
24
|
+
attribute :images, Types::Array.of(Pwinty::Image)
|
25
|
+
attribute :merchantOrderId, Types::String.optional
|
26
|
+
attribute :preferredShippingMethod, Types::String
|
27
|
+
attribute :mobileTelephone, Types::String.optional
|
28
|
+
attribute :created, Types::JSON::DateTime
|
29
|
+
attribute :lastUpdated, Types::JSON::DateTime
|
30
|
+
attribute :canCancel, Types::Bool
|
31
|
+
attribute :canHold, Types::Bool
|
32
|
+
attribute :canUpdateShipping, Types::Bool
|
33
|
+
attribute :canUpdateImages, Types::Bool
|
34
|
+
attribute :errorMessage, Types::String.optional
|
35
|
+
attribute :invoiceAmountNet, Types::Integer
|
36
|
+
attribute :invoiceTax, Types::Integer
|
37
|
+
attribute :invoiceCurrency, Types::String.optional
|
38
|
+
attribute :tag, Types::String.optional
|
39
|
+
|
40
|
+
def self.list(page_size=50)
|
41
|
+
all_orders = list_each_page(page_size)
|
42
|
+
Pwinty.collate_results(all_orders, self)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.list_each_page(page_size, page_start=0, total_orders_count=nil)
|
46
|
+
all_orders = []
|
47
|
+
while total_orders_count.nil? or all_orders.count < total_orders_count
|
48
|
+
response = Pwinty.conn.get("orders?limit=#{page_size}&start=#{page_start}")
|
49
|
+
total_orders_count ||= response.body['data']['count']
|
50
|
+
all_orders = all_orders + response.body['data']['content']
|
51
|
+
page_start = page_start + page_size
|
52
|
+
end
|
53
|
+
all_orders
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
def self.count
|
58
|
+
response = Pwinty.conn.get("orders?count=1&offset=0")
|
59
|
+
response.body['data']['count']
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def self.create(**args)
|
64
|
+
response = Pwinty.conn.post("orders", args)
|
65
|
+
new(response.body['data'])
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.find(id)
|
69
|
+
response = Pwinty.conn.get("orders/#{id}")
|
70
|
+
new(response.body['data'])
|
71
|
+
end
|
72
|
+
|
73
|
+
def update(**args)
|
74
|
+
update_body = self.to_hash.merge(args)
|
75
|
+
response = Pwinty.conn.put("orders/#{self.id}/", update_body)
|
76
|
+
update_instance_attributes(response.body['data'])
|
77
|
+
end
|
78
|
+
|
79
|
+
def submission_status
|
80
|
+
response = Pwinty.conn.get("orders/#{id}/SubmissionStatus")
|
81
|
+
Pwinty::OrderStatus.new(response.body['data'])
|
82
|
+
end
|
116
83
|
|
84
|
+
def submit
|
85
|
+
self.update_status 'Submitted'
|
117
86
|
end
|
87
|
+
|
88
|
+
def cancel
|
89
|
+
self.update_status 'Cancelled'
|
90
|
+
end
|
91
|
+
|
92
|
+
def hold
|
93
|
+
self.update_status 'AwaitingPayment'
|
94
|
+
end
|
95
|
+
|
96
|
+
def add_image image
|
97
|
+
images = add_images([image])
|
98
|
+
self.images
|
99
|
+
end
|
100
|
+
|
101
|
+
def add_images images
|
102
|
+
response = Pwinty.conn.post("orders/#{self.id}/images/batch", images)
|
103
|
+
success = response.status == 200
|
104
|
+
unless success
|
105
|
+
Pwinty.logger.warn response.body['statusTxt']
|
106
|
+
end
|
107
|
+
if response.body['data'] && response.body['data']['items']
|
108
|
+
images = Pwinty.collate_results(response.body['data']['items'], Pwinty::Image)
|
109
|
+
self.images = self.images + images
|
110
|
+
end
|
111
|
+
self.images
|
112
|
+
end
|
113
|
+
|
114
|
+
def update_instance_attributes(attrs)
|
115
|
+
self.assign_attributes(attrs)
|
116
|
+
end
|
117
|
+
|
118
|
+
def packingSlipUrl=(new_url)
|
119
|
+
# Work around for https://github.com/tomharvey/pwinty3-rb/issues/14
|
120
|
+
@attributes[:packingSlipUrl] = new_url
|
121
|
+
end
|
122
|
+
|
123
|
+
protected
|
124
|
+
|
125
|
+
def update_status status
|
126
|
+
response = Pwinty.conn.post("orders/#{self.id}/status", {status: status})
|
127
|
+
success = response.status == 200
|
128
|
+
unless success
|
129
|
+
Pwinty.logger.warn response.body['statusTxt']
|
130
|
+
end
|
131
|
+
success
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
118
135
|
end
|
data/lib/pwinty/order_status.rb
CHANGED
@@ -2,16 +2,16 @@ require 'pwinty/photo_status'
|
|
2
2
|
|
3
3
|
module Pwinty
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
class OrderStatus < Pwinty::Base
|
6
|
+
attribute :id, Types::Coercible::Integer
|
7
|
+
attribute :isValid, Types::Bool
|
8
|
+
attribute :generalErrors, Types::Array.of(Types::String)
|
9
|
+
attribute :photos, Types::Array.of(Pwinty::PhotoStatus)
|
10
|
+
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
def self.check(id)
|
13
|
+
response = Pwinty.conn.get("orders/#{id}/SubmissionStatus")
|
14
|
+
new(response.body['data'])
|
15
|
+
end
|
16
|
+
end
|
17
17
|
end
|
data/lib/pwinty/photo_status.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Pwinty
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
class PhotoStatus < Pwinty::Base
|
4
|
+
attribute :id, Types::Coercible::Integer
|
5
|
+
attribute :errors, Types::Array.of(Types::String)
|
6
|
+
attribute :warnings, Types::Array.of(Types::String)
|
7
|
+
end
|
8
8
|
end
|
data/lib/pwinty/shipment.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
module Pwinty
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
class Shipment < Pwinty::Base
|
4
|
+
attribute :shipmentId, Types::String.optional
|
5
|
+
attribute :isTracked, Types::Bool
|
6
|
+
attribute :trackingNumber, Types::String.optional
|
7
|
+
attribute :trackingUrl, Types::String.optional
|
8
|
+
attribute :carrier, Types::String.optional
|
9
|
+
attribute :photoIds, Types::Array.of(Types::Integer)
|
10
|
+
attribute :earliestEstimatedArrivalDate, Types::JSON::DateTime.optional
|
11
|
+
attribute :latestEstimatedArrivalDate, Types::JSON::DateTime.optional
|
12
|
+
attribute :shippedOn, Types::JSON::DateTime.optional
|
13
|
+
end
|
14
14
|
end
|
data/lib/pwinty/shipping_info.rb
CHANGED
@@ -2,8 +2,8 @@ require "pwinty/shipment"
|
|
2
2
|
|
3
3
|
module Pwinty
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
class ShippingInfo < Pwinty::Base
|
6
|
+
attribute :price, Types::Integer
|
7
|
+
attribute :shipments, Types::Array.of(Pwinty::Shipment)
|
8
|
+
end
|
9
9
|
end
|
data/lib/pwinty/version.rb
CHANGED
data/pwinty.gemspec
CHANGED
@@ -27,13 +27,14 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
|
-
spec.add_development_dependency "bundler", "~>
|
31
|
-
spec.add_development_dependency "rake", "~>
|
30
|
+
spec.add_development_dependency "bundler", "~> 2.2.10"
|
31
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
32
32
|
spec.add_development_dependency "rspec", "~> 3.0"
|
33
33
|
|
34
34
|
spec.add_development_dependency "vcr", "~> 5.0"
|
35
35
|
spec.add_development_dependency "webmock", "~> 3.6"
|
36
36
|
spec.add_development_dependency "simplecov", "~> 0.17"
|
37
|
+
spec.add_development_dependency "dotenv", "~> 2.7.5"
|
37
38
|
|
38
39
|
spec.add_dependency "dry-struct", "~> 1.0"
|
39
40
|
spec.add_dependency "dry-struct-setters", "~> 0.2"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pwinty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Harvey
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.2.10
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.2.10
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '13.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '13.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0.17'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: dotenv
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.7.5
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.7.5
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: dry-struct
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -172,8 +186,10 @@ executables: []
|
|
172
186
|
extensions: []
|
173
187
|
extra_rdoc_files: []
|
174
188
|
files:
|
189
|
+
- ".env.sample"
|
175
190
|
- ".gitignore"
|
176
191
|
- ".rspec"
|
192
|
+
- ".rubocop.yml"
|
177
193
|
- ".travis.yml"
|
178
194
|
- CODE_OF_CONDUCT.md
|
179
195
|
- Gemfile
|
@@ -202,7 +218,7 @@ metadata:
|
|
202
218
|
homepage_uri: https://github.com/tomharvey/pwinty3-rb
|
203
219
|
source_code_uri: https://github.com/tomharvey/pwinty3-rb
|
204
220
|
documentation_uri: https://pwinty.com/api/
|
205
|
-
post_install_message:
|
221
|
+
post_install_message:
|
206
222
|
rdoc_options: []
|
207
223
|
require_paths:
|
208
224
|
- lib
|
@@ -218,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
218
234
|
version: '0'
|
219
235
|
requirements: []
|
220
236
|
rubygems_version: 3.0.6
|
221
|
-
signing_key:
|
237
|
+
signing_key:
|
222
238
|
specification_version: 4
|
223
239
|
summary: Order photo prints through Pwinty
|
224
240
|
test_files: []
|