futureshop 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fba3e1d77af05a3e3f36f22eb07fd0ee0c6126b13ce951c47c58515c890c705d
4
- data.tar.gz: 100d20afab4bb4199d3080ab13fd0fb6e39968257c5aa267cfaaf1f6321b0cbc
3
+ metadata.gz: e7656d0cc9f40144256020b14e6f45bf161851ec1b3487901662efb8c741f869
4
+ data.tar.gz: f3b18e8fd1bb8ad58c10c42216ff219123fde61e869827ed31876ecc1b9ebdfb
5
5
  SHA512:
6
- metadata.gz: 7903e9fde5a94044374daf982a57b7d834f4d8f9047619cf26d144e490ba834b1ebace0e5292731323ebb891adbaf2e9375fdaadf6158aa4d904f2a85cfb8407
7
- data.tar.gz: 2fed2130ba08408186997df4a6277123c2f6bc52c35eba17503a1076f18f4d6336777e83aa5876684b965378e34f4d107c34a995d702b9006645ce0f56d852ab
6
+ metadata.gz: 77627e2b9030c438e1b4891a1957129bbd9ab027fcebf97b85e041f52fd19602711a2a85f58555ea7e93cb7ff8d3016672db7a5dcf254fef92bcd6e1d45808ae
7
+ data.tar.gz: bf8ec9076b7ed937d41e0ee67823f47f2100008d209f51a47ff78eb76ae13a33f65d54169ead5f9e854a6eab54112be746645d731138a5b0eb68364d298b1f90
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.1] - 2021-08-05
4
+
5
+ - Fix CSV conversion for optionPriceList and optionList
6
+
3
7
  ## [0.1.0] - 2021-07-04
4
8
 
5
9
  - Initial release
data/exe/futureshop CHANGED
@@ -40,55 +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
- require "csv" if options[:format] == "csv"
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
43
+ Futureshop.orders(**options)
92
44
  end
93
45
 
94
46
  def client
data/lib/futureshop.rb CHANGED
@@ -3,5 +3,94 @@ require_relative "futureshop/client"
3
3
 
4
4
  module Futureshop
5
5
  class Error < StandardError; end
6
- # Your code goes here...
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_value.with_object([]) {|value, values|
29
+ case value
30
+ when Hash
31
+ value.each_value do |v|
32
+ values << v
33
+ end
34
+ when Array
35
+ # only shipmentList is an Array and its length is 0
36
+ shipment.each_value do |v|
37
+ case v
38
+ when Hash
39
+ v.each_value do |ov|
40
+ values << ov
41
+ end
42
+ when Array
43
+ product.each_pair do |k, v|
44
+ case k
45
+ when "optionPriceList"
46
+ v = v.collect {|optionPrice| "#{optionPrice['name']}:#{optionPrice['selectionName']}(#{optionPrice['price']})"}.join("/")
47
+ when "optionList"
48
+ v = v.collect {|option| [option["name"], option["selectionItem"]].join(":")}.join(",")
49
+ end
50
+ values << v
51
+ end
52
+ else
53
+ values << v
54
+ end
55
+ end
56
+ else
57
+ values << value
58
+ end
59
+ }
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ def client
68
+ @client ||= Futureshop::Client.new(
69
+ shop_key: ENV["FUTURESHOP_SHOP_KEY"],
70
+ client_id: ENV["FUTURESHOP_CLIENT_ID"],
71
+ client_secret: ENV["FUTURESHOP_CLIENT_SECRET"],
72
+ api_domain: ENV["FUTURESHOP_API_DOMAIN"]
73
+ )
74
+ end
75
+
76
+ private
77
+
78
+ def aggregate_headers(obj, headers = [])
79
+ obj.each_pair do |key, value|
80
+ unless %w[buyerInfo addressInfo shippingInfo shipmentList productList].include? key
81
+ headers << key
82
+ end
83
+ case value
84
+ when Hash
85
+ headers.concat aggregate_headers(value).collect {|header| "#{key}.#{header}"}
86
+ when Array
87
+ sample = value[0]
88
+ if sample
89
+ headers.concat aggregate_headers(sample).collect {|header| "#{key}.#{header}"}
90
+ end
91
+ end
92
+ end
93
+ headers
94
+ end
95
+ end
7
96
  end
@@ -1,3 +1,3 @@
1
1
  module Futureshop
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  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.0
4
+ version: 0.1.1
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-07-21 00:00:00.000000000 Z
11
+ date: 2021-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake