futureshop 0.1.1 → 0.1.5
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 +4 -4
- data/.gitlab-ci.yml +1 -1
- data/CHANGELOG.md +18 -0
- data/README.md +1 -0
- data/exe/futureshop +25 -24
- data/lib/futureshop/client.rb +13 -8
- data/lib/futureshop/inventory.rb +51 -0
- data/lib/futureshop/version.rb +1 -1
- data/lib/futureshop.rb +26 -17
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de1dda6ccfb095050e2c4555103dcf79fbc9bb816230671a43d03ebd2ab8ce7b
|
4
|
+
data.tar.gz: 8f9c5ce46b616c378f131a769709256d3e02753179966495f1b6da797da7cdf8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c16675ddac87f365e25bd71661900a81731b1b390112e58c98e0d31cb7a0afcd7f824bb98b5cc92bed40c109a36a735d464f5c2acc6ddd78e378ed09afd2e692
|
7
|
+
data.tar.gz: 93b8ae4040cfa6f496871a4aa84c815a94da50f24a99a4b44f974efa06bcf1b7f0289256ac7b282841e23e380ec5732c174b49a2c99ed778f6535b43d81ecac9
|
data/.gitlab-ci.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.1.5] - 2021-10-21
|
4
|
+
|
5
|
+
- Add `Futureshop::Inventory` class
|
6
|
+
- Add `inventories` subcommand
|
7
|
+
|
8
|
+
## [0.1.4] - 2021-10-11
|
9
|
+
|
10
|
+
- Handle order's couponList field, which was introduced on 2021-09-29
|
11
|
+
|
12
|
+
## [0.1.3] - 2021-08-25
|
13
|
+
|
14
|
+
- Fix option passing
|
15
|
+
- Fix handling of nextUrl
|
16
|
+
|
17
|
+
## [0.1.2] - 2021-08-06
|
18
|
+
|
19
|
+
- Fix command-line option name
|
20
|
+
|
3
21
|
## [0.1.1] - 2021-08-05
|
4
22
|
|
5
23
|
- Fix CSV conversion for optionPriceList and optionList
|
data/README.md
CHANGED
data/exe/futureshop
CHANGED
@@ -4,7 +4,7 @@ require "optparse"
|
|
4
4
|
require "optparse/time"
|
5
5
|
require "futureshop"
|
6
6
|
|
7
|
-
SUPPORTED_COMMANDS = %w[orders]
|
7
|
+
SUPPORTED_COMMANDS = %w[orders inventories]
|
8
8
|
|
9
9
|
def main(argv)
|
10
10
|
global_options = parse_global_options(argv)
|
@@ -14,6 +14,8 @@ def main(argv)
|
|
14
14
|
case subcommand
|
15
15
|
when "orders"
|
16
16
|
orders global_options, argv
|
17
|
+
when "inventories"
|
18
|
+
inventories global_options, argv
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
@@ -40,34 +42,33 @@ def orders(global_options, argv)
|
|
40
42
|
opt.on "--order-date-start=DATE", Time
|
41
43
|
opt.on "--order-date-end=DATE", Time
|
42
44
|
})
|
43
|
-
Futureshop.orders(
|
45
|
+
Futureshop.orders(order_date_start: options[:"order-date-start"], order_date_end: options[:"order-date-end"], format: options[:format])
|
44
46
|
end
|
45
47
|
|
46
|
-
def
|
47
|
-
|
48
|
-
shop_key: ENV["FUTURESHOP_SHOP_KEY"],
|
49
|
-
client_id: ENV["FUTURESHOP_CLIENT_ID"],
|
50
|
-
client_secret: ENV["FUTURESHOP_CLIENT_SECRET"],
|
51
|
-
api_domain: ENV["FUTURESHOP_API_DOMAIN"]
|
52
|
-
)
|
53
|
-
end
|
48
|
+
def inventories(global_options, argv)
|
49
|
+
require "futureshop/inventory"
|
54
50
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
51
|
+
options = {
|
52
|
+
type: ["regular"],
|
53
|
+
product_no: [],
|
54
|
+
jan_code: []
|
55
|
+
}
|
56
|
+
options = options.update(parse_options(argv) {|opt|
|
57
|
+
opt.on "--type=TYPE", Array
|
58
|
+
opt.on "--create-date-start=DATE", Time
|
59
|
+
opt.on "--create-date-end=DATE", Time
|
60
|
+
opt.on "--product-no=NUMBER", Array
|
61
|
+
opt.on "--jan-code=CODE", Array
|
62
|
+
})
|
63
|
+
if options[:type]
|
64
|
+
unknown_types = options[:type].select {|type| ! %w[regular preorder planned realstore].include?(type)}
|
65
|
+
unless unknown_types.empty?
|
66
|
+
raise "Unknown type(s): #{unknown_types.join(', ')}"
|
68
67
|
end
|
69
68
|
end
|
70
|
-
|
69
|
+
Futureshop::Inventory.each types: options[:type].collect(&:to_sym), create_date_start: options[:"create-date-start"], create_date_end: options[:"create-date-end"], product_no: options[:"product-no"], jan_code: options[:"jan-code"] do |inventory|
|
70
|
+
puts inventory.to_json
|
71
|
+
end
|
71
72
|
end
|
72
73
|
|
73
74
|
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
|
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Futureshop
|
2
|
+
class Inventory
|
3
|
+
class << self
|
4
|
+
def each_batch(types: [:regular], create_date_start: nil, create_date_end: nil, product_no: [], jan_code: [])
|
5
|
+
params = {
|
6
|
+
types: types,
|
7
|
+
product_no: product_no,
|
8
|
+
jan_code: jan_code
|
9
|
+
}
|
10
|
+
params[:create_date_start] = create_date_start.strftime("%FT%T") if create_date_start
|
11
|
+
params[:create_date_end] = create_date_end.strftime("%FT%T") if create_date_end
|
12
|
+
res = client.get("/admin-api/v1/inventory", params: params)
|
13
|
+
yield res["productList"]
|
14
|
+
|
15
|
+
next_url = res["nextUrl"]
|
16
|
+
while next_url
|
17
|
+
sleep Client::INTERVAL
|
18
|
+
url = URI.parse(next_url)
|
19
|
+
res = client.request_by_uri(:get, url)
|
20
|
+
yield res["productList"]
|
21
|
+
next_url = res["nextUrl"]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def each(**args)
|
26
|
+
return enum_for(__method__, **args) unless block_given?
|
27
|
+
|
28
|
+
each_batch **args do |inventories|
|
29
|
+
inventories.each do |inventory|
|
30
|
+
yield inventory
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def all(**args)
|
36
|
+
return each.to_a
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def client
|
42
|
+
@client ||= Futureshop::Client.new(
|
43
|
+
shop_key: ENV["FUTURESHOP_SHOP_KEY"],
|
44
|
+
client_id: ENV["FUTURESHOP_CLIENT_ID"],
|
45
|
+
client_secret: ENV["FUTURESHOP_CLIENT_SECRET"],
|
46
|
+
api_domain: ENV["FUTURESHOP_API_DOMAIN"]
|
47
|
+
)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/futureshop/version.rb
CHANGED
data/lib/futureshop.rb
CHANGED
@@ -25,33 +25,40 @@ module Futureshop
|
|
25
25
|
raise "Multiple shipmentList. orderNo: #{order["orderNo"]}" if order["shipmentList"].length > 1
|
26
26
|
order["shipmentList"].each do |shipment|
|
27
27
|
shipment["productList"].each do |product|
|
28
|
-
csv << order.
|
28
|
+
csv << order.each_pair.with_object([]) {|(key, value), values|
|
29
29
|
case value
|
30
30
|
when Hash
|
31
31
|
value.each_value do |v|
|
32
32
|
values << v
|
33
33
|
end
|
34
34
|
when Array
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
v
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
49
53
|
end
|
54
|
+
else
|
50
55
|
values << v
|
51
56
|
end
|
52
|
-
else
|
53
|
-
values << v
|
54
57
|
end
|
58
|
+
when "couponList"
|
59
|
+
values << value.collect {|coupon| [coupon["id"], coupon["name"]].join(":")}.join("/")
|
60
|
+
else
|
61
|
+
raise "Unknown array field: #{key}"
|
55
62
|
end
|
56
63
|
else
|
57
64
|
values << value
|
@@ -60,6 +67,8 @@ module Futureshop
|
|
60
67
|
end
|
61
68
|
end
|
62
69
|
end
|
70
|
+
else
|
71
|
+
raise RuntimeError("unsupported format: #{format}")
|
63
72
|
end
|
64
73
|
end
|
65
74
|
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.5
|
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-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- futureshop.gemspec
|
74
74
|
- lib/futureshop.rb
|
75
75
|
- lib/futureshop/client.rb
|
76
|
+
- lib/futureshop/inventory.rb
|
76
77
|
- lib/futureshop/version.rb
|
77
78
|
homepage: https://gitlab.com/KitaitiMakoto/futuresohp
|
78
79
|
licenses:
|