item_builder 0.1.26 → 0.1.31

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: 8492d320599234405f053957073589a52c3338b44df6d9788de69a166dda571a
4
- data.tar.gz: 61ca9debe7fbd6eb3fb52e7231a486049f2d223fc7f511fbac1bb1aeea63bbc5
3
+ metadata.gz: 74e5b0e4f3ee0a2d87e595f5659d70650b00abb1480fe943e1fbb5ccf54237a6
4
+ data.tar.gz: 77ddf3ca953ba1628f5e01a0687d0d2609658dcc44d5c829f31ba70a36ce7380
5
5
  SHA512:
6
- metadata.gz: 7bc64e7ef1ca238fb7ba1d09348501f55b3417de1982a6b8009fae8687bf3e6213491f209a6104df813ec35a059d935daaab89b8d927a0ee091aa5e551ae7201
7
- data.tar.gz: 97670ab47df3c2f85bf88fb8f3eb3f56faf6c77d8c302255777eb6e1819ab847235feda7b633c5af06f56df3c6648183c5bc080e4f2640273d10434450df52f6
6
+ metadata.gz: b3fd6fcb694762e46917de1fa61e0104c40d092595886037f171ef91701af2130eb005130f3315915105de049d95d67c4bb16df5c62927a1dc3d63cefa353d0f
7
+ data.tar.gz: 41c7495ab40026e6fbcd9a7f8f40c63619de96b78c660fb374e9be4c630edb60a0fc7e6f11429d7fb4997f6b4f2c16ca9946a8b60239dbb1c21f981c2e84e4b3
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)
@@ -35,7 +36,14 @@ class ItemBuilder
35
36
 
36
37
  def quantity_simple_mode
37
38
  listings.map do |listing|
38
- modes[mode].new(qty_simple_params(listing)).perform
39
+ if listing.channel_id == 18
40
+ new_param = qty_simple_params(listing)
41
+ .merge({zilingo_delta_quantity: zilingo_delta_quantity})
42
+
43
+ modes[mode].new(new_param).perform
44
+ else
45
+ modes[mode].new(qty_simple_params(listing)).perform
46
+ end
39
47
  end
40
48
  end
41
49
 
@@ -45,7 +53,7 @@ class ItemBuilder
45
53
  stock_allocs: stock_allocs, variant_listings: variant_listings,
46
54
  bundles: bundles, item_bundle_variants: item_bundle_variants,
47
55
  existing_alloc_stocks: existing_alloc_stocks,
48
- reserved_stocks: reserved_stocks
56
+ reserved_stocks: reserved_stocks
49
57
  }
50
58
  end
51
59
 
@@ -71,8 +79,7 @@ class ItemBuilder
71
79
 
72
80
  def item_bundle_variants
73
81
  @item_bundle_variants ||= BundleVariant.where(
74
- bundle_id: bundle_ids,
75
- channel_id: listings[0].channel_id
82
+ bundle_id: bundle_ids
76
83
  )
77
84
  end
78
85
 
@@ -106,6 +113,16 @@ class ItemBuilder
106
113
  @listings ||= VariantListing.where(id: listing_ids)
107
114
  end
108
115
 
116
+ def skus
117
+ @skus ||= listings.map(&:local_id).uniq
118
+ end
119
+
120
+ def zilingo_delta_quantity
121
+ @zilingo_delta_quantity ||= ItemBuilder::ZilingoQuantityService.new(
122
+ listings: listings, skus: skus
123
+ ).perform
124
+ end
125
+
109
126
  def modes
110
127
  {
111
128
  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
@@ -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.26'
4
+ VERSION = '0.1.31'
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.26
4
+ version: 0.1.31
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-02-17 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: {}