tiny_builder 0.0.5 → 0.0.6

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: a7008ba5de564b4e194e0e062a5fe8b42d2db1389467486916b56593d1bc55cf
4
- data.tar.gz: 4f618de26362c65b4b7c4613e79c207888982b7a467aeabd6ebcf9e129bd0d7f
3
+ metadata.gz: 0e74aed48d7a6bde96ec9e6dbaf479044bd2d551b59f47992e72e4169ce58da3
4
+ data.tar.gz: 94ec01f9675a3d3b54dceb4ec3ebc749c1b2485a425156b6c5017b5eefb0a798
5
5
  SHA512:
6
- metadata.gz: 463f30d62d92f1d6da463eb800f507268b69b0cb6d27e44833be680f1f98f892abe78ca99e2e4be02c9fda4aa8ab854f1f4b8900cfe9d69d4fc2953d8ba4a9eb
7
- data.tar.gz: 40f1c096bb3d1fcbe0e3cb355393f845d2938d83decca41e9e002edf130622a54a4504600e6fe47f619bb100a8be07e76552388414e1dd561681f4945150c044
6
+ metadata.gz: 6ca8521dac8c51243a9372cb63fa67b934a675af3127dcc01aa79494c9e2ac3ff9507cde3207bf579b5d006769fee0b44c2f2a5827a89aa696f749223dcd073d
7
+ data.tar.gz: c04d6de7140861ed1ab84e752d03595d0eafa7b0f184f6c269b5fe326591b3f6f8036c30ab5cd8b35e0d77726e647d1406852146295ee83e624ece9b3d63c4bd
@@ -14,9 +14,12 @@ class TinyBuilder
14
14
  end
15
15
  end
16
16
 
17
+ def apigateway_url
18
+ ENV['API_GATEWAY_URL'] || raise('api gateway is not set')
19
+ end
20
+
17
21
  def zalora_stock_url
18
- url = ENV['API_GATEWAY_URL'] || raise('api gateway is not set')
19
- url + "/zalora/listing_stock"
22
+ apigateway_url + "/zalora/listing_stock"
20
23
  end
21
24
 
22
25
  def headers
@@ -31,5 +34,26 @@ class TinyBuilder
31
34
  }
32
35
  }.to_json
33
36
  end
37
+
38
+ def inventory_item_payload(listing)
39
+ {
40
+ "credential": credential,
41
+ "data": { "local_id": listing[:local_id] }
42
+ }.to_json
43
+ end
44
+
45
+ def location_payload
46
+ {
47
+ "credential": credential
48
+ }.to_json
49
+ end
50
+
51
+ def shopify_inventory_item_url
52
+ apigateway_url + '/shopify/data_variant'
53
+ end
54
+
55
+ def shopify_location_url
56
+ apigateway_url + '/shopify/data_location'
57
+ end
34
58
  end
35
59
  end
@@ -34,6 +34,7 @@ class TinyBuilder
34
34
  if credential['channel_id'] == 13
35
35
  TinyBuilder::ZaloraQuantity.new(credential, listings).perform
36
36
  elsif credential['channel_id'] == 2
37
+ TinyBuilder::ShopifyQuantity.new(credential, listings).perform
37
38
  end
38
39
  end
39
40
  end
@@ -5,7 +5,18 @@ require 'tiny_builder/base_builder'
5
5
  class TinyBuilder
6
6
  class QuantityBuilder < BaseBuilder
7
7
  def to_h(listing)
8
- quantity_hash(listing)
8
+ quantity_hash(listing).merge(channel_data(listing))
9
+ end
10
+
11
+ def channel_data(listing)
12
+ if channel_id = 2
13
+ {
14
+ inventory_item_id: listing[:inventory_item_id],
15
+ location_id: listing[:location_id]
16
+ }
17
+ else
18
+ {}
19
+ end
9
20
  end
10
21
  end
11
22
  end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ class TinyBuilder
4
+ class ShopifyQuantity
5
+ include ApigatewayHelper
6
+
7
+ attr_reader :credential
8
+ attr_reader :listings
9
+
10
+ def initialize(credential, listings)
11
+ @credential = credential
12
+ @listings = listings
13
+ end
14
+
15
+ def perform
16
+ listings.each do |listing|
17
+ assign_inventory_item_id(listing)
18
+ assign_location_id(listing)
19
+ listing.save
20
+ end
21
+ end
22
+
23
+ def assign_inventory_item_id(listing)
24
+ return unless listing[:inventory_item_id].blank?
25
+
26
+ begin
27
+ listing[:inventory_item_id] = inventory_item_id(listing)
28
+ rescue
29
+ listing[:shopify_last_log] = "Error when getting inventory_item_id"
30
+ end
31
+ end
32
+
33
+ def assign_location_id(listing)
34
+ return unless listing[:location_id].blank?
35
+
36
+ begin
37
+ listing[:location_id] = credential['primary_warehouse_id'] || location_id
38
+ rescue
39
+ listing[:shopify_last_log] = "Error when getting location_id"
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def inventory_item_id(listing)
46
+ args = {
47
+ method: :post,
48
+ url: shopify_inventory_item_url,
49
+ payload: inventory_item_payload(listing),
50
+ headers: headers
51
+ }
52
+
53
+ resp = JSON.parse(rest_client(args, [200, 402]))
54
+ resp['inventory_item_id']
55
+ end
56
+
57
+ def location_id
58
+ @location_id ||= get_location_id
59
+ end
60
+
61
+ def get_location_id
62
+ args = {
63
+ method: :post,
64
+ url: shopify_location_url,
65
+ payload: location_payload,
66
+ headers: headers
67
+ }
68
+
69
+ resp = JSON.parse(rest_client(args, [200, 402]))
70
+ resp['id']
71
+ end
72
+ end
73
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class TinyBuilder
4
- VERSION = '0.0.5'
4
+ VERSION = '0.0.6'
5
5
  end
data/lib/tiny_builder.rb CHANGED
@@ -11,6 +11,7 @@ require 'tiny_builder/price_builder'
11
11
  require 'tiny_builder/quantity_builder'
12
12
  require 'tiny_builder/apigateway_helper'
13
13
  require 'tiny_builder/zalora_quantity'
14
+ require 'tiny_builder/shopify_quantity'
14
15
 
15
16
  class TinyBuilder
16
17
  include ModeExecutor
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - hayakaza
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-06 00:00:00.000000000 Z
11
+ date: 2023-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -143,6 +143,7 @@ files:
143
143
  - lib/tiny_builder/quantity_builder.rb
144
144
  - lib/tiny_builder/quantity_counter.rb
145
145
  - lib/tiny_builder/quantity_helper.rb
146
+ - lib/tiny_builder/shopify_quantity.rb
146
147
  - lib/tiny_builder/version.rb
147
148
  - lib/tiny_builder/zalora_quantity.rb
148
149
  homepage: