pwinty 3.0.5 → 3.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -0
- data/Gemfile.lock +1 -1
- 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 +126 -118
- 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
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 290864d8b0b05f062c739b0ad74a6d5e4fb722a685343e20d3608529589d1d71
|
4
|
+
data.tar.gz: 825267f3abe3d13417380b5203aef156e2bc303f39d668859ff05af2259bfc9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80d135300d8909a8676268a20de3d1febdaa3099008df4bed4a83440ffe03c23e584da706cbe79769736570411a8c21c0fbebb96427e1548ae5f6e3f0eef0801
|
7
|
+
data.tar.gz: 1e45b1a0072531eda9c95b77e7ca300a8fe4e9dc436f78220894072cbe15c70ad88da2ada678f356d789fe6e37440e35ba02fbb30dfa05a951be5139eda9309e
|
data/.rubocop.yml
ADDED
data/Gemfile.lock
CHANGED
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,124 +3,132 @@ 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
|
-
|
84
|
-
def submit
|
85
|
-
self.update_status 'Submitted'
|
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
|
-
protected
|
115
|
-
|
116
|
-
def update_status status
|
117
|
-
response = Pwinty.conn.post("orders/#{self.id}/status", {status: status})
|
118
|
-
success = response.status == 200
|
119
|
-
unless success
|
120
|
-
Pwinty.logger.warn response.body['statusTxt']
|
121
|
-
end
|
122
|
-
success
|
123
|
-
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
|
124
83
|
|
84
|
+
def submit
|
85
|
+
self.update_status 'Submitted'
|
125
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
|
+
@attributes[:packingSlipUrl] = new_url
|
120
|
+
end
|
121
|
+
|
122
|
+
protected
|
123
|
+
|
124
|
+
def update_status status
|
125
|
+
response = Pwinty.conn.post("orders/#{self.id}/status", {status: status})
|
126
|
+
success = response.status == 200
|
127
|
+
unless success
|
128
|
+
Pwinty.logger.warn response.body['statusTxt']
|
129
|
+
end
|
130
|
+
success
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
126
134
|
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
|
11
|
+
attribute :latestEstimatedArrivalDate, Types::JSON::DateTime
|
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
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Harvey
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -189,6 +189,7 @@ files:
|
|
189
189
|
- ".env.sample"
|
190
190
|
- ".gitignore"
|
191
191
|
- ".rspec"
|
192
|
+
- ".rubocop.yml"
|
192
193
|
- ".travis.yml"
|
193
194
|
- CODE_OF_CONDUCT.md
|
194
195
|
- Gemfile
|
@@ -232,7 +233,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
232
233
|
- !ruby/object:Gem::Version
|
233
234
|
version: '0'
|
234
235
|
requirements: []
|
235
|
-
|
236
|
+
rubyforge_project:
|
237
|
+
rubygems_version: 2.7.7
|
236
238
|
signing_key:
|
237
239
|
specification_version: 4
|
238
240
|
summary: Order photo prints through Pwinty
|