item_builder_mwh 0.1.12 → 0.1.13

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: 5d1bdd2602056502397904701b901ca0e64fc1e1720d19ad6224bf2730abb35f
4
- data.tar.gz: d38c4c58bc14bb122b5134709eb6716dd050dcd2c7bf1a6af953c4c26df06f7a
3
+ metadata.gz: 5e0e327d2d75048169959add8240680ad93b2e945ad143bd50ceebde691fe1e6
4
+ data.tar.gz: d4989a73567a5a977a704bc96d746271cd7aaf84d3112fe867381f42a3ed1b23
5
5
  SHA512:
6
- metadata.gz: 5e9db45fb157df0b8a978e169a0b5a54704421df77028f1996584010d407e8f8649642db4d4db2c7dd427c266d020ea3f131ae772d45ba357d4dff9935db2f63
7
- data.tar.gz: d3014d0450be1a652e55bc0b708ed89eeed6fedc29a279a58fad42134b52b5c845bd30eeb7d7eb860ae6b70a8df22514d67124a56cdc11282b7d4f8457652f84
6
+ metadata.gz: 8e1dcdd50c6cc91c051bab7a6722dc11b70b1a0db58f99538f37ed651cc4522f6f807c03798f4d142ef7f8fc6de62c6edad6354eb68d2bd16ba35ec5f996c2d3
7
+ data.tar.gz: d52b17a20acec7efde7d482261c9782cb9548f3fc2b3489f7e440e719b2c4b01ab0e3f472f49a1df0545af277c98567e6903932a08592d191c1a2479c5130f74
@@ -7,6 +7,7 @@ require 'item_builder_mwh/modes/price_service'
7
7
  require 'item_builder_mwh/modes/quantity_service'
8
8
  require 'item_builder_mwh/modes/simple_service'
9
9
  require 'item_models'
10
+ require 'item_builder_mwh/zilingo_quantity_service'
10
11
 
11
12
  class ItemBuilderMwh
12
13
  attr_reader :listing_ids
@@ -34,7 +35,14 @@ class ItemBuilderMwh
34
35
 
35
36
  def quantity_simple_mode
36
37
  listings.map do |listing|
37
- modes[mode].new(qty_simple_params(listing)).perform
38
+ if listing.channel_id == 18
39
+ new_param = qty_simple_params(listing)
40
+ .merge({zilingo_delta_quantity: zilingo_delta_quantity})
41
+
42
+ modes[mode].new(new_param).perform
43
+ else
44
+ modes[mode].new(qty_simple_params(listing)).perform
45
+ end
38
46
  end
39
47
  end
40
48
 
@@ -100,6 +108,16 @@ class ItemBuilderMwh
100
108
  @variant_ids ||= listings.map(&:variant_id).uniq
101
109
  end
102
110
 
111
+ def skus
112
+ @skus ||= listings.map(&:local_id).uniq
113
+ end
114
+
115
+ def zilingo_delta_quantity
116
+ @zilingo_delta_quantity ||= ItemBuilderMwh::ZilingoQuantityService.new(
117
+ listings: listings, skus: skus
118
+ ).perform
119
+ end
120
+
103
121
  def order_host
104
122
  url = ENV['ORDERS_URL'] || 'orders.forstok.com'
105
123
  url + '/api/v3/item_line/reserved_stock'
@@ -16,6 +16,7 @@ class ItemBuilderMwh
16
16
  attr_reader :existing_alloc_stocks
17
17
  attr_reader :variant_listings
18
18
  attr_reader :reserved_stocks
19
+ attr_reader :zilingo_delta_quantity
19
20
  def initialize(args)
20
21
  @listing = args.fetch(:listing)
21
22
  @wh_spaces = args.fetch(:wh_spaces, [])
@@ -26,6 +27,7 @@ class ItemBuilderMwh
26
27
  @existing_alloc_stocks = args.fetch(:existing_alloc_stocks, [])
27
28
  @variant_listings = args.fetch(:variant_listings, [])
28
29
  @reserved_stocks = args.fetch(:reserved_stocks, [])
30
+ @zilingo_delta_quantity = args.fetch(:zilingo_delta_quantity, [])
29
31
  warehouse
30
32
  end
31
33
 
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'item_builder_mwh/modes/quantity/base'
4
+ class ItemBuilderMwh
5
+ module Modes
6
+ module Quantity
7
+ class ZilingoService < Base
8
+ def perform
9
+ available_quantity - reserved_stock.to_i
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -6,6 +6,8 @@ require 'item_builder_mwh/get_quantity_service'
6
6
  require 'item_builder_mwh/modes/quantity/base'
7
7
  require 'item_builder_mwh/modes/quantity/lazada_service'
8
8
  require 'item_builder_mwh/modes/quantity/zalora_service'
9
+ require 'item_builder_mwh/modes/quantity/zilingo_service'
10
+
9
11
  class ItemBuilderMwh
10
12
  module Modes
11
13
  class QuantityService
@@ -14,6 +16,7 @@ class ItemBuilderMwh
14
16
  QUANTITY_CHANNEL = {}.tap do |hash|
15
17
  hash[3] = :Lazada
16
18
  hash[13] = :Zalora
19
+ hash[18] = :Zilingo
17
20
  end.freeze
18
21
 
19
22
  def perform
@@ -50,7 +53,11 @@ class ItemBuilderMwh
50
53
  end
51
54
 
52
55
  def reserved_stock
53
- reserved_stocks.find {|rs| rs['variant_id'] == listing.variant_id }['reserved_quantity']
56
+ if channel_name == 'Zilingo'
57
+ zilingo_delta_quantity[listing.local_id].to_i
58
+ else
59
+ reserved_stocks.find {|rs| rs['variant_id'] == listing.variant_id }['reserved_quantity']
60
+ end
54
61
  end
55
62
 
56
63
  def available_quantity(qty)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ItemBuilderMwh
4
- VERSION = '0.1.12'
4
+ VERSION = '0.1.13'
5
5
  end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'item_builder_mwh/modes.rb'
4
+ class ItemBuilderMwh
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_mwh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.13
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-02-16 00:00:00.000000000 Z
11
+ date: 2021-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -131,6 +131,7 @@ files:
131
131
  - lib/item_builder_mwh/modes/quantity/base.rb
132
132
  - lib/item_builder_mwh/modes/quantity/lazada_service.rb
133
133
  - lib/item_builder_mwh/modes/quantity/zalora_service.rb
134
+ - lib/item_builder_mwh/modes/quantity/zilingo_service.rb
134
135
  - lib/item_builder_mwh/modes/quantity_service.rb
135
136
  - lib/item_builder_mwh/modes/simple/base.rb
136
137
  - lib/item_builder_mwh/modes/simple/blibli_service.rb
@@ -143,6 +144,7 @@ files:
143
144
  - lib/item_builder_mwh/modes/simple/zalora_service.rb
144
145
  - lib/item_builder_mwh/modes/simple_service.rb
145
146
  - lib/item_builder_mwh/version.rb
147
+ - lib/item_builder_mwh/zilingo_quantity_service.rb
146
148
  homepage:
147
149
  licenses: []
148
150
  metadata: {}