item_builder 0.1.15 → 0.1.20

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.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/lib/item_builder.rb +94 -52
  3. data/lib/item_builder/get_quantity_service.rb +22 -29
  4. data/lib/item_builder/modes.rb +11 -3
  5. data/lib/item_builder/modes/active_service.rb +1 -1
  6. data/lib/item_builder/modes/base_service.rb +1 -1
  7. data/lib/item_builder/modes/price/base.rb +1 -1
  8. data/lib/item_builder/modes/price/blibli_service.rb +1 -1
  9. data/lib/item_builder/modes/price/bukalapak_service.rb +1 -1
  10. data/lib/item_builder/modes/price/jd_service.rb +1 -1
  11. data/lib/item_builder/modes/price/sale_price_policy.rb +1 -1
  12. data/lib/item_builder/modes/price/shopify_service.rb +1 -1
  13. data/lib/item_builder/modes/price/zalora_service.rb +1 -1
  14. data/lib/item_builder/modes/price_service.rb +1 -1
  15. data/lib/item_builder/modes/quantity/base.rb +1 -39
  16. data/lib/item_builder/modes/quantity/lazada_service.rb +1 -1
  17. data/lib/item_builder/modes/quantity/zalora_service.rb +1 -1
  18. data/lib/item_builder/modes/quantity_service.rb +21 -6
  19. data/lib/item_builder/modes/simple_service.rb +1 -1
  20. data/lib/item_builder/modes/update/base.rb +1 -1
  21. data/lib/item_builder/modes/update/blibli_service.rb +1 -1
  22. data/lib/item_builder/modes/update/bukalapak_service.rb +1 -1
  23. data/lib/item_builder/modes/update/jd_service.rb +1 -1
  24. data/lib/item_builder/modes/update/lazada_service.rb +1 -1
  25. data/lib/item_builder/modes/update/shopify_service.rb +1 -1
  26. data/lib/item_builder/modes/update/tokopedia_service.rb +1 -1
  27. data/lib/item_builder/modes/update/zalora_service.rb +1 -1
  28. data/lib/item_builder/modes/update_service.rb +1 -1
  29. data/lib/item_builder/version.rb +2 -2
  30. metadata +2 -3
  31. data/lib/item_builder/modes/quantity/blibli_service.rb +0 -51
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78374ce9b35b89257c71b2c25a0ec5ae52490eaa79ca64c777acc1fd65bcb2e5
4
- data.tar.gz: b839aa926980f7479349658c67ed6e870e2c7960944d0f9abcc2839dec21f984
3
+ metadata.gz: 05a5aaf51ca610c9a2ea38268de98a9c610205fae9ecbaf2fdc111799264437f
4
+ data.tar.gz: a8a1de4a22e3002203db71564da0c88ed2f0440b5ef3d3c43faf7b419d912727
5
5
  SHA512:
6
- metadata.gz: 35913352045ce6d2d1df6d641ed49e2a4fcd7e6aca2b8ec7e016315fe8923dad12037db32f3eeb52077f514685673071b3aa548c36460e715e4e4784ead4306c
7
- data.tar.gz: 53928e6cc0be8ad63fb1a42644d4195c031a8a6afc3aece2ff8ae57c3e85a8f49c001288e632d34dfe9c7eae38c6c71175e305823fa73abe65262b61d037ac8d
6
+ metadata.gz: 105786a98ff16a0531fa9d82078d70ddeae34c0b3516b44f84760a415e8bd22195bc8771905580df71dd8e6d3788dbf65a64b16741bc69b56674b4c9e4013bd8
7
+ data.tar.gz: c00f310744876ea11269848eac6dcdef46887a43fc855f92337bb5b1cc90deca4f169cfd20cfc3f1defe751aac53fb03b39edb7a733c42bf6c85e476da0b5b5a
@@ -8,68 +8,110 @@ require 'item_builder/modes/quantity_service'
8
8
  require 'item_builder/modes/simple_service'
9
9
  require 'item_models'
10
10
 
11
- module ItemBuilder
12
- class << self
13
- attr_reader :listing_ids
14
- attr_reader :listings
15
- attr_reader :mode
16
- attr_reader :wh_spaces
17
- attr_reader :variants
18
- attr_reader :variant_ids
19
- def build(listing_ids, mode)
20
- @listing_ids = listing_ids
21
- @mode = mode
22
- mode_check
23
- end
11
+ class ItemBuilder
12
+ def self.build(listing_ids, mode)
13
+ new(listing_ids, mode).mode_check
14
+ end
24
15
 
25
- def mode_check
26
- if mode == :quantity
27
- quantity_mode
28
- else
29
- default
30
- end
31
- end
16
+ attr_reader :listing_ids
17
+ attr_reader :listings
18
+ attr_reader :mode
19
+ attr_reader :wh_spaces
20
+ attr_reader :variants
21
+ attr_reader :variant_ids
32
22
 
33
- def quantity_mode
34
- listings.map do |listing|
35
- modes[mode].new(
36
- listing: listing,
37
- wh_spaces: wh_spaces,
38
- variants: variants
39
- ).perform
40
- end
41
- end
23
+ def initialize(listing_ids, mode)
24
+ @listing_ids = listing_ids
25
+ @mode = mode
26
+ end
42
27
 
43
- def default
44
- listings.map do |listing|
45
- modes[mode].new(listing: listing).perform
46
- end
28
+ def mode_check
29
+ if mode == :quantity
30
+ quantity_mode
31
+ else
32
+ default
47
33
  end
34
+ end
48
35
 
49
- def wh_spaces
50
- @wh_spaces ||= WarehouseSpace.where(item_variant_id: variant_ids)
36
+ def quantity_mode
37
+ listings.map do |listing|
38
+ modes[mode].new(qty_params(listing)).perform
51
39
  end
40
+ end
52
41
 
53
- def variants
54
- @variants ||= Variant.where(id: variant_ids)
55
- end
42
+ def qty_params(listing)
43
+ {
44
+ listing: listing, wh_spaces: wh_spaces,
45
+ variants: variants, stock_allocs: stock_allocs,
46
+ bundles: bundles, item_bundle_variants: item_bundle_variants,
47
+ existing_alloc_stocks: existing_alloc_stocks
48
+ }
49
+ end
56
50
 
57
- def variant_ids
58
- @variant_ids ||= listings.map(&:variant_id).uniq
51
+ def default
52
+ listings.map do |listing|
53
+ modes[mode].new(listing: listing).perform
59
54
  end
55
+ end
60
56
 
61
- def listings
62
- @listings ||= VariantListing.where(id: listing_ids)
63
- end
57
+ def existing_alloc_stocks
58
+ @existing_alloc_stocks ||= VariantListingStockAllocation.where(
59
+ variant_association_id: vl_ids
60
+ ).where('ADDTIME(end_at, "07:00") >= NOW()')
61
+ end
64
62
 
65
- def modes
66
- {
67
- price: ItemBuilder::Modes::PriceService,
68
- quantity: ItemBuilder::Modes::QuantityService,
69
- simple: ItemBuilder::Modes::SimpleService,
70
- active: ItemBuilder::Modes::ActiveService,
71
- update: ItemBuilder::Modes::UpdateService
72
- }
73
- end
63
+ def vl_ids
64
+ @vl_ids ||= variant_listings.map(&:id).uniq
65
+ end
66
+
67
+ def variant_listings
68
+ @variant_listings ||= VariantListing.where(variant_id: variant_ids)
69
+ end
70
+
71
+ def item_bundle_variants
72
+ @item_bundle_variants ||= BundleVariant.where(
73
+ bundle_id: bundle_ids,
74
+ channel_id: listings[0].channel_id
75
+ )
76
+ end
77
+
78
+ def bundle_ids
79
+ @bundle_ids ||= bundles.map(&:id).uniq
80
+ end
81
+
82
+ def bundles
83
+ @bundles ||= Bundle.where(variant_id: variant_ids).group(:variant_id)
84
+ end
85
+
86
+ def stock_allocs
87
+ @stock_allocs ||= VariantListingStockAllocation.where(
88
+ variant_association_id: variant_ids
89
+ )
90
+ end
91
+
92
+ def wh_spaces
93
+ @wh_spaces ||= WarehouseSpace.where(item_variant_id: variant_ids)
94
+ end
95
+
96
+ def variants
97
+ @variants ||= Variant.where(id: variant_ids)
98
+ end
99
+
100
+ def variant_ids
101
+ @variant_ids ||= listings.map(&:variant_id).uniq
102
+ end
103
+
104
+ def listings
105
+ @listings ||= VariantListing.where(id: listing_ids)
106
+ end
107
+
108
+ def modes
109
+ {
110
+ price: ItemBuilder::Modes::PriceService,
111
+ quantity: ItemBuilder::Modes::QuantityService,
112
+ simple: ItemBuilder::Modes::SimpleService,
113
+ active: ItemBuilder::Modes::ActiveService,
114
+ update: ItemBuilder::Modes::UpdateService
115
+ }
74
116
  end
75
117
  end
@@ -2,13 +2,16 @@
2
2
 
3
3
  require 'warehouse_models'
4
4
  require 'item_builder/modes.rb'
5
- module ItemBuilder
5
+ class ItemBuilder
6
6
  class GetQuantityService
7
7
  attr_reader :listing, :wh_sp, :variant
8
8
  def initialize(args)
9
9
  @listing = args.fetch(:listing)
10
10
  @wh_sp = args.fetch(:wh_sp)
11
11
  @variant = args.fetch(:variant)
12
+ @stock_alloc = args.fetch(:stock_alloc)
13
+ @bundle_variants = args.fetch(:bundle_variants)
14
+ @existing_allocated_stock = args.fetch(:existing_allocated_stock)
12
15
  end
13
16
 
14
17
  def perform
@@ -18,7 +21,7 @@ module ItemBuilder
18
21
  # yang masuk di kondisi ini,
19
22
  # artinya akun tersebut ada allocated stock yang aktif
20
23
  allocated_stock
21
- elsif existing_allocated_stock.present?
24
+ elsif @existing_allocated_stock.present?
22
25
  # yang masuk di kondisi ini,
23
26
  # artinya akun tersebut tidak ada allocated stock yang aktif,
24
27
  # namun ada allocated stock yg aktif dari channel lain
@@ -35,25 +38,21 @@ module ItemBuilder
35
38
  def check_consignment_variant?
36
39
  listing.consignment? ||
37
40
  (
38
- !listing.active? && listing.channel_id == 12
41
+ !listing.active? && [11, 12, 15].include?(listing.channel_id)
39
42
  )
40
43
  end
41
44
 
42
45
  def allocated_stock_active?
43
- listing.present? && stock_alloc.present? && allocated_start_end?
46
+ listing.present? && @stock_alloc.present? && allocated_start_end?
44
47
  end
45
48
 
46
49
  def allocated_start_end?
47
- stock_alloc.start_at.beginning_of_day <= Time.now &&
48
- stock_alloc.end_at.end_of_day >= Time.now
50
+ @stock_alloc.start_at.beginning_of_day <= Time.now &&
51
+ @stock_alloc.end_at.end_of_day >= Time.now
49
52
  end
50
53
 
51
54
  def allocated_stock
52
- stock_alloc.quantity.to_i - one_alloc_rsvd_stock(stock_alloc).to_i
53
- end
54
-
55
- def stock_alloc
56
- @stock_alloc ||= listing.variant_listing_stock_allocation
55
+ @stock_alloc.quantity.to_i - one_alloc_rsvd_stock(@stock_alloc).to_i
57
56
  end
58
57
 
59
58
  # warehouse_stock fungsi untuk mendapatkan available quantity
@@ -76,10 +75,10 @@ module ItemBuilder
76
75
 
77
76
  def qty_bundle
78
77
  # Quantity for bundle config
79
- if bundle_variants.present?
78
+ if @bundle_variants.present?
80
79
  qty_list = []
81
- bundle_variants.each do |bvr|
82
- qty = WarehouseSpace.find_by(item_variant_id: bvr.variant_id)&.quantity
80
+ @bundle_variants.each do |bvr|
81
+ qty = wh_sp.select {|ws| s.variant_id == bvr.variant_id }.first.quantity
83
82
  qty ||= 0
84
83
  qty = qty / bvr.unit
85
84
  qty_list.push(qty)
@@ -90,31 +89,27 @@ module ItemBuilder
90
89
  end
91
90
  end
92
91
 
93
- def bundle_variants
94
- Bundle.where(
95
- 'variant_id = ?', variant.id
96
- ).first.bundle_variants.where(channel_id: listing.channel_id)
92
+ def wh_sp
93
+ @wh_sp ||= WarehouseSpace.where(item_variant_id: variant_ids)
97
94
  end
98
95
 
99
- def listing_wh_sp_quantity
100
- @listing_wh_sp_quantity ||= wh_sp&.quantity || 0
96
+ def variant_ids
97
+ @variant_ids ||= @bundle_variants.map(&:variant_id).uniq
101
98
  end
102
99
 
