item_builder_mwh 0.1.14 → 0.1.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/item_builder_mwh.rb +24 -4
- data/lib/item_builder_mwh/get_quantity_service.rb +1 -1
- data/lib/item_builder_mwh/modes.rb +4 -2
- data/lib/item_builder_mwh/modes/quantity/base.rb +3 -3
- data/lib/item_builder_mwh/modes/quantity/lazada_service.rb +1 -1
- data/lib/item_builder_mwh/modes/quantity/zalora_service.rb +1 -1
- data/lib/item_builder_mwh/modes/quantity/zilingo_service.rb +1 -1
- data/lib/item_builder_mwh/modes/quantity_service.rb +9 -3
- data/lib/item_builder_mwh/modes/simple_service.rb +13 -3
- data/lib/item_builder_mwh/version.rb +1 -1
- data/lib/item_builder_mwh/zalora_quantity_service.rb +73 -0
- 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: '08f98253d8c700cbb5849d299ce485fc07ec96d5de0df1077e711dff490055b9'
|
4
|
+
data.tar.gz: 56f60c4b7f0f5356fb22b58eab61b63bed29e603d5ad44155d55cc6b231d077a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1937a3e7a8853bd0a13d554951ba4f32ff8579237ffe05e0c0510a6cbb689bcdae5bd0ff8320ac9d0b9754d043a4b35ca4670accf1e0928289921658e79605f1
|
7
|
+
data.tar.gz: fafb92c7b40c166bd96265618935e1e8aba6aa47977ee13b0727b29326a5c29044ec286d9f64d9ba5cfbb2e7624b246144f8cbe83bb080cf47b55d1a818053d7
|
data/lib/item_builder_mwh.rb
CHANGED
@@ -8,6 +8,7 @@ require 'item_builder_mwh/modes/quantity_service'
|
|
8
8
|
require 'item_builder_mwh/modes/simple_service'
|
9
9
|
require 'item_models'
|
10
10
|
require 'item_builder_mwh/zilingo_quantity_service'
|
11
|
+
require 'item_builder_mwh/zalora_quantity_service'
|
11
12
|
|
12
13
|
class ItemBuilderMwh
|
13
14
|
attr_reader :listing_ids
|
@@ -37,7 +38,12 @@ class ItemBuilderMwh
|
|
37
38
|
listings.map do |listing|
|
38
39
|
if listing.channel_id == 18
|
39
40
|
new_param = qty_simple_params(listing)
|
40
|
-
.merge({
|
41
|
+
.merge({zilingo_quantity: zilingo_quantity})
|
42
|
+
|
43
|
+
modes[mode].new(new_param).perform
|
44
|
+
elsif listing.channel_id == 13
|
45
|
+
new_param = qty_simple_params(listing)
|
46
|
+
.merge({zalora_reserved_stock: zalora_reserved_stock})
|
41
47
|
|
42
48
|
modes[mode].new(new_param).perform
|
43
49
|
else
|
@@ -48,7 +54,15 @@ class ItemBuilderMwh
|
|
48
54
|
|
49
55
|
def default
|
50
56
|
listings.map do |listing|
|
51
|
-
|
57
|
+
if listing.channel_id == 2 && mode == :active
|
58
|
+
modes[mode].new(qty_simple_params(listing)).perform
|
59
|
+
elsif listing.channel_id == 18 && mode == :active
|
60
|
+
modes[mode].new(qty_simple_params(listing)
|
61
|
+
.merge(zilingo_quantity: zilingo_quantity)
|
62
|
+
).perform
|
63
|
+
else
|
64
|
+
modes[mode].new(listing: listing).perform
|
65
|
+
end
|
52
66
|
end
|
53
67
|
end
|
54
68
|
|
@@ -112,8 +126,14 @@ class ItemBuilderMwh
|
|
112
126
|
@skus ||= listings.map(&:local_id).uniq
|
113
127
|
end
|
114
128
|
|
115
|
-
def
|
116
|
-
@
|
129
|
+
def zilingo_quantity
|
130
|
+
@zilingo_quantity ||= ItemBuilderMwh::ZilingoQuantityService.new(
|
131
|
+
listings: listings, skus: skus
|
132
|
+
).perform
|
133
|
+
end
|
134
|
+
|
135
|
+
def zalora_reserved_stock
|
136
|
+
@zalora_reserved_stock ||= ItemBuilderMwh::ZaloraQuantityService.new(
|
117
137
|
listings: listings, skus: skus
|
118
138
|
).perform
|
119
139
|
end
|
@@ -16,7 +16,8 @@ class ItemBuilderMwh
|
|
16
16
|
attr_reader :existing_alloc_stocks
|
17
17
|
attr_reader :variant_listings
|
18
18
|
attr_reader :reserved_stocks
|
19
|
-
attr_reader :
|
19
|
+
attr_reader :zilingo_quantity
|
20
|
+
attr_reader :zalora_reserved_stock
|
20
21
|
def initialize(args)
|
21
22
|
@listing = args.fetch(:listing)
|
22
23
|
@wh_spaces = args.fetch(:wh_spaces, [])
|
@@ -27,7 +28,8 @@ class ItemBuilderMwh
|
|
27
28
|
@existing_alloc_stocks = args.fetch(:existing_alloc_stocks, [])
|
28
29
|
@variant_listings = args.fetch(:variant_listings, [])
|
29
30
|
@reserved_stocks = args.fetch(:reserved_stocks, [])
|
30
|
-
@
|
31
|
+
@zilingo_quantity = args.fetch(:zilingo_quantity, [])
|
32
|
+
@zalora_reserved_stock = args.fetch(:zalora_reserved_stock, [])
|
31
33
|
warehouse
|
32
34
|
end
|
33
35
|
|
@@ -6,14 +6,14 @@ class ItemBuilderMwh
|
|
6
6
|
class Base
|
7
7
|
attr_reader :listing
|
8
8
|
attr_reader :available_quantity
|
9
|
-
attr_reader :
|
9
|
+
attr_reader :local_qty
|
10
10
|
|
11
|
-
def initialize(listing, available_quantity,
|
11
|
+
def initialize(listing, available_quantity, local_qty)
|
12
12
|
raise 'listing is not set' if listing.nil?
|
13
13
|
|
14
14
|
@listing = listing
|
15
15
|
@available_quantity = available_quantity
|
16
|
-
@
|
16
|
+
@local_qty = local_qty
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -45,16 +45,22 @@ class ItemBuilderMwh
|
|
45
45
|
def qty_channel(qty)
|
46
46
|
class_name = "ItemBuilderMwh::Modes::Quantity::#{channel_name}Service"
|
47
47
|
qty_channel_service = class_name.constantize
|
48
|
-
qty_channel_service.new(listing, available_quantity(qty),
|
48
|
+
qty_channel_service.new(listing, available_quantity(qty), local_qty.to_i).perform
|
49
49
|
end
|
50
50
|
|
51
51
|
def channel_name
|
52
52
|
QUANTITY_CHANNEL[listing.channel_id].to_s
|
53
53
|
end
|
54
54
|
|
55
|
-
def
|
55
|
+
def local_qty
|
56
56
|
if channel_name == 'Zilingo'
|
57
|
-
|
57
|
+
return 0 if zilingo_quantity.blank?
|
58
|
+
|
59
|
+
zilingo_quantity[listing.local_id].to_i
|
60
|
+
elsif channel_name == 'Zalora'
|
61
|
+
return 0 if zalora_reserved_stock.blank?
|
62
|
+
|
63
|
+
zalora_reserved_stock[listing.local_id].to_i
|
58
64
|
else
|
59
65
|
reserved_stocks.find {|rs| rs['variant_id'] == listing.variant_id }['reserved_quantity']
|
60
66
|
end
|
@@ -88,11 +88,21 @@ class ItemBuilderMwh
|
|
88
88
|
def qty_channel(qty)
|
89
89
|
class_name = "ItemBuilderMwh::Modes::Quantity::#{quantity_name}Service"
|
90
90
|
qty_channel_service = class_name.constantize
|
91
|
-
qty_channel_service.new(listing, available_quantity(qty),
|
91
|
+
qty_channel_service.new(listing, available_quantity(qty), local_qty.to_i).perform
|
92
92
|
end
|
93
93
|
|
94
|
-
def
|
95
|
-
|
94
|
+
def local_qty
|
95
|
+
if channel_name == 'Zilingo'
|
96
|
+
return 0 if zilingo_quantity.blank?
|
97
|
+
|
98
|
+
zilingo_quantity[listing.local_id].to_i
|
99
|
+
elsif channel_name == 'Zalora'
|
100
|
+
return 0 if zalora_reserved_stock.blank?
|
101
|
+
|
102
|
+
zalora_reserved_stock[listing.local_id].to_i
|
103
|
+
else
|
104
|
+
reserved_stocks.find {|rs| rs['variant_id'] == listing.variant_id }['reserved_quantity']
|
105
|
+
end
|
96
106
|
end
|
97
107
|
|
98
108
|
def available_quantity(qty)
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'item_builder_mwh/modes.rb'
|
4
|
+
class ItemBuilderMwh
|
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
|
+
elsif resp.dig('ErrorResponse', 'Head', 'ErrorMessage') == 'E009: Access Denied'
|
49
|
+
return nil
|
50
|
+
end
|
51
|
+
success_handle(resp)
|
52
|
+
end
|
53
|
+
|
54
|
+
def success_handle(resp)
|
55
|
+
hash = Hash.new
|
56
|
+
resp.dig("SuccessResponse", "Body", "ProductStocks", "ProductStock").each do |sku|
|
57
|
+
hash[sku['SellerSku']] = sku['ReservedStock']
|
58
|
+
end
|
59
|
+
hash
|
60
|
+
end
|
61
|
+
|
62
|
+
def rest_client(params, rescued_codes = 200)
|
63
|
+
RestClient::Request.execute(params.merge(timeout: 3)) do |response|
|
64
|
+
code = response.code
|
65
|
+
unless Array.wrap(rescued_codes).include?(code)
|
66
|
+
raise "Response Code is #{code}"
|
67
|
+
end
|
68
|
+
|
69
|
+
response
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: item_builder_mwh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Ivander
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-14 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_mwh/modes/simple/zalora_service.rb
|
145
145
|
- lib/item_builder_mwh/modes/simple_service.rb
|
146
146
|
- lib/item_builder_mwh/version.rb
|
147
|
+
- lib/item_builder_mwh/zalora_quantity_service.rb
|
147
148
|
- lib/item_builder_mwh/zilingo_quantity_service.rb
|
148
149
|
homepage:
|
149
150
|
licenses: []
|