tiny_builder 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tiny_builder/apigateway_helper.rb +11 -0
- data/lib/tiny_builder/mode_executor.rb +2 -0
- data/lib/tiny_builder/quantity_builder.rb +5 -1
- data/lib/tiny_builder/version.rb +1 -1
- data/lib/tiny_builder/woocommerce_quantity.rb +47 -0
- data/lib/tiny_builder.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0697caf27e45cd86fc137e9b8e44043d56f36049f984606bb5dae3b00376a586'
|
4
|
+
data.tar.gz: 7331985a4c4aecdeac1f47268c96682972d345990ace314fabc807ad83568f60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f85ab0ac6f474a7b62e96e0f030c4bb0694561f31e66a4c12beadfad4621684e9024d27ffdc9b9c2b2c9015115b6ce72ce915cf27ea70822a5284b971c2417ad
|
7
|
+
data.tar.gz: 85e4aa9d32dc4ce06ff105f82a698f0b72b2c8c19a8fe53df03b2f557ab01fc8ebc9d041b0c393d235f74f751f06810bce07510fc54c3beb90b8b8c619dd9537
|
@@ -55,5 +55,16 @@ class TinyBuilder
|
|
55
55
|
def shopify_location_url
|
56
56
|
apigateway_url + '/shopify/data_location'
|
57
57
|
end
|
58
|
+
|
59
|
+
def woocommerce_product_url
|
60
|
+
apigateway_url + '/woocommerce/item'
|
61
|
+
end
|
62
|
+
|
63
|
+
def woocommerce_item_payload(listing)
|
64
|
+
{
|
65
|
+
"credential": credential,
|
66
|
+
"data": { "local_item_id": listing.local_item_id, local_id: listing[:local_id] }
|
67
|
+
}.to_json
|
68
|
+
end
|
58
69
|
end
|
59
70
|
end
|
@@ -35,6 +35,8 @@ class TinyBuilder
|
|
35
35
|
TinyBuilder::ZaloraQuantity.new(credential, listings).perform
|
36
36
|
elsif credential['channel_id'] == 2
|
37
37
|
TinyBuilder::ShopifyQuantity.new(credential, listings).perform
|
38
|
+
elsif credential['channel_id'] == 19
|
39
|
+
TinyBuilder::WoocommerceQuantity.new(credential, listings).perform
|
38
40
|
end
|
39
41
|
end
|
40
42
|
end
|
@@ -9,11 +9,15 @@ class TinyBuilder
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def channel_data(listing)
|
12
|
-
if channel_id
|
12
|
+
if channel_id == 2
|
13
13
|
{
|
14
14
|
inventory_item_id: listing[:inventory_item_id],
|
15
15
|
location_id: listing[:location_id]
|
16
16
|
}
|
17
|
+
elsif channel_id == 19
|
18
|
+
{
|
19
|
+
meta_location_id: listing[:meta_location_id]
|
20
|
+
}
|
17
21
|
else
|
18
22
|
{}
|
19
23
|
end
|
data/lib/tiny_builder/version.rb
CHANGED
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class TinyBuilder
|
4
|
+
class WoocommerceQuantity
|
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_location_id(listing)
|
18
|
+
listing.save
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def assign_location_id(listing)
|
23
|
+
return unless listing[:meta_location_id].blank?
|
24
|
+
|
25
|
+
begin
|
26
|
+
listing[:meta_location_id] = meta_location_id(listing)
|
27
|
+
rescue
|
28
|
+
listing[:wocommerce_last_log] = "Error when getting woocommerce location_id"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def meta_location_id(listing)
|
35
|
+
args = {
|
36
|
+
method: :post,
|
37
|
+
url: woocommerce_product_url,
|
38
|
+
payload: woocommerce_item_payload(listing),
|
39
|
+
headers: headers
|
40
|
+
}
|
41
|
+
|
42
|
+
resp = JSON.parse(rest_client(args, [200, 402]))
|
43
|
+
data = Array.wrap(resp['meta_data']).find { |meta_data| meta_data['key'] == 'smifw_location_stocks' }
|
44
|
+
data ? data['id'] : nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/tiny_builder.rb
CHANGED
@@ -12,6 +12,7 @@ require 'tiny_builder/quantity_builder'
|
|
12
12
|
require 'tiny_builder/apigateway_helper'
|
13
13
|
require 'tiny_builder/zalora_quantity'
|
14
14
|
require 'tiny_builder/shopify_quantity'
|
15
|
+
require 'tiny_builder/woocommerce_quantity'
|
15
16
|
|
16
17
|
class TinyBuilder
|
17
18
|
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.
|
4
|
+
version: 0.0.7
|
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
|
+
date: 2023-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -145,6 +145,7 @@ files:
|
|
145
145
|
- lib/tiny_builder/quantity_helper.rb
|
146
146
|
- lib/tiny_builder/shopify_quantity.rb
|
147
147
|
- lib/tiny_builder/version.rb
|
148
|
+
- lib/tiny_builder/woocommerce_quantity.rb
|
148
149
|
- lib/tiny_builder/zalora_quantity.rb
|
149
150
|
homepage:
|
150
151
|
licenses: []
|