103
- def existing_allocated_stock
104
- VariantListingStockAllocation.where(
105
- variant_association_id: variant.variant_listings.pluck(:id)
106
- ).where('ADDTIME(end_at, "07:00") >= NOW()')
100
+ def listing_wh_sp_quantity
101
+ @listing_wh_sp_quantity ||= wh_sp&.quantity || 0
107
102
  end
108
103
 
109
104
  def count_existing_alloc_stock
110
- return 0 if existing_allocated_stock.blank?
105
+ return 0 if @existing_allocated_stock.blank?
111
106
 
112
- existing_allocated_stock.sum(:quantity)
107
+ @existing_allocated_stock.sum(:quantity)
113
108
  end
114
109
 
115
110
  def count_alloc_rsvd_stock
116
111
  stock = 0
117
- existing_allocated_stock.each do |allocated_stock|
112
+ @existing_allocated_stock.each do |allocated_stock|
118
113
  stock += one_alloc_rsvd_stock(allocated_stock).to_i
119
114
  end
120
115
  stock
@@ -135,8 +130,6 @@ module ItemBuilder
135
130
  # allocated reserved stock
136
131
  def one_alloc_rsvd_stock(allocated_stock)
137
132
  RestClient.get("#{host}?#{params(allocated_stock)}")
138
- rescue RestClient::ExceptionWithResponse => e
139
- e.response
140
133
  end
141
134
  end
142
135
  end
@@ -6,15 +6,23 @@ require 'item_builder/modes/quantity_service'
6
6
  require 'item_builder/modes/simple_service'
7
7
  require 'item_builder/modes/active_service'
8
8
  require 'item_builder/modes/update_service'
9
- module ItemBuilder
9
+ class ItemBuilder
10
10
  module Modes
11
11
  attr_reader :listing
12
12
  attr_reader :wh_spaces
13
13
  attr_reader :variants
14
+ attr_reader :stock_allocs
15
+ attr_reader :bundles
16
+ attr_reader :item_bundle_variants
17
+ attr_reader :existing_alloc_stocks
14
18
  def initialize(args)
15
19
  @listing = args.fetch(:listing)
16
- @wh_spaces = args.fetch(:wh_spaces) || []
17
- @variants = args.fetch(:variants) || []
20
+ @wh_spaces = args.fetch(:wh_spaces, [])
21
+ @variants = args.fetch(:variants, [])
22
+ @stock_allocs = args.fetch(:stock_allocs, [])
23
+ @bundles = args.fetch(:bundles, [])
24
+ @item_bundle_variants = args.fetch(:item_bundle_variants, [])
25
+ @existing_alloc_stocks = args.fetch(:existing_alloc_stocks, [])
18
26
  end
19
27
 
20
28
  def base
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'item_builder/modes.rb'
4
- module ItemBuilder
4
+ class ItemBuilder
5
5
  module Modes
6
6
  class ActiveService
7
7
  include Modes
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'item_builder/modes.rb'
4
- module ItemBuilder
4
+ class ItemBuilder
5
5
  module Modes
6
6
  class BaseService
7
7
  attr_reader :listing
@@ -4,7 +4,7 @@ require 'date'
4
4
  require 'item_builder/modes.rb'
5
5
  require 'item_builder/modes/price_service'
6
6
  require 'item_builder/modes/price/sale_price_policy'
7
- module ItemBuilder
7
+ class ItemBuilder
8
8
  module Modes
9
9
  module Price
10
10
  class Base
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'date'
4
4
  require 'item_builder/modes/price/base'
5
- module ItemBuilder
5
+ class ItemBuilder
6
6
  module Modes
7
7
  module Price
8
8
  class BlibliService < Base
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'date'
4
4
  require 'item_builder/modes/price/base'
5
- module ItemBuilder
5
+ class ItemBuilder
6
6
  module Modes
7
7
  module Price
8
8
  class BukalapakService < Base
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'date'
4
4
  require 'item_builder/modes/price/base'
5
- module ItemBuilder
5
+ class ItemBuilder
6
6
  module Modes
7
7
  module Price
8
8
  class JdService < Base
@@ -3,7 +3,7 @@
3
3
  require 'date'
4
4
  require 'item_builder/modes.rb'
5
5
  require 'item_builder/modes/price_service'
6
- module ItemBuilder
6
+ class ItemBuilder
7
7
  module Modes
8
8
  module Price
9
9
  class SalePricePolicy
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'date'
4
4
  require 'item_builder/modes/price/base'
5
- module ItemBuilder
5
+ class ItemBuilder
6
6
  module Modes
7
7
  module Price
8
8
  class ShopifyService < Base
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'date'
4
4
  require 'item_builder/modes/price/base'
5
- module ItemBuilder
5
+ class ItemBuilder
6
6
  module Modes
7
7
  module Price
8
8
  class ZaloraService < Base
@@ -6,7 +6,7 @@ require 'item_builder/modes/price/bukalapak_service'
6
6
  require 'item_builder/modes/price/zalora_service'
7
7
  require 'item_builder/modes/price/shopify_service'
8
8
  require 'item_builder/modes/price/jd_service'
9
- module ItemBuilder
9
+ class ItemBuilder
10
10
  module Modes
11
11
  class PriceService
12
12
  include Modes
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module ItemBuilder
3
+ class ItemBuilder
4
4
  module Modes
5
5
  module Quantity
6
6
  class Base
@@ -26,48 +26,10 @@ module ItemBuilder
26
26
 
27
27
  def reserved_stock
28
28
  RestClient.get("#{order_host}?#{reserved_params}")
29
- rescue RestClient::ExceptionWithResponse => e
30
- e.response
31
29
  end
32
30
 
33
31
  def apigateway_get
34
32
  RestClient.get("#{host}?#{params}")
35
- rescue RestClient::ExceptionWithResponse => e
36
- e.response
37
- end
38
-
39
- def headers
40
- {
41
- content_type: :json,
42
- accept: :json
43
- }
44
- end
45
-
46
- def credential
47
- account_id = listing.profile_channel_association_id
48
- host = ENV['CREDENTIAL_URL'] || 'user.forstok.com'
49
- begin
50
- RestClient.get("#{host}/credential?account_id=#{account_id}")
51
- rescue RestClient::ExceptionWithResponse => e
52
- e.response
53
- end
54
- end
55
-
56
- def data
57
- {
58
- "credential": JSON.parse(credential)['credential'],
59
- "data": request
60
- }
61
- end
62
-
63
- def api_data
64
- data.to_json
65
- end
66
-
67
- def apigateway_post
68
- RestClient.post(url, api_data, headers)
69
- rescue RestClient::ExceptionWithResponse => e
70
- e.response
71
33
  end
72
34
  end
73
35
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'item_builder/modes/quantity/base'
4
- module ItemBuilder
4
+ class ItemBuilder
5
5
  module Modes
6
6
  module Quantity
7
7
  class LazadaService < Base
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'item_builder/modes/quantity/base'
4
- module ItemBuilder
4
+ class ItemBuilder
5
5
  module Modes
6
6
  module Quantity
7
7
  class ZaloraService < Base
@@ -5,16 +5,14 @@ require 'item_builder/modes.rb'
5
5
  require 'item_builder/get_quantity_service'
6
6
  require 'item_builder/modes/quantity/base'
7
7
  require 'item_builder/modes/quantity/lazada_service'
8
- require 'item_builder/modes/quantity/blibli_service'
9
8
  require 'item_builder/modes/quantity/zalora_service'
10
- module ItemBuilder
9
+ class ItemBuilder
11
10
  module Modes
12
11
  class QuantityService
13
12
  include Modes
14
13
 
15
14
  QUANTITY_CHANNEL = {}.tap do |hash|
16
15
  hash[3] = :Lazada
17
- hash[9] = :Blibli
18
16
  hash[13] = :Zalora
19
17
  end.freeze
20
18
 
@@ -48,12 +46,29 @@ module ItemBuilder
48
46
 
49
47
  def available_quantity
50
48
  ItemBuilder::GetQuantityService.new(
51
- listing: listing,
52
- variant: variant,
53
- wh_sp: warehouse
49
+ listing: listing, variant: variant,
50
+ wh_sp: warehouse, stock_alloc: stock_alloc,
51
+ bundle_variants: bundle_variants,
52
+ existing_allocated_stock: existing_allocated_stock
54
53
  ).perform
55
54
  end
56
55
 
56
+ def existing_allocated_stock
57
+ existing_alloc_stocks.select {|eas| eas.variant_association_id == listing.id }
58
+ end
59
+
60
+ def bundle_variants
61
+ item_bundle_variants.select {|ibv| ibv.bundle_id == bundle.id }
62
+ end
63
+
64
+ def bundle
65
+ bundles.select {|b| b.variant_id == listing.variant_id }.first
66
+ end
67
+
68
+ def stock_alloc
69
+ stock_allocs.select {|sa| sa.variant_association_id == listing.id }.first
70
+ end
71
+
57
72
  def warehouse
