pwinty 3.0.5 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/Dockerfile +17 -0
  3. data/.devcontainer/base.Dockerfile +43 -0
  4. data/.devcontainer/devcontainer.json +37 -0
  5. data/.rubocop.yml +8 -0
  6. data/.travis.yml +1 -1
  7. data/Gemfile.lock +82 -63
  8. data/README.md +50 -99
  9. data/lib/pwinty/api_models/order.rb +114 -0
  10. data/lib/pwinty/api_models/order_asset.rb +7 -0
  11. data/lib/pwinty/api_models/order_charge.rb +5 -0
  12. data/lib/pwinty/api_models/order_cost.rb +7 -0
  13. data/lib/pwinty/api_models/order_item.rb +24 -0
  14. data/lib/pwinty/api_models/order_packing_slip.rb +7 -0
  15. data/lib/pwinty/api_models/order_recipient.rb +17 -0
  16. data/lib/pwinty/api_models/order_recipient_address.rb +11 -0
  17. data/lib/pwinty/api_models/order_shipment.rb +16 -0
  18. data/lib/pwinty/api_models/order_shipment_carrier.rb +6 -0
  19. data/lib/pwinty/api_models/order_shipment_fulfillment_location.rb +7 -0
  20. data/lib/pwinty/api_models/order_shipment_item.rb +6 -0
  21. data/lib/pwinty/api_models/order_status.rb +11 -0
  22. data/lib/pwinty/api_models/order_status_auth_details.rb +7 -0
  23. data/lib/pwinty/api_models/order_status_details.rb +10 -0
  24. data/lib/pwinty/api_models/order_status_issue.rb +11 -0
  25. data/lib/pwinty/api_models/order_tracking.rb +6 -0
  26. data/lib/pwinty/api_models/product.rb +19 -0
  27. data/lib/pwinty/api_models/product_dimensions.rb +8 -0
  28. data/lib/pwinty/api_models/product_variant.rb +8 -0
  29. data/lib/pwinty/base.rb +6 -6
  30. data/lib/pwinty/http_errors.rb +13 -11
  31. data/lib/pwinty/version.rb +1 -1
  32. data/lib/pwinty.rb +48 -49
  33. data/pwinty.gemspec +13 -13
  34. metadata +56 -39
  35. data/lib/pwinty/country.rb +0 -12
  36. data/lib/pwinty/image.rb +0 -24
  37. data/lib/pwinty/order.rb +0 -126
  38. data/lib/pwinty/order_status.rb +0 -17
  39. data/lib/pwinty/photo_status.rb +0 -8
  40. data/lib/pwinty/shipment.rb +0 -14
  41. data/lib/pwinty/shipping_info.rb +0 -9
