item_builder 0.1.28 → 0.1.33

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 637545e1e40b3f319760f991d19621b9a0e68b48a16c9219ce4103995070727f
4
- data.tar.gz: 9128cf0c849fc64ac5f60393c173a7c95d68dc169a75acae8c08b22bad451428
3
+ metadata.gz: e5163bc9aeaf2a76f547dc19cb482de6f50fe456e9f9a62860493e9a4d2c4a7c
4
+ data.tar.gz: fb2f1120b1518a26fbf7c36892afe8bfb2e7dd38fc4797e8864cf7b7c1a9fb8a
5
5
  SHA512:
6
- metadata.gz: 1b854582f9f8bd9f31eee880d643dc1f4884529740fcbf147c892ab5e08cecc07fe969c7f8f0926d712a8934c8390a1a15ee05681ad211be3873ddd7b1a0ca30
7
- data.tar.gz: 7bf2f7c0711a76a18ca01bb6321a0f7d82d5a81d37cf6f633aed36af3728da47de0e8093e4f1571e66ba99e4d3deb47ac6b57045cc8251e686e9a6226e6afdd3
6
+ metadata.gz: 5cd6ffa5b4add1d53f21dad2fb40475dffecc8950116c047c90d6802d56262d1fec562565ee02fae17740b660b4c6ec073f807ea68890949506f9d34fe197ec1
7
+ data.tar.gz: f5c222851018274f3b03d768d0c7e78273061ef7e9c4bcf3e8c032cb533db62284291beadedccf6a83b6000ac54ca40220de3a6a1a2dbc661c064ca5316ae0e1
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
 
@@ -105,6 +118,16 @@ class ItemBuilder
105
118
  @listings ||= VariantListing.where(id: listing_ids)
106
119
  end
107
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
+
108
131
  def modes
109
132
  {
110
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
@@ -22,7 +24,7 @@ class ItemBuilder
22
24
 
23
25
  def to_h
24
26
  {
25
- quantity: qty
27
+ quantity: [qty, 0].sort[1]
26
28
  }
27
29
  end
28
30
 
@@ -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.28'
4
+ VERSION = '0.1.33'
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.28
4
+ version: 0.1.33
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-10 00:00:00.000000000 Z
11
+ date: 2021-03-03 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