item_builder 0.1.29 → 0.1.30
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 +14 -2
- data/lib/item_builder/modes.rb +2 -0
- data/lib/item_builder/modes/quantity/zilingo_service.rb +1 -58
- data/lib/item_builder/modes/quantity_service.rb +5 -1
- data/lib/item_builder/version.rb +1 -1
- data/lib/item_builder/zilingo_quantity_service.rb +64 -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: 4b05a2126b02a1494542d1dfa5c7889dde9df101efb6cc2d36a2b639483deaeb
|
4
|
+
data.tar.gz: c5a27afae1de6da5ee31ced96d1924df675d7b0ae38c8765e2f0b770d00a9c58
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79681dbd1b388370204afc5b517ec7ac1cf8943ca1ac3f798f7f4667fc215597f68b888bcc31a42b48b98e285b60c5ebb0ed1a3d3961221e84f4ca3b5f2c41d3
|
7
|
+
data.tar.gz: 36e3a579e47f0533dca84a9cf8482320d6bf4607af85aac3c360de8d50830fd061010323bd9a2686897790a87c927ad5f2b308e84397c812cd605816ee7f6991
|
data/lib/item_builder.rb
CHANGED
@@ -7,6 +7,7 @@ require 'item_builder/modes/price_service'
|
|
7
7
|
require 'item_builder/modes/quantity_service'
|
8
8
|
require 'item_builder/modes/simple_service'
|
9
9
|
require 'item_models'
|
10
|
+
require 'item_builder/zilingo_quantity_service'
|
10
11
|
|
11
12
|
class ItemBuilder
|
12
13
|
def self.build(listing_ids, mode)
|
@@ -45,7 +46,8 @@ class ItemBuilder
|
|
45
46
|
stock_allocs: stock_allocs, variant_listings: variant_listings,
|
46
47
|
bundles: bundles, item_bundle_variants: item_bundle_variants,
|
47
48
|
existing_alloc_stocks: existing_alloc_stocks,
|
48
|
-
reserved_stocks: reserved_stocks
|
49
|
+
reserved_stocks: reserved_stocks,
|
50
|
+
zilingo_delta_quantity: zilingo_delta_quantity
|
49
51
|
}
|
50
52
|
end
|
51
53
|
|
@@ -105,6 +107,16 @@ class ItemBuilder
|
|
105
107
|
@listings ||= VariantListing.where(id: listing_ids)
|
106
108
|
end
|
107
109
|
|
110
|
+
def skus
|
111
|
+
@skus ||= listings.map(&:local_id).uniq
|
112
|
+
end
|
113
|
+
|
114
|
+
def zilingo_delta_quantity
|
115
|
+
@zilingo_delta_quantity ||= ItemBuilder::ZilingoQuantityService.new(
|
116
|
+
listings: listings, skus: skus
|
117
|
+
).perform
|
118
|
+
end
|
119
|
+
|
108
120
|
def modes
|
109
121
|
{
|
110
122
|
price: ItemBuilder::Modes::PriceService,
|
@@ -128,6 +140,6 @@ class ItemBuilder
|
|
128
140
|
def reserved_stocks
|
129
141
|
@reserved_stocks ||= JSON.parse(RestClient.get(
|
130
142
|
"#{order_host}?#{reserved_params}"
|
131
|
-
).body) if [3,13
|
143
|
+
).body) if [3,13].include?(listings[0].channel_id)
|
132
144
|
end
|
133
145
|
end
|
data/lib/item_builder/modes.rb
CHANGED
@@ -17,6 +17,7 @@ class ItemBuilder
|
|
17
17
|
attr_reader :existing_alloc_stocks
|
18
18
|
attr_reader :variant_listings
|
19
19
|
attr_reader :reserved_stocks
|
20
|
+
attr_reader :zilingo_delta_quantity
|
20
21
|
def initialize(args)
|
21
22
|
@listing = args.fetch(:listing)
|
22
23
|
@wh_spaces = args.fetch(:wh_spaces, [])
|
@@ -27,6 +28,7 @@ class ItemBuilder
|
|
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, [])
|
31
|
+
@zilingo_delta_quantity = args.fetch(:zilingo_delta_quantity)
|
30
32
|
end
|
31
33
|
|
32
34
|
def base
|
@@ -6,64 +6,7 @@ class ItemBuilder
|
|
6
6
|
module Quantity
|
7
7
|
class ZilingoService < Base
|
8
8
|
def perform
|
9
|
-
available_quantity -
|
10
|
-
end
|
11
|
-
|
12
|
-
def local_quantity
|
13
|
-
quantities = sku_quantities(listing.local_item_id)
|
14
|
-
quantities[listing.local_id]
|
15
|
-
end
|
16
|
-
|
17
|
-
def headers
|
18
|
-
{ content_type: :json, accept: :json }
|
19
|
-
end
|
20
|
-
|
21
|
-
def data(item_id)
|
22
|
-
{
|
23
|
-
"credential": JSON.parse(credential)['credential'],
|
24
|
-
"data": { "item_id": item_id }
|
25
|
-
}.to_json
|
26
|
-
end
|
27
|
-
|
28
|
-
def credential
|
29
|
-
return @credential if @credential
|
30
|
-
|
31
|
-
account_id = listing.profile_channel_association_id
|
32
|
-
host = ENV['CREDENTIAL_URL'] || raise('credential url is not set')
|
33
|
-
url = "#{host}/credential?account_id=#{account_id}"
|
34
|
-
@credential = rest_client(method: :get, url: url)
|
35
|
-
end
|
36
|
-
|
37
|
-
def url
|
38
|
-
url = ENV['API_GATEWAY_URL'] || raise('api gateway is not set')
|
39
|
-
url + "/zilingo/item_quantities"
|
40
|
-
end
|
41
|
-
|
42
|
-
def sku_quantities(item_id)
|
43
|
-
args = {
|
44
|
-
method: :post, url: url, payload: data(item_id), headers: headers
|
45
|
-
}
|
46
|
-
resp = JSON.parse(rest_client(args, [200, 500, 406]))
|
47
|
-
response_process(resp)
|
48
|
-
end
|
49
|
-
|
50
|
-
def response_process(resp)
|
51
|
-
hash = Hash.new
|
52
|
-
resp['zilingoSKUQuantities'].each do |sku|
|
53
|
-
hash[sku['zilingoSKUId']] = sku['quantity'] + sku['frozenQuantity']
|
54
|
-
end
|
55
|
-
hash
|
56
|
-
end
|
57
|
-
|
58
|
-
def rest_client(params, rescued_codes = 200)
|
59
|
-
RestClient::Request.execute(params.merge(timeout: 3)) do |response|
|
60
|
-
code = response.code
|
61
|
-
unless Array.wrap(rescued_codes).include?(code)
|
62
|
-
raise "Response Code is #{code}"
|
63
|
-
end
|
64
|
-
|
65
|
-
response
|
66
|
-
end
|
9
|
+
available_quantity - reserved_stock.to_i
|
67
10
|
end
|
68
11
|
end
|
69
12
|
end
|
@@ -47,7 +47,11 @@ class ItemBuilder
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def reserved_stock
|
50
|
-
|
50
|
+
if channel_name == 'Zilingo'
|
51
|
+
zilingo_delta_quantity[listing.local_id]
|
52
|
+
else
|
53
|
+
reserved_stocks.find {|rs| rs['variant_id'] == listing.variant_id }['reserved_quantity']
|
54
|
+
end
|
51
55
|
end
|
52
56
|
|
53
57
|
def available_quantity
|
data/lib/item_builder/version.rb
CHANGED
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'item_builder/modes.rb'
|
4
|
+
class ItemBuilder
|
5
|
+
class ZilingoQuantityService
|
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 + "/zilingo/item_quantity_by_sku"
|
43
|
+
end
|
44
|
+
|
45
|
+
def response_process(resp)
|
46
|
+
hash = Hash.new
|
47
|
+
resp['zilingoSKUQuantities'].each do |sku|
|
48
|
+
hash[sku['zilingoSKUId']] = sku['quantity'] + sku['frozenQuantity']
|
49
|
+
end
|
50
|
+
hash
|
51
|
+
end
|
52
|
+
|
53
|
+
def rest_client(params, rescued_codes = 200)
|
54
|
+
RestClient::Request.execute(params.merge(timeout: 3)) do |response|
|
55
|
+
code = response.code
|
56
|
+
unless Array.wrap(rescued_codes).include?(code)
|
57
|
+
raise "Response Code is #{code}"
|
58
|
+
end
|
59
|
+
|
60
|
+
response
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
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.30
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- okaaryanata
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-16 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/zilingo_quantity_service.rb
|
147
148
|
homepage:
|
148
149
|
licenses: []
|
149
150
|
metadata: {}
|