@@ -0,0 +1,5 @@
1
+ module Pwinty
2
+ class OrderCharge < Pwinty::Base
3
+ """https://www.prodigi.com/print-api/docs/reference/#order-object-charge"""
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module Pwinty
2
+ class OrderCost < Pwinty::Base
3
+ """https://www.prodigi.com/print-api/docs/reference/#order-object-cost"""
4
+ attribute? :amount, Types::String.optional
5
+ attribute? :currency, Types::String.optional
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ module Pwinty
2
+ class OrderItem < Pwinty::Base
3
+ """https://www.prodigi.com/print-api/docs/reference/#order-object-item"""
4
+ attribute? :id, Types::String.optional
5
+ attribute? :merchantReference, Types::String.optional
6
+ attribute? :sku, Types::String
7
+ attribute? :copies, Types::Integer
8
+ attribute? :sizing, Types::String.default('fillPrintArea')
9
+ attribute? :assets, Types::Array.of(Pwinty::OrderAsset)
10
+ attribute? :attributes, Types::Hash
11
+
12
+ def serializable
13
+ item_attrs = Hash.new
14
+ item_attrs.update(self.attributes)
15
+ item_attrs[:assets] = []
16
+ for asset in self.assets
17
+ item_attrs[:assets] << asset.attributes
18
+ end
19
+ item_attrs
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,7 @@
1
+ module Pwinty
2
+ class OrderPackingSlip < Pwinty::Base
3
+ """https://www.prodigi.com/print-api/docs/reference/#order-object-packing-slip"""
4
+ attribute? :url, Types::String.optional
5
+ attribute? :status, Types::String.optional
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ require "pwinty/api_models/order_recipient_address"
2
+
3
+ module Pwinty
4
+ class OrderRecipient < Pwinty::Base
5
+ """https://www.prodigi.com/print-api/docs/reference/#order-object-recipient"""
6
+ attribute? :name, Types::String.optional
7
+ attribute? :email, Types::String.optional
8
+ attribute? :phoneNumber, Types::String.optional
9
+ attribute? :address, Pwinty::OrderRecipientAddress
10
+
11
+ def serializable
12
+ recp_attrs = self.attributes
13
+ recp_attrs[:address] = self.address.attributes
14
+ recp_attrs
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ module Pwinty
2
+ class OrderRecipientAddress < Pwinty::Base
3
+ """https://www.prodigi.com/print-api/docs/reference/#order-object-address"""
4
+ attribute? :line1, Types::String.optional
5
+ attribute? :line2, Types::String.optional
6
+ attribute? :postalOrZipCode, Types::String.optional
7
+ attribute? :countryCode, Types::String.optional
8
+ attribute? :townOrCity, Types::String.optional
9
+ attribute? :stateOrCounty, Types::String.optional
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ require "pwinty/api_models/order_shipment_carrier"
2
+ require "pwinty/api_models/order_shipment_item"
3
+ require "pwinty/api_models/order_shipment_fulfillment_location"
4
+ require "pwinty/api_models/order_tracking"
5
+
6
+ module Pwinty
7
+ class OrderShipment < Pwinty::Base
8
+ """https://www.prodigi.com/print-api/docs/reference/#order-object-shipment"""
9
+ attribute? :id, Types::String.optional
10
+ attribute? :carrier, Pwinty::OrderShipmentCarrier.optional
11
+ attribute? :tracking, Pwinty::OrderTracking.optional
12
+ attribute? :dispatchDate, Types::String.optional
13
+ attribute? :items, Types::Array.of(Pwinty::OrderShipmentItem).optional
14
+ attribute? :fulfillmentLocation, Pwinty::OrderShipmentFulfillmentLocation
15
+ end
16
+ end
@@ -0,0 +1,6 @@
1
+ module Pwinty
2
+ class OrderShipmentCarrier < Pwinty::Base
3
+ attribute? :name, Types::String.optional
4
+ attribute? :service, Types::String.optional
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ module Pwinty
2
+ class OrderShipmentFulfillmentLocation < Pwinty::Base
3
+ """https://www.prodigi.com/print-api/docs/reference/#order-object-fulfillment-location"""
4
+ attribute? :countryCode, Types::String.optional
5
+ attribute? :labCode, Types::String.optional
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ module Pwinty
2
+ class OrderShipmentItem < Pwinty::Base
3
+ """https://www.prodigi.com/print-api/docs/reference/#order-shipment-item"""
4
+ attribute? :id, Types::String.optional
5
+ end
6
+ end
@@ -0,0 +1,11 @@
1
+ require "pwinty/api_models/order_status_details"
2
+ require "pwinty/api_models/order_status_issue"
3
+
4
+ module Pwinty
5
+ class OrderStatus < Pwinty::Base
6
+ """https://www.prodigi.com/print-api/docs/reference/#status-status-object"""
7
+ attribute? :stage, Types::String.default('NotYetSubmitted')
8
+ attribute? :details, Pwinty::OrderStatusDetails
9
+ attribute? :issues, Types::Array.of(Pwinty::OrderStatusIssue)
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module Pwinty
2
+ class OrderStatusAuthDetails < Pwinty::Base
3
+ """https://www.prodigi.com/print-api/docs/reference/#status-status-authorisation-details"""
4
+ attribute? :authorisationUrl, Types::String.optional
5
+ attribute? :paymentDetails, Pwinty::OrderCost
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ module Pwinty
2
+ class OrderStatusDetails < Pwinty::Base
3
+ """https://www.prodigi.com/print-api/docs/reference/#status-status-object-details"""
4
+ attribute? :downloadAssets, Types::String.optional
5
+ attribute? :allocateProductionLocation, Types::String.optional
6
+ attribute? :printReadyAssetsPrepared, Types::String.optional
7
+ attribute? :inProduction, Types::String.optional
8
+ attribute? :shipping, Types::String.optional
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ require "pwinty/api_models/order_status_auth_details"
2
+
3
+ module Pwinty
4
+ class OrderStatusIssue < Pwinty::Base
5
+ """https://www.prodigi.com/print-api/docs/reference/#status-status-object-issues"""
6
+ attribute? :objectId, Types::String.optional
7
+ attribute? :errorCode, Types::String.optional
8
+ attribute? :description, Types::String.optional
9
+ attribute? :authorisationDetails, Pwinty::OrderStatusAuthDetails.optional
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ module Pwinty
2
+ class OrderTracking < Pwinty::Base
3
+ attribute? :number, Types::String.optional
4
+ attribute? :url, Types::String.optional
5
+ end
6
+ end
@@ -0,0 +1,19 @@
1
+ require "pwinty/api_models/product_dimensions"
2
+ require "pwinty/api_models/product_variant"
3
+
4
+ module Pwinty
5
+ class Product < Pwinty::Base
6
+ """https://www.prodigi.com/print-api/docs/reference/#product-details"""
7
+ attribute :sku, Types::String
8
+ attribute :description, Types::String
9
+ attribute :productDimensions, Pwinty::ProductDimensions
10
+ attribute :attributes, Types::Hash
11
+ attribute :printAreas, Types::Hash
12
+ attribute :variants, Types::Array.of(Pwinty::ProductVariant)
13
+
14
+ def self.find(sku)
15
+ response = Pwinty.conn.get("products/#{sku}")
16
+ new(response.body['product'])
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ module Pwinty
2
+ class ProductDimensions < Pwinty::Base
3
+ """https://www.prodigi.com/print-api/docs/reference/#product-details-object"""
4
+ attribute :width, Types::Float
5
+ attribute :height, Types::Float
6
+ attribute :units, Types::String
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Pwinty
2
+ class ProductVariant < Pwinty::Base
3
+ """https://www.prodigi.com/print-api/docs/reference/#product-details-object-variant"""
4
+ attribute :attributes, Types::Hash
5
+ attribute :shipsTo, Types::Array.of(Types::String)
6
+ attribute :printAreaSizes, Types::Hash
7
+ end
8
+ end
data/lib/pwinty/base.rb CHANGED
@@ -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,13 +1,15 @@
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 400; raise Pwinty::ValidationError, msg
7
+ when 401; raise Pwinty::AuthenticationError, msg
8
+ when 404; raise Pwinty::NotFound, msg
9
+ when 405; raise Pwinty::MethodNotAllowed, msg
10
+ when 415; raise Pwinty::InvalidContentTypeHeader, msg
11
+ when 500; raise Pwinty::Error, msg
12
+ end
13
+ end
14
+ end
13
15
  end
