item_builder 0.1.27 → 0.1.32

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: a763ddee15f0b1e5b2eb969edb188ea8fe00efbfdedf9a7e4dbadb166da740f7
4
- data.tar.gz: 9717492d76e8d5acdeacb2ebb3187d56d2e0518ef713bab43bf407b4b18a8c3d
3
+ metadata.gz: 85f8e8062ec5018662226331da7ff63bdc7f30ad96c0acd01583d367afc52f18
4
+ data.tar.gz: 4ccbef79af924bfa8b997ec5a999853324e12711266861ecbd5f60f0f25b5364
5
5
  SHA512:
6
- metadata.gz: ce4cd090c4a1a76ad0396eb441c8f4efd86847b7d9385ef895e031b98d92cb14964efa396c68f44b2f048892b07d7be09f3661d7c33404e7779f68c665f89243
7
- data.tar.gz: b0e75e13332ca568b68c3344b85c591c5f644a97ed6807bcba4be6b775e3716dceaecfc08f0ab4814d513fe8b0624d429ec8995de56a0e72b0dbaf02fded415a
6
+ metadata.gz: fc31355e9b290e792d52dda3b3ec445c648b49521279c931b6daf2e16d148cb3b2d7b2db1a17dbca0a906514e82b1831c0439fb776f6e2d8c474c93d595234a2
7
+ data.tar.gz: 7d3e836f23c40b9ded8904933b90701aac8d9ea512c140b0e7b04c495c37a81d18d28491dafd5dcc729a01f0470eaa933dd7c7b228e8a89c364e97be04a58531
data/lib/item_builder.rb CHANGED
@@ -6,7 +6,9 @@ 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'
11
+ require 'item_builder/zilingo_quantity_service'
10
12
 
11
13
  class ItemBuilder
12
14
  def self.build(listing_ids, mode)
@@ -26,7 +28,7 @@ class ItemBuilder
26
28
  end
27
29
 
28
30
  def mode_check
29
- if mode == :quantity || mode == :simple
31
+ if mode == :quantity || mode == :simple
30
32
  quantity_simple_mode
31
33
  else
32
34
  default
@@ -35,7 +37,14 @@ class ItemBuilder
35
37
 
36
38
  def quantity_simple_mode
37
39
  listings.map do |listing|
38
- modes[mode].new(qty_simple_params(listing)).perform
40
+ if listing.channel_id == 18
41
+ new_param = qty_simple_params(listing)
42
+ .merge({zilingo_delta_quantity: zilingo_delta_quantity})
43
+
44
+ modes[mode].new(new_param).perform
45
+ else
46
+ modes[mode].new(qty_simple_params(listing)).perform
47
+ end
39
48
  end
40
49
  end
41
50
 
@@ -45,13 +54,17 @@ class ItemBuilder
45
54
  stock_allocs: stock_allocs, variant_listings: variant_listings,
46
55
  bundles: bundles, item_bundle_variants: item_bundle_variants,
47
56
  existing_alloc_stocks: existing_alloc_stocks,
48
- reserved_stocks: reserved_stocks
57
+ reserved_stocks: reserved_stocks
49
58
  }
50
59
  end
51
60
 
52
61
  def default
53
62
  listings.map do |listing|
54
- modes[mode].new(listing: listing).perform
63
+ if listing.channel_id == 2 && mode == :active
64
+ modes[mode].new(qty_simple_params(listing)).perform
65
+ else
66
+ modes[mode].new(listing: listing).perform
67
+ end
55
68
  end
56
69
  end
57
70
 
@@ -71,9 +84,7 @@ class ItemBuilder
71
84
 
72
85
  def item_bundle_variants
73
86
  @item_bundle_variants ||= BundleVariant.where(
74
- bundle_id: bundle_ids,
75
- channel_id: listings[0].channel_id,
76
- removed_at: nil
87
+ bundle_id: bundle_ids
77
88
  )
78
89
  end
79
90
 
@@ -107,6 +118,16 @@ class ItemBuilder
107
118
  @listings ||= VariantListing.where(id: listing_ids)
108
119
  end
109
120
 
121
+ def skus
122
+ @skus ||= listings.map(&:local_id).uniq
123
+ end
124
+
125
+ def zilingo_delta_quantity
126
+ @zilingo_delta_quantity ||= ItemBuilder::ZilingoQuantityService.new(
127
+ listings: listings, skus: skus
128
+ ).perform
129
+ end
130
+
110
131
  def modes
111
132
  {
112
133
  price: ItemBuilder::Modes::PriceService,
@@ -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
@@ -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
- to_h.merge(base)
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,17 @@ 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
+ ).to_h
34
+ end
35
+
20
36
  def active_variant
21
37
  VariantListing
22
38
  .where(local_item_id: listing.local_item_id,
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'item_builder/modes/quantity/base'
4
+ class ItemBuilder
5
+ module Modes
6
+ module Quantity
7
+ class ZilingoService < Base
8
+ def perform
9
+ available_quantity - reserved_stock
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -6,6 +6,7 @@ require 'item_builder/get_quantity_service'
6
6
  require 'item_builder/modes/quantity/base'
7
7
  require 'item_builder/modes/quantity/lazada_service'
8
8
  require 'item_builder/modes/quantity/zalora_service'
9
+ require 'item_builder/modes/quantity/zilingo_service'
9
10
  class ItemBuilder
10
11
  module Modes
11
12
  class QuantityService
@@ -14,6 +15,7 @@ class ItemBuilder
14
15
  QUANTITY_CHANNEL = {}.tap do |hash|
15
16
  hash[3] = :Lazada
16
17
  hash[13] = :Zalora
18
+ hash[18] = :Zilingo
17
19
  end.freeze
18
20
 
19
21
  def perform
@@ -45,7 +47,11 @@ class ItemBuilder
45
47
  end
46
48
 
47
49
  def reserved_stock
48
- reserved_stocks.find {|rs| rs['variant_id'] == listing.variant_id }['reserved_quantity']
50
+ if channel_name == 'Zilingo'
51
+ zilingo_delta_quantity[listing.local_id].to_i
52
+ else
53
+ reserved_stocks.find {|rs| rs['variant_id'] == listing.variant_id }['reserved_quantity']
54
+ end
49
55
  end
50
56
 
51
57
  def available_quantity
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ItemBuilder
4
- VERSION = '0.1.27'
4
+ VERSION = '0.1.32'
5
5
  end
@@ -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.27
4
+ version: 0.1.32
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-08 00:00:00.000000000 Z
11
+ date: 2021-03-01 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/modes/quantity/base.rb
132
132
  - lib/item_builder/modes/quantity/lazada_service.rb
133
133
  - lib/item_builder/modes/quantity/zalora_service.rb
134
+ - lib/item_builder/modes/quantity/zilingo_service.rb
134
135
  - lib/item_builder/modes/quantity_service.rb
135
136
  - lib/item_builder/modes/simple_service.rb
136
137
  - lib/item_builder/modes/update/base.rb
@@ -143,6 +144,7 @@ files:
143
144
  - lib/item_builder/modes/update/zalora_service.rb
144
145
  - lib/item_builder/modes/update_service.rb
145
146
  - lib/item_builder/version.rb
147
+ - lib/item_builder/zilingo_quantity_service.rb
146
148
  homepage:
147
149
  licenses: []
148
150
  metadata: {}
@@ -161,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
163
  - !ruby/object:Gem::Version
162
164
  version: '0'
163
165
  requirements: []
164
- rubygems_version: 3.0.6
166
+ rubygems_version: 3.0.9
165
167
  signing_key:
166
168
  specification_version: 4
167
169
  summary: Item builder