pwinty 3.0.1 → 3.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5076f4e3e6fe45dc91cd6f502d24c3579406b2894e13835c4455feaeca66eb86
4
- data.tar.gz: '07998de4bca760eee940c24e235e36aa74a543a93aee204fe6bc5f5cf0109292'
3
+ metadata.gz: 290864d8b0b05f062c739b0ad74a6d5e4fb722a685343e20d3608529589d1d71
4
+ data.tar.gz: 825267f3abe3d13417380b5203aef156e2bc303f39d668859ff05af2259bfc9c
5
5
  SHA512:
6
- metadata.gz: d5ad732854db523ae41b30541cced1335616816219166caaa737a082fe6a55625c9c0d76cb678ce1056bbe70bb6d7d51f44766f16adf0f9c4e855b5dea09071d
7
- data.tar.gz: 2ee761b1229f0cf3b08ac81b27055016a54e1e394c5f93ee4d9c970d72671add4197681b598b09eb361d3acabfe0e7790335e19a4422c1b4626728721eb1b8e4
6
+ metadata.gz: 80d135300d8909a8676268a20de3d1febdaa3099008df4bed4a83440ffe03c23e584da706cbe79769736570411a8c21c0fbebb96427e1548ae5f6e3f0eef0801
7
+ data.tar.gz: 1e45b1a0072531eda9c95b77e7ca300a8fe4e9dc436f78220894072cbe15c70ad88da2ada678f356d789fe6e37440e35ba02fbb30dfa05a951be5139eda9309e
@@ -0,0 +1,2 @@
1
+ PWINTY_API_KEY=YOUR_PWINTY_API_KEY
2
+ PWINTY_MERCHANT_ID=YOUR_PWINTY_API_KEY
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /.env
9
10
 
10
11
  # rspec failure tracking
11
12
  .rspec_status
@@ -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.1)
4
+ pwinty (3.0.6)
5
5
  dry-struct (~> 1.0)
6
6
  dry-struct-setters (~> 0.2)
7
7
  faraday (~> 0.15)
@@ -11,72 +11,73 @@ PATH
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- addressable (2.6.0)
15
- public_suffix (>= 2.0.2, < 4.0)
16
- concurrent-ruby (1.1.5)
14
+ addressable (2.7.0)
15
+ public_suffix (>= 2.0.2, < 5.0)
16
+ concurrent-ruby (1.1.6)
17
17
  crack (0.4.3)
18
18
  safe_yaml (~> 1.0.0)
19
19
  diff-lcs (1.3)
20
20
  docile (1.3.2)
21
- dry-configurable (0.8.3)
21
+ dotenv (2.7.5)
22
+ dry-configurable (0.11.5)
22
23
  concurrent-ruby (~> 1.0)
23
24
  dry-core (~> 0.4, >= 0.4.7)
25
+ dry-equalizer (~> 0.2)
24
26
  dry-container (0.7.2)
25
27
  concurrent-ruby (~> 1.0)
26
28
  dry-configurable (~> 0.1, >= 0.1.3)
27
29
  dry-core (0.4.9)
28
30
  concurrent-ruby (~> 1.0)
29
- dry-equalizer (0.2.2)
30
- dry-inflector (0.1.2)
31
- dry-logic (1.0.3)
31
+ dry-equalizer (0.3.0)
32
+ dry-inflector (0.2.0)
33
+ dry-logic (1.0.6)
32
34
  concurrent-ruby (~> 1.0)
33
35
  dry-core (~> 0.2)
34
36
  dry-equalizer (~> 0.2)
35
- dry-struct (1.0.0)
36
- dry-core (~> 0.4, >= 0.4.3)
37
- dry-equalizer (~> 0.2)
38
- dry-types (~> 1.0)
37
+ dry-struct (1.3.0)
38
+ dry-core (~> 0.4, >= 0.4.4)
39
+ dry-equalizer (~> 0.3)
40
+ dry-types (~> 1.3)
39
41
  ice_nine (~> 0.11)
40
42
  dry-struct-setters (0.2.0)
41
43
  dry-struct (>= 0.5.0)
42
- dry-types (1.1.1)
44
+ dry-types (1.4.0)
43
45
  concurrent-ruby (~> 1.0)
44
46
  dry-container (~> 0.3)
45
47
  dry-core (~> 0.4, >= 0.4.4)
46
- dry-equalizer (~> 0.2, >= 0.2.2)
48
+ dry-equalizer (~> 0.3)
47
49
  dry-inflector (~> 0.1, >= 0.1.2)
48
50
  dry-logic (~> 1.0, >= 1.0.2)
49
- faraday (0.15.4)
51
+ faraday (0.17.3)
50
52
  multipart-post (>= 1.2, < 3)
51
- faraday_middleware (0.13.1)
53
+ faraday_middleware (0.14.0)
52
54
  faraday (>= 0.7.4, < 1.0)
53
- hashdiff (1.0.0)
55
+ hashdiff (1.0.1)
54
56
  ice_nine (0.11.2)
55
- json (2.2.0)
57
+ json (2.3.0)
56
58
  multipart-post (2.1.1)
57
- public_suffix (3.1.1)
58
- rake (10.5.0)
59
- rspec (3.8.0)
60
- rspec-core (~> 3.8.0)
61
- rspec-expectations (~> 3.8.0)
62
- rspec-mocks (~> 3.8.0)
63
- rspec-core (3.8.2)
64
- rspec-support (~> 3.8.0)
65
- rspec-expectations (3.8.4)
59
+ public_suffix (4.0.5)
60
+ rake (13.0.1)
61
+ rspec (3.9.0)
62
+ rspec-core (~> 3.9.0)
63
+ rspec-expectations (~> 3.9.0)
64
+ rspec-mocks (~> 3.9.0)
65
+ rspec-core (3.9.2)
66
+ rspec-support (~> 3.9.3)
67
+ rspec-expectations (3.9.2)
66
68
  diff-lcs (>= 1.2.0, < 2.0)
67
- rspec-support (~> 3.8.0)
68
- rspec-mocks (3.8.1)
69
+ rspec-support (~> 3.9.0)
70
+ rspec-mocks (3.9.1)
69
71
  diff-lcs (>= 1.2.0, < 2.0)
70
- rspec-support (~> 3.8.0)
71
- rspec-support (3.8.2)
72
+ rspec-support (~> 3.9.0)
73
+ rspec-support (3.9.3)
72
74
  safe_yaml (1.0.5)
73
- simplecov (0.17.0)
75
+ simplecov (0.18.5)
74
76
  docile (~> 1.1)
75
- json (>= 1.8, < 3)
76
- simplecov-html (~> 0.10.0)
77
- simplecov-html (0.10.2)
78
- vcr (5.0.0)
79
- webmock (3.6.2)
77
+ simplecov-html (~> 0.11)
78
+ simplecov-html (0.12.2)
79
+ vcr (5.1.0)
80
+ webmock (3.8.3)
80
81
  addressable (>= 2.3.6)
81
82
  crack (>= 0.3.2)
82
83
  hashdiff (>= 0.4.0, < 2.0.0)
@@ -86,8 +87,9 @@ PLATFORMS
86
87
 
87
88
  DEPENDENCIES
88
89
  bundler (~> 1.17)
90
+ dotenv (~> 2.7.5)
89
91
  pwinty!
90
- rake (~> 10.0)
92
+ rake (~> 13.0)
91
93
  rspec (~> 3.0)
92
94
  simplecov (~> 0.17)
93
95
  vcr (~> 5.0)
data/README.md CHANGED
@@ -188,8 +188,7 @@ order.shippingInfo.shipments[0]
188
188
  ``` ruby
189
189
  orders = Pwinty::Order.list
190
190
  ```
