pwinty 3.0.6 → 4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.devcontainer/Dockerfile +17 -0
- data/.devcontainer/base.Dockerfile +43 -0
- data/.devcontainer/devcontainer.json +37 -0
- data/.travis.yml +1 -1
- data/Gemfile.lock +82 -63
- data/README.md +50 -99
- data/lib/pwinty/api_models/order.rb +114 -0
- data/lib/pwinty/api_models/order_asset.rb +7 -0
- data/lib/pwinty/api_models/order_charge.rb +5 -0
- data/lib/pwinty/api_models/order_cost.rb +7 -0
- data/lib/pwinty/api_models/order_item.rb +24 -0
- data/lib/pwinty/api_models/order_packing_slip.rb +7 -0
- data/lib/pwinty/api_models/order_recipient.rb +17 -0
- data/lib/pwinty/api_models/order_recipient_address.rb +11 -0
- data/lib/pwinty/api_models/order_shipment.rb +16 -0
- data/lib/pwinty/api_models/order_shipment_carrier.rb +6 -0
- data/lib/pwinty/api_models/order_shipment_fulfillment_location.rb +7 -0
- data/lib/pwinty/api_models/order_shipment_item.rb +6 -0
- data/lib/pwinty/api_models/order_status.rb +11 -0
- data/lib/pwinty/api_models/order_status_auth_details.rb +7 -0
- data/lib/pwinty/api_models/order_status_details.rb +10 -0
- data/lib/pwinty/api_models/order_status_issue.rb +11 -0
- data/lib/pwinty/api_models/order_tracking.rb +6 -0
- data/lib/pwinty/api_models/product.rb +19 -0
- data/lib/pwinty/api_models/product_dimensions.rb +8 -0
- data/lib/pwinty/api_models/product_variant.rb +8 -0
- data/lib/pwinty/http_errors.rb +6 -4
- data/lib/pwinty/version.rb +1 -1
- data/lib/pwinty.rb +11 -12
- data/pwinty.gemspec +13 -13
- metadata +55 -40
- data/lib/pwinty/country.rb +0 -12
- data/lib/pwinty/image.rb +0 -24
- data/lib/pwinty/order.rb +0 -134
- data/lib/pwinty/order_status.rb +0 -17
- data/lib/pwinty/photo_status.rb +0 -8
- data/lib/pwinty/shipment.rb +0 -14
- data/lib/pwinty/shipping_info.rb +0 -9
data/lib/pwinty/order.rb
DELETED
@@ -1,134 +0,0 @@
|
|
1
|
-
require 'dry/struct/with_setters'
|
2
|
-
|
3
|
-
require "pwinty/shipping_info"
|
4
|
-
|
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
|
-
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
|
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
|
-
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
|
134
|
-
end
|
data/lib/pwinty/order_status.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'pwinty/photo_status'
|
2
|
-
|
3
|
-
module Pwinty
|
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
|
-
|
11
|
-
|
12
|
-
def self.check(id)
|
13
|
-
response = Pwinty.conn.get("orders/#{id}/SubmissionStatus")
|
14
|
-
new(response.body['data'])
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
data/lib/pwinty/photo_status.rb
DELETED
data/lib/pwinty/shipment.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
module Pwinty
|
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
|
14
|
-
end
|