item_builder 0.1.30 → 0.1.35
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/lib/item_builder.rb +29 -6
- data/lib/item_builder/get_quantity_service.rb +1 -1
- data/lib/item_builder/modes.rb +3 -1
- data/lib/item_builder/modes/active_service.rb +18 -1
- data/lib/item_builder/modes/quantity/zilingo_service.rb +1 -1
- data/lib/item_builder/modes/quantity_service.rb +4 -2
- data/lib/item_builder/modes/simple_service.rb +2 -1
- data/lib/item_builder/version.rb +1 -1
- data/lib/item_builder/zalora_quantity_service.rb +68 -0
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 943f08798aa049f27fb26ea0770050ebee5c79e99938024ef0d5aaf154d084c9
|
|
4
|
+
data.tar.gz: 3318ecd4b4f81f91ab4c9c46e9919ffd55a34dadd3c8954864acbaa9573dd00c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: df2e735b1590b7ad053d8c436c6dfacf4ec1c6493e4d50118392f40c61cb2d5eaa095734ea7b9b21b663a40c10aa4ba21a33061975d8c046a134d3553d2d0f69
|
|
7
|
+
data.tar.gz: b93c28e2d41870f21d51cefa3a7c2afff1f52c3badb9fdbb4ffc709de8c930da12e9a0f96c4e4a0fcdcfb99b7a302482626465a9337fd971bbb96c8148dff70f
|
data/lib/item_builder.rb
CHANGED
|
@@ -6,8 +6,10 @@ require 'item_builder/modes/base_service'
|
|
|
6
6
|
require 'item_builder/modes/price_service'
|
|
7
7
|
require 'item_builder/modes/quantity_service'
|
|
8
8
|
require 'item_builder/modes/simple_service'
|
|
9
|
+
require 'item_builder/modes/active_service'
|
|
9
10
|
require 'item_models'
|
|
10
11
|
require 'item_builder/zilingo_quantity_service'
|
|
12
|
+
require 'item_builder/zalora_quantity_service'
|
|
11
13
|
|
|
12
14
|
class ItemBuilder
|
|
13
15
|
def self.build(listing_ids, mode)
|
|
@@ -27,7 +29,7 @@ class ItemBuilder
|
|
|
27
29
|
end
|
|
28
30
|
|
|
29
31
|
def mode_check
|
|
30
|
-
if mode == :quantity || mode == :simple
|
|
32
|
+
if mode == :quantity || mode == :simple
|
|
31
33
|
quantity_simple_mode
|
|
32
34
|
else
|
|
33
35
|
default
|
|
@@ -36,7 +38,19 @@ class ItemBuilder
|
|
|
36
38
|
|
|
37
39
|
def quantity_simple_mode
|
|
38
40
|
listings.map do |listing|
|
|
39
|
-
|
|
41
|
+
if listing.channel_id == 18
|
|
42
|
+
new_param = qty_simple_params(listing)
|
|
43
|
+
.merge({zilingo_delta_quantity: zilingo_delta_quantity})
|
|
44
|
+
|
|
45
|
+
modes[mode].new(new_param).perform
|
|
46
|
+
elsif listing.channel_id == 13
|
|
47
|
+
new_param = qty_simple_params(listing)
|
|
48
|
+
.merge({zalora_reserved_stock: zalora_reserved_stock})
|
|
49
|
+
|
|
50
|
+
modes[mode].new(new_param).perform
|
|
51
|
+
else
|
|
52
|
+
modes[mode].new(qty_simple_params(listing)).perform
|
|
53
|
+
end
|
|
40
54
|
end
|
|
41
55
|
end
|
|
42
56
|
|
|
@@ -46,14 +60,17 @@ class ItemBuilder
|
|
|
46
60
|
stock_allocs: stock_allocs, variant_listings: variant_listings,
|
|
47
61
|
bundles: bundles, item_bundle_variants: item_bundle_variants,
|
|
48
62
|
existing_alloc_stocks: existing_alloc_stocks,
|
|
49
|
-
reserved_stocks: reserved_stocks
|
|
50
|
-
zilingo_delta_quantity: zilingo_delta_quantity
|
|
63
|
+
reserved_stocks: reserved_stocks
|
|
51
64
|
}
|
|
52
65
|
end
|
|
53
66
|
|
|
54
67
|
def default
|
|
55
68
|
listings.map do |listing|
|
|
56
|
-
|
|
69
|
+
if listing.channel_id == 2 && mode == :active
|
|
70
|
+
modes[mode].new(qty_simple_params(listing)).perform
|
|
71
|
+
else
|
|
72
|
+
modes[mode].new(listing: listing).perform
|
|
73
|
+
end
|
|
57
74
|
end
|
|
58
75
|
end
|
|
59
76
|
|
|
@@ -117,6 +134,12 @@ class ItemBuilder
|
|
|
117
134
|
).perform
|
|
118
135
|
end
|
|
119
136
|
|
|
137
|
+
def zalora_reserved_stock
|
|
138
|
+
@zalora_reserved_stock ||= ItemBuilder::ZaloraQuantityService.new(
|
|
139
|
+
listings: listings, skus: skus
|
|
140
|
+
).perform
|
|
141
|
+
end
|
|
142
|
+
|
|
120
143
|
def modes
|
|
121
144
|
{
|
|
122
145
|
price: ItemBuilder::Modes::PriceService,
|
|
@@ -140,6 +163,6 @@ class ItemBuilder
|
|
|
140
163
|
def reserved_stocks
|
|
141
164
|
@reserved_stocks ||= JSON.parse(RestClient.get(
|
|
142
165
|
"#{order_host}?#{reserved_params}"
|
|
143
|
-
).body) if [3
|
|
166
|
+
).body) if [3].include?(listings[0].channel_id)
|
|
144
167
|
end
|
|
145
168
|
end
|
data/lib/item_builder/modes.rb
CHANGED
|
@@ -18,6 +18,7 @@ class ItemBuilder
|
|
|
18
18
|
attr_reader :variant_listings
|
|
19
19
|
attr_reader :reserved_stocks
|
|
20
20
|
attr_reader :zilingo_delta_quantity
|
|
21
|
+
attr_reader :zalora_reserved_stock
|
|
21
22
|
def initialize(args)
|
|
22
23
|
@listing = args.fetch(:listing)
|
|
23
24
|
@wh_spaces = args.fetch(:wh_spaces, [])
|
|
@@ -28,7 +29,8 @@ class ItemBuilder
|
|
|
28
29
|
@existing_alloc_stocks = args.fetch(:existing_alloc_stocks, [])
|
|
29
30
|
@variant_listings = args.fetch(:variant_listings, [])
|
|
30
31
|
@reserved_stocks = args.fetch(:reserved_stocks, [])
|
|
31
|
-
@zilingo_delta_quantity = args.fetch(:zilingo_delta_quantity)
|
|
32
|
+
@zilingo_delta_quantity = args.fetch(:zilingo_delta_quantity, [])
|
|
33
|
+
@zalora_reserved_stock = args.fetch(:zalora_reserved_stock, [])
|
|
32
34
|
end
|
|
33
35
|
|
|
34
36
|
def base
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'item_builder/modes/quantity_service.rb'
|
|
3
4
|
require 'item_builder/modes.rb'
|
|
4
5
|
class ItemBuilder
|
|
5
6
|
module Modes
|
|
@@ -7,7 +8,11 @@ class ItemBuilder
|
|
|
7
8
|
include Modes
|
|
8
9
|
|
|
9
10
|
def perform
|
|
10
|
-
|
|
11
|
+
if listing.channel_id == 2
|
|
12
|
+
to_h.merge(base).merge(quantity)
|
|
13
|
+
else
|
|
14
|
+
to_h.merge(base)
|
|
15
|
+
end
|
|
11
16
|
end
|
|
12
17
|
|
|
13
18
|
def to_h
|
|
@@ -17,6 +22,18 @@ class ItemBuilder
|
|
|
17
22
|
}
|
|
18
23
|
end
|
|
19
24
|
|
|
25
|
+
def quantity
|
|
26
|
+
QuantityService.new(
|
|
27
|
+
listing: listing, wh_spaces: wh_spaces, variants: variants,
|
|
28
|
+
stock_allocs: stock_allocs, variant_listings: variant_listings,
|
|
29
|
+
bundles: bundles, item_bundle_variants: item_bundle_variants,
|
|
30
|
+
existing_alloc_stocks: existing_alloc_stocks,
|
|
31
|
+
reserved_stocks: reserved_stocks,
|
|
32
|
+
zilingo_delta_quantity: zilingo_delta_quantity,
|
|
33
|
+
zalora_reserved_stock: zalora_reserved_stock
|
|
34
|
+
).to_h
|
|
35
|
+
end
|
|
36
|
+
|
|
20
37
|
def active_variant
|
|
21
38
|
VariantListing
|
|
22
39
|
.where(local_item_id: listing.local_item_id,
|
|
@@ -24,7 +24,7 @@ class ItemBuilder
|
|
|
24
24
|
|
|
25
25
|
def to_h
|
|
26
26
|
{
|
|
27
|
-
quantity: qty
|
|
27
|
+
quantity: [qty, 0].sort[1]
|
|
28
28
|
}
|
|
29
29
|
end
|
|
30
30
|
|
|
@@ -48,7 +48,9 @@ class ItemBuilder
|
|
|
48
48
|
|
|
49
49
|
def reserved_stock
|
|
50
50
|
if channel_name == 'Zilingo'
|
|
51
|
-
zilingo_delta_quantity[listing.local_id]
|
|
51
|
+
zilingo_delta_quantity[listing.local_id].to_i
|
|
52
|
+
elsif channel_name == 'Zalora'
|
|
53
|
+
zalora_reserved_stock[listing.local_id].to_i
|
|
52
54
|
else
|
|
53
55
|
reserved_stocks.find {|rs| rs['variant_id'] == listing.variant_id }['reserved_quantity']
|
|
54
56
|
end
|
|
@@ -22,7 +22,8 @@ class ItemBuilder
|
|
|
22
22
|
stock_allocs: stock_allocs, variant_listings: variant_listings,
|
|
23
23
|
bundles: bundles, item_bundle_variants: item_bundle_variants,
|
|
24
24
|
existing_alloc_stocks: existing_alloc_stocks,
|
|
25
|
-
reserved_stocks: reserved_stocks
|
|
25
|
+
reserved_stocks: reserved_stocks,
|
|
26
|
+
zilingo_delta_quantity: zilingo_delta_quantity
|
|
26
27
|
).to_h
|
|
27
28
|
end
|
|
28
29
|
|
data/lib/item_builder/version.rb
CHANGED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'item_builder/modes.rb'
|
|
4
|
+
class ItemBuilder
|
|
5
|
+
class ZaloraQuantityService
|
|
6
|
+
attr_reader :listings, :skus
|
|
7
|
+
def initialize(args)
|
|
8
|
+
@listings = args.fetch(:listings)
|
|
9
|
+
@skus = args.fetch(:skus)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def perform
|
|
13
|
+
args = {
|
|
14
|
+
method: :post, url: url, payload: data, headers: headers
|
|
15
|
+
}
|
|
16
|
+
resp = JSON.parse(rest_client(args, [200, 500, 406]))
|
|
17
|
+
response_process(resp)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def headers
|
|
21
|
+
{ content_type: :json, accept: :json }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def data
|
|
25
|
+
{
|
|
26
|
+
"credential": JSON.parse(credential)['credential'],
|
|
27
|
+
"data": { "skus": skus }
|
|
28
|
+
}.to_json
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def credential
|
|
32
|
+
return @credential if @credential
|
|
33
|
+
|
|
34
|
+
account_id = listings[0].profile_channel_association_id
|
|
35
|
+
host = ENV['CREDENTIAL_URL'] || raise('credential url is not set')
|
|
36
|
+
url = "#{host}/credential?account_id=#{account_id}"
|
|
37
|
+
@credential = rest_client(method: :get, url: url)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def url
|
|
41
|
+
url = ENV['API_GATEWAY_URL'] || raise('api gateway is not set')
|
|
42
|
+
url + "/zalora/product_stocks"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def response_process(resp)
|
|
46
|
+
if resp.dig("response_code") && resp.dig("response_code") != 200
|
|
47
|
+
raise "Response Code is #{resp.dig("response_code")}"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
hash = Hash.new
|
|
51
|
+
resp.dig("SuccessResponse", "Body", "ProductStocks", "ProductStock").each do |sku|
|
|
52
|
+
hash[sku['SellerSku']] = sku['ReservedStock']
|
|
53
|
+
end
|
|
54
|
+
hash
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def rest_client(params, rescued_codes = 200)
|
|
58
|
+
RestClient::Request.execute(params.merge(timeout: 3)) do |response|
|
|
59
|
+
code = response.code
|
|
60
|
+
unless Array.wrap(rescued_codes).include?(code)
|
|
61
|
+
raise "Response Code is #{code}"
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
response
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: item_builder
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.35
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- okaaryanata
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-
|
|
11
|
+
date: 2021-04-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -144,6 +144,7 @@ files:
|
|
|
144
144
|
- lib/item_builder/modes/update/zalora_service.rb
|
|
145
145
|
- lib/item_builder/modes/update_service.rb
|
|
146
146
|
- lib/item_builder/version.rb
|
|
147
|
+
- lib/item_builder/zalora_quantity_service.rb
|
|
147
148
|
- lib/item_builder/zilingo_quantity_service.rb
|
|
148
149
|
homepage:
|
|
149
150
|
licenses: []
|
|
@@ -163,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
163
164
|
- !ruby/object:Gem::Version
|
|
164
165
|
version: '0'
|
|
165
166
|
requirements: []
|
|
166
|
-
rubygems_version: 3.0.
|
|
167
|
+
rubygems_version: 3.0.9
|
|
167
168
|
signing_key:
|
|
168
169
|
specification_version: 4
|
|
169
170
|
summary: Item builder
|