@@ -1,3 +1,3 @@
1
1
  module Pwinty
2
- VERSION = "3.0.5"
2
+ VERSION = "4.0.0"
3
3
  end
data/lib/pwinty.rb CHANGED
@@ -2,61 +2,60 @@ require 'faraday'
2
2
  require 'faraday_middleware'
3
3
 
4
4
  require "pwinty/base"
5
- require "pwinty/country"
6
5
  require "pwinty/http_errors"
7
- require "pwinty/image"
8
- require "pwinty/order"
9
- require "pwinty/order_status"
10
- require 'pwinty/photo_status'
11
- require "pwinty/shipment"
12
- require "pwinty/shipping_info"
13
6
  require "pwinty/version"
14
7
 
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
33
- end
34
-
35
- def self.url
36
- "#{Pwinty::BASE_URL}/#{Pwinty::API_VERSION}/"
37
- end
8
+ require "pwinty/api_models/order"
9
+ require 'pwinty/api_models/product'
38
10
 
39
- def self.headers
40
- {
41
- 'X-Pwinty-MerchantId' => Pwinty::MERCHANT_ID,
42
- 'X-Pwinty-REST-API-Key' => Pwinty::API_KEY,
43
- }
11
+ module Pwinty
12
+ class Error < StandardError; end
13
+ class OrderActionUnavailable < Pwinty::Error; end
14
+ class AuthenticationError < Pwinty::Error; end
15
+ class InvalidContentTypeHeader < Pwinty::Error; end
16
+ class MethodNotAllowed < Pwinty::Error; end
17
+ class OrderNotFound < Pwinty::Error; end
18
+ class StateIsInvalid < Pwinty::Error; end
19
+ class ValidationError < 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://api.sandbox.prodigi.com'
24
+ API_VERSION = 'v4.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
44
32
  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-API-Key' => Pwinty::API_KEY,