191
- **N.B - There appears to be an issue with the pagination of the list results from the API.
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. Then, run
208
- `rake` to run the tests. You can also run `bin/console` for an interactive
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
@@ -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::OrderNotFound, 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,
17
- frame: Types::String,
18
- edge: Types::String,
19
- paperType: Types::String,
20
- frameColour: Types::String,
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,108 +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 :paymentUrl, Types::String.optional
21
- attribute :price, Types::Integer
22
- attribute :shippingInfo, Pwinty::ShippingInfo
23
- attribute :images, Types::Array.of(Pwinty::Image)
24
- attribute :merchantOrderId, Types::String.optional
25
- attribute :preferredShippingMethod, Types::String
26
- attribute :mobileTelephone, Types::String.optional
27
- attribute :created, Types::JSON::DateTime
28
- attribute :lastUpdated, Types::JSON::DateTime
29
- attribute :canCancel, Types::Bool
30
- attribute :canHold, Types::Bool
31
- attribute :canUpdateShipping, Types::Bool
32
- attribute :canUpdateImages, Types::Bool
33
- attribute :errorMessage, Types::String.optional
34
- attribute :invoiceAmountNet, Types::Integer
35
- attribute :invoiceTax, Types::Integer
36
- attribute :invoiceCurrency, Types::String.optional
37
- attribute :tag, Types::String.optional
38
-
39
- def self.list
40
- response = Pwinty.conn.get("orders?count=250&offset=0")
41
- r_data = response.body['data']
42
- # TODO There is some bug with offset in the API.
43
- # total_count = r_data['count']
44
- Pwinty.collate_results(r_data['content'], self)
45
- end
46
-
47
-
48
- def self.count
49
- response = Pwinty.conn.get("orders?count=1&offset=0")
50
- response.body['data']['count']
51
- end
52
-
53
-
54
- def self.create(**args)
55
- response = Pwinty.conn.post("orders", args)
56
- new(response.body['data'])
57
- end
58
-
59
- def self.find(id)
60
- response = Pwinty.conn.get("orders/#{id}")
61
- new(response.body['data'])
62
- end
63
-
64
- def update(**args)
65
- update_body = self.to_hash.merge(args)
66
- response = Pwinty.conn.put("orders/#{self.id}/", update_body)
67
- self.assign_attributes(response.body['data'])
68
- end
69
-
70
- def submission_status
71
- response = Pwinty.conn.get("orders/#{id}/SubmissionStatus")
72
- Pwinty::OrderStatus.new(response.body['data'])
73
- end
74
-
75
- def submit
76
- self.update_status 'Submitted'
77
- end
78
-
79
- def cancel
80
- self.update_status 'Cancelled'
81
- end
82
-
83
- def hold
84
- self.update_status 'AwaitingPayment'
85
- end
86
-
87
- def add_image image
88
- images = add_images([image])
89
- self.images
90
- end
91
-
92
- def add_images images
93
- response = Pwinty.conn.post("orders/#{self.id}/images/batch", images)
94
- images = Pwinty.collate_results(response.body['data']['items'], Pwinty::Image)
95
- self.images = self.images + images
96
- end
97
-
98
- protected
99
-
100
- def update_status status
101
- response = Pwinty.conn.post("orders/#{self.id}/status", {status: status})
102
- success = response.status == 200
103
- unless success
104
- Pwinty.logger.warn response.body['statusTxt']
105
- end
106
- success
107
- 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
108
83
 
84
+ def submit
85
+ self.update_status 'Submitted'
109
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
110
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.1"
2
+ VERSION = "3.0.6"
3
3
  end
@@ -28,12 +28,13 @@ Gem::Specification.new do |spec|
28
28
  spec.require_paths = ["lib"]
29
29
 
30
30
  spec.add_development_dependency "bundler", "~> 1.17"
31
- spec.add_development_dependency "rake", "~> 10.0"
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.1
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: 2019-08-27 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
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
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: '10.0'
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