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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed7db0843764844edfd7aa88b2c2bcfd9ea3445363cce5ac04a099f0db05478a
4
- data.tar.gz: 0c8dfce677943320fa92a672a739c5ec05ae323357af47bcc3856426e44b06c1
3
+ metadata.gz: 290864d8b0b05f062c739b0ad74a6d5e4fb722a685343e20d3608529589d1d71
4
+ data.tar.gz: 825267f3abe3d13417380b5203aef156e2bc303f39d668859ff05af2259bfc9c
5
5
  SHA512:
6
- metadata.gz: dea713ec0c5667fa2578f9c82d8654f8b0bd25e2240715cc630db018414a3398f3744a7278c6b373363d74a2eae72e6b27a049904110aef013095d2c636475ea
7
- data.tar.gz: b816f723de43d8ac43d03077ad6d6ca1002d95ba12808caae6291fde1215ff9c3b57256a09ab0c890f8f7a95f22a869e1d9c1ee32706b40a93ee624ffc127287
6
+ metadata.gz: 80d135300d8909a8676268a20de3d1febdaa3099008df4bed4a83440ffe03c23e584da706cbe79769736570411a8c21c0fbebb96427e1548ae5f6e3f0eef0801
7
+ data.tar.gz: 1e45b1a0072531eda9c95b77e7ca300a8fe4e9dc436f78220894072cbe15c70ad88da2ada678f356d789fe6e37440e35ba02fbb30dfa05a951be5139eda9309e
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ DisabledByDefault: true
3
+ Layout/IndentationStyle:
4
+ Enabled: true
5
+ Layout/IndentationWidth:
6
+ Enabled: true
7
+ Layout/IndentationConsistency:
8
+ Enabled: true
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pwinty (3.0.5)
4
+ pwinty (3.0.6)
5
5
  dry-struct (~> 1.0)
6
6
  dry-struct-setters (~> 0.2)
7
7
  faraday (~> 0.15)
@@ -13,50 +13,50 @@ require "pwinty/shipping_info"
13
13
  require "pwinty/version"
14
14
 
15
15
  module Pwinty
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
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
- 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
52
- end
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
- def self.collate_results(response_data, targetted_class)
56
- collection = []
57
- response_data.each do |individual_attr|
58
- collection << targetted_class.new(individual_attr)
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
@@ -2,11 +2,11 @@ require 'dry-struct'
2
2
 
3
3
  module Pwinty
4
4
 
5
- module Types
6
- include Dry::Types()
7
- end
5
+ module Types
6
+ include Dry::Types()
7
+ end
8
8
 
9
- class Base < Dry::Struct
10
- transform_keys(&:to_sym)
11
- end
9
+ class Base < Dry::Struct
10
+ transform_keys(&:to_sym)
11
+ end
12
12
  end
@@ -1,12 +1,12 @@
1
1
  module Pwinty
2
2
 
3
- class Country < Pwinty::Base
4
- attribute :name, Types::String
5
- attribute :isoCode, Types::String
3
+ class Country < Pwinty::Base
4
+ attribute :name, Types::String
5
+ attribute :isoCode, Types::String
6
6
 
7
- def self.list
8
- response = Pwinty.conn.get("countries")
9
- Pwinty.collate_results(response.body['data'], self)
10
- end
11
- end
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
@@ -1,13 +1,13 @@
1
1
  module Pwinty
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
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
@@ -1,24 +1,24 @@
1
1
  module Pwinty
2
2
 
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
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
@@ -3,124 +3,132 @@ require 'dry/struct/with_setters'
3
3
  require "pwinty/shipping_info"
4
4
 
5
5
  module Pwinty
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
- self.assign_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
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
@@ -2,16 +2,16 @@ require 'pwinty/photo_status'
2
2
 
3
3
  module Pwinty
4
4
 
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
-
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
- def self.check(id)
13
- response = Pwinty.conn.get("orders/#{id}/SubmissionStatus")
14
- new(response.body['data'])
15
- end
16
- end
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
@@ -1,8 +1,8 @@
1
1
  module Pwinty
2
2
 
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
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
@@ -1,14 +1,14 @@
1
1
  module Pwinty
2
2
 
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
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
@@ -2,8 +2,8 @@ require "pwinty/shipment"
2
2
 
3
3
  module Pwinty
4
4
 
5
- class ShippingInfo < Pwinty::Base
6
- attribute :price, Types::Integer
7
- attribute :shipments, Types::Array.of(Pwinty::Shipment)
8
- end
5
+ class ShippingInfo < Pwinty::Base
6
+ attribute :price, Types::Integer
7
+ attribute :shipments, Types::Array.of(Pwinty::Shipment)
8
+ end
9
9
  end
@@ -1,3 +1,3 @@
1
1
  module Pwinty
2
- VERSION = "3.0.5"
2
+ VERSION = "3.0.6"
3
3
  end
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.5
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-05-19 00:00:00.000000000 Z
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
- rubygems_version: 3.0.6
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