futureshop 0.1.0 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +1 -1
- data/CHANGELOG.md +17 -0
- data/exe/futureshop +1 -76
- data/lib/futureshop/client.rb +13 -8
- data/lib/futureshop/version.rb +1 -1
- data/lib/futureshop.rb +99 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98c8d7b64e6c87c143bf69d49a3ca20c480b7bf07086fdf8c5fa45f1ede4b33a
|
4
|
+
data.tar.gz: b18b15af5c1790f11137305848888744bb88c3248b2aa9e2bc432584ba4e493f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40b81c3cd65ef881c8a14d8eb3120351c184e4971d893acb76dde46defb187a85527ffc85c4b01552751c8b1b640dbc6c8c3951877203645a1890ccd9124e7ec
|
7
|
+
data.tar.gz: fbedd017cec85d9fbb717d556a7727d47672a0c91611a14f62b93452e4bcb2a3ea0fb9c5a26c7cf56366740fc85b8e9cfc530811d9dfcad3f43189dcaa55010b
|
data/.gitlab-ci.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.1.4] - 2021-10-11
|
4
|
+
|
5
|
+
- Handle order's couponList field, which was introduced on 2021-09-29
|
6
|
+
|
7
|
+
## [0.1.3] - 2021-08-25
|
8
|
+
|
9
|
+
- Fix option passing
|
10
|
+
- Fix handling of nextUrl
|
11
|
+
|
12
|
+
## [0.1.2] - 2021-08-06
|
13
|
+
|
14
|
+
- Fix command-line option name
|
15
|
+
|
16
|
+
## [0.1.1] - 2021-08-05
|
17
|
+
|
18
|
+
- Fix CSV conversion for optionPriceList and optionList
|
19
|
+
|
3
20
|
## [0.1.0] - 2021-07-04
|
4
21
|
|
5
22
|
- Initial release
|
data/exe/futureshop
CHANGED
@@ -40,82 +40,7 @@ def orders(global_options, argv)
|
|
40
40
|
opt.on "--order-date-start=DATE", Time
|
41
41
|
opt.on "--order-date-end=DATE", Time
|
42
42
|
})
|
43
|
-
|
44
|
-
|
45
|
-
client.each_order(order_date_start: options[:"order-date-start"], order_date_end: options[:"order-date-end"]).with_index do |row, index|
|
46
|
-
sleep 1 # FIXME: Delegate to client
|
47
|
-
order = client.order(row["orderNo"])
|
48
|
-
case options[:format]
|
49
|
-
when "json"
|
50
|
-
puts order.to_json
|
51
|
-
when "csv"
|
52
|
-
headers = []
|
53
|
-
CSV $stdout do |csv|
|
54
|
-
if index == 0
|
55
|
-
csv << aggregate_headers(order)
|
56
|
-
end
|
57
|
-
raise "Multiple shipmentList. orderNo: #{order["orderNo"]}" if order["shipmentList"].length > 1
|
58
|
-
order["shipmentList"].each do |shipment|
|
59
|
-
shipment["productList"].each do |product|
|
60
|
-
csv << order.each_value.with_object([]) {|value, values|
|
61
|
-
case value
|
62
|
-
when Hash
|
63
|
-
value.each_value do |v|
|
64
|
-
values << v
|
65
|
-
end
|
66
|
-
when Array
|
67
|
-
# only shipmentList is an Array and its length is 0
|
68
|
-
shipment.each_value do |v|
|
69
|
-
case v
|
70
|
-
when Hash
|
71
|
-
v.each_value do |ov|
|
72
|
-
values << ov
|
73
|
-
end
|
74
|
-
when Array
|
75
|
-
product.each_value do |v|
|
76
|
-
v = v.join("/") if v.kind_of? Array
|
77
|
-
values << v
|
78
|
-
end
|
79
|
-
else
|
80
|
-
values << v
|
81
|
-
end
|
82
|
-
end
|
83
|
-
else
|
84
|
-
values << value
|
85
|
-
end
|
86
|
-
}
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def client
|
95
|
-
Futureshop::Client.new(
|
96
|
-
shop_key: ENV["FUTURESHOP_SHOP_KEY"],
|
97
|
-
client_id: ENV["FUTURESHOP_CLIENT_ID"],
|
98
|
-
client_secret: ENV["FUTURESHOP_CLIENT_SECRET"],
|
99
|
-
api_domain: ENV["FUTURESHOP_API_DOMAIN"]
|
100
|
-
)
|
101
|
-
end
|
102
|
-
|
103
|
-
def aggregate_headers(obj, headers = [])
|
104
|
-
obj.each_pair do |key, value|
|
105
|
-
unless %w[buyerInfo addressInfo shippingInfo shipmentList productList].include? key
|
106
|
-
headers << key
|
107
|
-
end
|
108
|
-
case value
|
109
|
-
when Hash
|
110
|
-
headers.concat aggregate_headers(value).collect {|header| "#{key}.#{header}"}
|
111
|
-
when Array
|
112
|
-
sample = value[0]
|
113
|
-
if sample
|
114
|
-
headers.concat aggregate_headers(sample).collect {|header| "#{key}.#{header}"}
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
headers
|
43
|
+
Futureshop.orders(order_date_start: options[:"order-date-start"], order_date_end: options[:"order-date-end"], format: options[:format])
|
119
44
|
end
|
120
45
|
|
121
46
|
main ARGV
|
data/lib/futureshop/client.rb
CHANGED
@@ -42,10 +42,7 @@ module Futureshop
|
|
42
42
|
}
|
43
43
|
end
|
44
44
|
|
45
|
-
def
|
46
|
-
raise "Unsupported method: #{method}" unless [:get, :post].include?(method)
|
47
|
-
query = params.empty? ? nil : build_query(params)
|
48
|
-
uri = URI::HTTPS.build(host: @api_domain, port: @port, path: path, query: query)
|
45
|
+
def request_by_uri(method, uri, data: {})
|
49
46
|
request = Net::HTTP.const_get(method.capitalize).new(uri)
|
50
47
|
headers.each_pair do |field, value|
|
51
48
|
request[field] = value
|
@@ -56,6 +53,13 @@ module Futureshop
|
|
56
53
|
JSON.parse(response.body)
|
57
54
|
end
|
58
55
|
|
56
|
+
def request(method, path = "/", params: {}, data: {})
|
57
|
+
raise "Unsupported method: #{method}" unless [:get, :post].include?(method)
|
58
|
+
query = params.empty? ? nil : build_query(params)
|
59
|
+
uri = URI::HTTPS.build(host: @api_domain, port: @port, path: path, query: query)
|
60
|
+
request_by_uri(method, uri, data: data)
|
61
|
+
end
|
62
|
+
|
59
63
|
def get(path = "/", params: {})
|
60
64
|
request(:get, path, params: params)
|
61
65
|
end
|
@@ -78,12 +82,13 @@ module Futureshop
|
|
78
82
|
res = get("/admin-api/v1/shipping", params: params)
|
79
83
|
yield res["orderList"]
|
80
84
|
|
81
|
-
|
82
|
-
while
|
85
|
+
next_url = res["nextUrl"]
|
86
|
+
while next_url
|
83
87
|
sleep INTERVAL
|
84
|
-
|
88
|
+
url = URI.parse(next_url)
|
89
|
+
res = request_by_uri(:get, url)
|
85
90
|
yield res["orderList"]
|
86
|
-
|
91
|
+
next_url = res["nextUrl"]
|
87
92
|
end
|
88
93
|
end
|
89
94
|
|
data/lib/futureshop/version.rb
CHANGED
data/lib/futureshop.rb
CHANGED
@@ -3,5 +3,103 @@ require_relative "futureshop/client"
|
|
3
3
|
|
4
4
|
module Futureshop
|
5
5
|
class Error < StandardError; end
|
6
|
-
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_writer :client
|
9
|
+
|
10
|
+
def orders(format: "json", **options)
|
11
|
+
require "csv" if format == "csv"
|
12
|
+
|
13
|
+
client.each_order(**options).with_index do |row, index|
|
14
|
+
sleep 1 unless ENV["NO_THROTTLE"] # FIXME: Delegate to client
|
15
|
+
order = client.order(row["orderNo"])
|
16
|
+
case format
|
17
|
+
when "json"
|
18
|
+
puts order.to_json
|
19
|
+
when "csv"
|
20
|
+
headers = []
|
21
|
+
CSV $stdout do |csv|
|
22
|
+
if index == 0
|
23
|
+
csv << aggregate_headers(order)
|
24
|
+
end
|
25
|
+
raise "Multiple shipmentList. orderNo: #{order["orderNo"]}" if order["shipmentList"].length > 1
|
26
|
+
order["shipmentList"].each do |shipment|
|
27
|
+
shipment["productList"].each do |product|
|
28
|
+
csv << order.each_pair.with_object([]) {|(key, value), values|
|
29
|
+
case value
|
30
|
+
when Hash
|
31
|
+
value.each_value do |v|
|
32
|
+
values << v
|
33
|
+
end
|
34
|
+
when Array
|
35
|
+
case key
|
36
|
+
when "shipmentList"
|
37
|
+
# shipmentList's length is 1
|
38
|
+
shipment.each_value do |v|
|
39
|
+
case v
|
40
|
+
when Hash
|
41
|
+
v.each_value do |ov|
|
42
|
+
values << ov
|
43
|
+
end
|
44
|
+
when Array
|
45
|
+
product.each_pair do |k, v|
|
46
|
+
case k
|
47
|
+
when "optionPriceList"
|
48
|
+
v = v.collect {|optionPrice| "#{optionPrice['name']}:#{optionPrice['selectionName']}(#{optionPrice['price']})"}.join("/")
|
49
|
+
when "optionList"
|
50
|
+
v = v.collect {|option| [option["name"], option["selectionItem"]].join(":")}.join(",")
|
51
|
+
end
|
52
|
+
values << v
|
53
|
+
end
|
54
|
+
else
|
55
|
+
values << v
|
56
|
+
end
|
57
|
+
end
|
58
|
+
when "couponList"
|
59
|
+
values << value.collect {|coupon| [coupon["id"], coupon["name"]].join(":")}.join("/")
|
60
|
+
else
|
61
|
+
raise "Unknown array field: #{key}"
|
62
|
+
end
|
63
|
+
else
|
64
|
+
values << value
|
65
|
+
end
|
66
|
+
}
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
else
|
71
|
+
raise RuntimeError("unsupported format: #{format}")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def client
|
77
|
+
@client ||= Futureshop::Client.new(
|
78
|
+
shop_key: ENV["FUTURESHOP_SHOP_KEY"],
|
79
|
+
client_id: ENV["FUTURESHOP_CLIENT_ID"],
|
80
|
+
client_secret: ENV["FUTURESHOP_CLIENT_SECRET"],
|
81
|
+
api_domain: ENV["FUTURESHOP_API_DOMAIN"]
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def aggregate_headers(obj, headers = [])
|
88
|
+
obj.each_pair do |key, value|
|
89
|
+
unless %w[buyerInfo addressInfo shippingInfo shipmentList productList].include? key
|
90
|
+
headers << key
|
91
|
+
end
|
92
|
+
case value
|
93
|
+
when Hash
|
94
|
+
headers.concat aggregate_headers(value).collect {|header| "#{key}.#{header}"}
|
95
|
+
when Array
|
96
|
+
sample = value[0]
|
97
|
+
if sample
|
98
|
+
headers.concat aggregate_headers(sample).collect {|header| "#{key}.#{header}"}
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
headers
|
103
|
+
end
|
104
|
+
end
|
7
105
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: futureshop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kitaiti Makoto
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|