42
+ }
43
+ end
44
+
45
+ def self.conn
46
+ Faraday.new(url: url, headers: headers) do |config|
47
+ config.request :json
48
+ config.response :json
49
+ config.use Pwinty::HttpErrors
50
+ config.adapter Faraday.default_adapter
53
51
  end
52
+ end
54
53
 
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
54
+ def self.collate_results(response_data, targetted_class)
55
+ collection = []
56
+ response_data.each do |individual_attr|
57
+ collection << targetted_class.new(individual_attr)
61
58
  end
59
+ collection
60
+ end
62
61
  end
data/pwinty.gemspec CHANGED
@@ -9,14 +9,14 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Thomas Harvey"]
10
10
  spec.email = ["tom@alush.co.uk"]
11
11
 
12
- spec.summary = %q{Order photo prints through Pwinty}
13
- spec.description = "This wraps the Pwinty API at version 3 and aims to make your ruby life easier when interacting with the API."
12
+ spec.summary = %q{Order photo prints through the Prodigi Pwinty API}
13
+ spec.description = "This wraps the Pwinty API at version 4 and aims to make your ruby life easier when interacting with the API."
14
14
  spec.homepage = "https://github.com/tomharvey/pwinty3-rb"
15
15
  spec.license = "MIT"
16
16
 
17
17
  spec.metadata["homepage_uri"] = spec.homepage
18
18
  spec.metadata["source_code_uri"] = spec.homepage
19
- spec.metadata["documentation_uri"] = "https://pwinty.com/api/"
19
+ spec.metadata["documentation_uri"] = "https://www.prodigi.com/print-api/docs/"
20
20
 
21
21
  # Specify which files should be added to the gem when it is released.
22
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -27,18 +27,18 @@ 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", "~> 1.17"
31
- spec.add_development_dependency "rake", "~> 13.0"
32
- spec.add_development_dependency "rspec", "~> 3.0"
30
+ spec.add_development_dependency "bundler"
31
+ spec.add_development_dependency "rake"
32
+ spec.add_development_dependency "rspec"
33
33
 
34
- spec.add_development_dependency "vcr", "~> 5.0"
35
- spec.add_development_dependency "webmock", "~> 3.6"
36
- spec.add_development_dependency "simplecov", "~> 0.17"
34
+ spec.add_development_dependency "vcr", "~> 6.0"
35
+ spec.add_development_dependency "webmock", "~> 3.14"
36
+ spec.add_development_dependency "simplecov", "~> 0.21"
37
37
  spec.add_development_dependency "dotenv", "~> 2.7.5"
38
38
 
39
39
  spec.add_dependency "dry-struct", "~> 1.0"
40
- spec.add_dependency "dry-struct-setters", "~> 0.2"
41
- spec.add_dependency "faraday", "~> 0.15"
42
- spec.add_dependency "faraday_middleware", "~> 0.13"
43
- spec.add_dependency "json", "~> 2.2"
40
+ spec.add_dependency "dry-struct-setters", "~> 0.4"
41
+ spec.add_dependency "faraday", "~> 1.0"
42
+ spec.add_dependency "faraday_middleware", "~> 1.2"
43
+ spec.add_dependency "json", "~> 2.6"
44
44
  end