58
73
  wh_spaces.select {|ws| ws.item_variant_id == listing.variant_id }.first
59
74
  end
@@ -3,7 +3,7 @@
3
3
  require 'item_builder/modes/quantity_service.rb'
4
4
  require 'item_builder/modes/price_service.rb'
5
5
  require 'item_builder/modes.rb'
6
- module ItemBuilder
6
+ class ItemBuilder
7
7
  module Modes
8
8
  class SimpleService
9
9
  include Modes
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'item_builder/modes.rb'
4
- module ItemBuilder
4
+ class ItemBuilder
5
5
  module Modes
6
6
  module Update
7
7
  class Base
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'item_builder/modes/update/base'
4
- module ItemBuilder
4
+ class ItemBuilder
5
5
  module Modes
6
6
  module Update
7
7
  class BlibliService < Base
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'item_builder/modes/update/base'
4
- module ItemBuilder
4
+ class ItemBuilder
5
5
  module Modes
6
6
  module Update
7
7
  class BukalapakService < Base
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'item_builder/modes/update/base'
4
- module ItemBuilder
4
+ class ItemBuilder
5
5
  module Modes
6
6
  module Update
7
7
  class JdService < Base
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'item_builder/modes/update/base'
4
- module ItemBuilder
4
+ class ItemBuilder
5
5
  module Modes
6
6
  module Update
7
7
  class LazadaService < Base
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'item_builder/modes/update/base'
4
- module ItemBuilder
4
+ class ItemBuilder
5
5
  module Modes
6
6
  module Update
7
7
  class ShopifyService < Base
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'item_builder/modes/update/base'
4
- module ItemBuilder
4
+ class ItemBuilder
5
5
  module Modes
6
6
  module Update
7
7
  class TokopediaService < Base
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'item_builder/modes/update/base'
4
- module ItemBuilder
4
+ class ItemBuilder
5
5
  module Modes
6
6
  module Update
7
7
  class ZaloraService < Base
@@ -8,7 +8,7 @@ require 'item_builder/modes/update/zalora_service'
8
8
  require 'item_builder/modes/update/shopify_service'
9
9
  require 'item_builder/modes/update/jd_service'
10
10
  require 'item_builder/modes/update/tokopedia_service'
11
- module ItemBuilder
11
+ class ItemBuilder
12
12
  module Modes
13
13
  class UpdateService
14
14
  include Modes
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module ItemBuilder
4
- VERSION = '0.1.15'
3
+ class ItemBuilder
4
+ VERSION = '0.1.20'
5
5
  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.15
4
+ version: 0.1.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - okaaryanata
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-13 00:00:00.000000000 Z
11
+ date: 2021-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -129,7 +129,6 @@ files:
129
129
  - lib/item_builder/modes/price/zalora_service.rb
130
130
  - lib/item_builder/modes/price_service.rb
131
131
  - lib/item_builder/modes/quantity/base.rb
132
- - lib/item_builder/modes/quantity/blibli_service.rb
133
132
  - lib/item_builder/modes/quantity/lazada_service.rb
134
133
  - lib/item_builder/modes/quantity/zalora_service.rb
135
134
  - lib/item_builder/modes/quantity_service.rb
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'item_builder/modes/quantity/base'
4
- module ItemBuilder
5
- module Modes
6
- module Quantity
7
- class BlibliService < Base
8
- def perform
9
- local_variant
10
- end
11
-
12
- def local_variant
13
- qty = 0
14
- local_product['value']['items'].each do |item|
15
- qty = total_quantity(item) if item['itemSku'] == listing.local_id
16
- end
17
- qty
18
- end
19
-
20
- def total_quantity(item)
21
- # Make stock 0
22
- # if local reserved quantity is bigger than available quantity
23
- if item['reservedStockLevel2'] > available_quantity
24
- 0
25
- else
26
- available_quantity
27
- end
28
- end
29
-
30
- # Find local product based on id
31
- # @return [Hash] Local Blibli product
32
- def local_product
33
- @local_product ||= JSON.parse(apigateway_post)
34
- end
35
-
36
- private
37
-
38
- def request
39
- {
40
- "gdnSku": listing.local_id
41
- }
42
- end
43
-
44
- def url
45
- url = ENV['API_GATEWAY_URL'] || 'apigateway.forstok.com'
46
- url + '/blibli/item'
47
- end
48
- end
49
- end
50
- end
51
- end