e_plat 0.7.4 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/lib/e_plat/resource/concerns/graph_q_lable.rb +1 -1
- data/lib/e_plat/resource/concerns/overwrite_instance_methods.rb +29 -0
- data/lib/e_plat/resource/platform_specific/shopify/graph_q_l/v_2024_07/input.rb +14 -12
- data/lib/e_plat/resource/product/image.rb +1 -1
- data/lib/e_plat/resource/product/variant.rb +7 -4
- data/lib/e_plat/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11486ca4e2fa5fb088c3db3ba83cbe6084743d680433930434a396c72d5c9171
|
4
|
+
data.tar.gz: 18f2edac7726f48202c5190efa90d6fc8a460f9582df92cbb382897fa160b450
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 435b1d3159de9901f5ef5861a2531d44291d817ada8916e4a15fb7bd7047359734ed3a28055699281c10044f762b2a4b407ceddcc72ae139f8dc42bc2b3c8a19
|
7
|
+
data.tar.gz: fa6904dee0a4bc822219af558319fac7c4849862765b36f56009fe19f631a2d632f40dc0c6ee34753ebfc5167c8afbee7c47c7f9ac56518094f355c244e59926
|
data/README.md
CHANGED
@@ -560,6 +560,7 @@ Unfortunately it's in a Time Integer format. Haven't yet got dynamic conversion
|
|
560
560
|
|
561
561
|
<br>
|
562
562
|
<hr>
|
563
|
+
|
563
564
|
<br>
|
564
565
|
|
565
566
|
## API Coverage
|
@@ -806,6 +807,13 @@ Unfortunately it's in a Time Integer format. Haven't yet got dynamic conversion
|
|
806
807
|
<br>
|
807
808
|
|
808
809
|
|
810
|
+
> [!NOTE]
|
811
|
+
> For all resources, we also have a EPlat::ShopifyWebhook::{resource} class. These use the old REST API mappings that the webhooks still use.
|
812
|
+
> At PreProduct we interact with cached webhook hashes using these classes, e.g. `EPlat::ShopifyWebhook::Product.new({...})`.
|
813
|
+
> Meaning we can safely call getter methods and access the usual EPlat schema.
|
814
|
+
|
815
|
+
|
816
|
+
|
809
817
|
|
810
818
|
<hr>
|
811
819
|
<br>
|
@@ -895,6 +903,8 @@ product.as_json # hash of any updated attributes
|
|
895
903
|
product.as_full_json # hash of all attributes, regardless of if they've been updated or not
|
896
904
|
product.to_json # JSON string of any updated_attributes
|
897
905
|
product.to_full_json # JSON string of all attributes. regardless of if they've been updated or not
|
906
|
+
product.as_eplat_json # hash of all resource's EPlat attributes, values as EPlat getters produce
|
907
|
+
product.to_eplat_json # JSON of all resource's EPlat attributes, values as EPlat getters produce
|
898
908
|
|
899
909
|
```
|
900
910
|
|
@@ -48,6 +48,35 @@ module EPlat
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
+
def to_eplat_json(options = {})
|
52
|
+
root_at_top_of_json = self.mapping.include_root_in_request_body?(self)
|
53
|
+
options[:root] = self.element_name if root_at_top_of_json
|
54
|
+
|
55
|
+
result = '{'
|
56
|
+
result << as_eplat_json.map do |key, value|
|
57
|
+
"#{ActiveSupport::JSON.encode(key.to_s)}:#{ActiveSupport::JSON.encode(value, options)}"
|
58
|
+
end * ','
|
59
|
+
result << '}'
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def as_eplat_json
|
64
|
+
schema_keys = self.class.schema.keys
|
65
|
+
schema_keys.each_with_object({}) do |key, hash|
|
66
|
+
value = send(key)
|
67
|
+
|
68
|
+
hash[key] =
|
69
|
+
if value.is_a?(Array)
|
70
|
+
value.map { |item| item.respond_to?(:as_eplat_json) ? item.as_eplat_json : item }
|
71
|
+
elsif value.respond_to?(:as_eplat_json)
|
72
|
+
value.as_eplat_json
|
73
|
+
else
|
74
|
+
value
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
|
51
80
|
# Create and return a class definition for a resource inside the current resource
|
52
81
|
def create_resource_for(resource_name)
|
53
82
|
resource = Class.new(EPlat::Base) # <- this line changed
|
@@ -43,39 +43,41 @@ class EPlat::Shopify::GraphQL::V202407::Input
|
|
43
43
|
end.to_h.compact_blank
|
44
44
|
end
|
45
45
|
|
46
|
-
def format_graphql_item(item)
|
46
|
+
def format_graphql_item(item, key: nil)
|
47
47
|
case item
|
48
48
|
when Hash
|
49
|
-
"{ #{item.map { |k, v| "#{k}: #{v.is_a?(String) ? enum_friendly(v) : format_graphql_item(v)}" }.join(', ')} }"
|
49
|
+
"{ #{item.map { |k, v| "#{k}: #{v.is_a?(String) ? enum_friendly(v, key: k) : format_graphql_item(v, key: k)}" }.join(', ')} }"
|
50
50
|
when Array
|
51
|
-
"[ #{item.map { |i| format_graphql_item(i) }.join(', ')} ]"
|
51
|
+
"[ #{item.map { |i| format_graphql_item(i, key: key) }.join(', ')} ]"
|
52
52
|
else
|
53
|
-
enum_friendly(item)
|
53
|
+
enum_friendly(item, key: key)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
def enum_friendly(value)
|
58
|
-
case
|
59
|
-
|
57
|
+
def enum_friendly(value, key: nil)
|
58
|
+
case
|
59
|
+
when key == "tags"
|
60
|
+
"\"#{value}\""
|
61
|
+
when value.is_a?(String)
|
60
62
|
value.match?(/\A[A-Z_]+\z/) ? value : "\"#{value}\""
|
61
63
|
else
|
62
64
|
value
|
63
65
|
end
|
64
66
|
end
|
65
67
|
|
66
|
-
def format_graphql_args(args)
|
68
|
+
def format_graphql_args(args, key: nil)
|
67
69
|
args.map do |key, value|
|
68
70
|
case value
|
69
71
|
when Hash
|
70
|
-
"#{key}: { #{format_graphql_args
|
72
|
+
"#{key}: { #{format_graphql_args(value, key:)} }"
|
71
73
|
when Array
|
72
74
|
if (value.first.is_a? Hash)
|
73
|
-
"#{key}: [ #{value.map { |v| "{ #{format_graphql_args
|
75
|
+
"#{key}: [ #{value.map { |v| "{ #{format_graphql_args(v, key:)} }" }.join(', ')} ]"
|
74
76
|
else
|
75
|
-
"#{key}: [ #{value.map { |v| enum_friendly(v) }.join(', ')} ]"
|
77
|
+
"#{key}: [ #{value.map { |v| enum_friendly(v, key: key) }.join(', ')} ]"
|
76
78
|
end
|
77
79
|
when String
|
78
|
-
"#{key}: #{enum_friendly(value)}"
|
80
|
+
"#{key}: #{enum_friendly(value, key: key)}"
|
79
81
|
else
|
80
82
|
"#{key}: #{value}"
|
81
83
|
end
|
@@ -28,7 +28,8 @@ module EPlat
|
|
28
28
|
string :tax_code
|
29
29
|
boolean :requires_shipping
|
30
30
|
string :admin_graphql_api_id
|
31
|
-
|
31
|
+
array :option_values
|
32
|
+
# hash :image # default: {}, just for Shopify Webhooks
|
32
33
|
end
|
33
34
|
|
34
35
|
def save
|
@@ -36,11 +37,13 @@ module EPlat
|
|
36
37
|
super
|
37
38
|
end
|
38
39
|
|
39
|
-
def image_src
|
40
|
+
def image_src(images=[]) # EPlat::Product::Image => string
|
40
41
|
if client.bigcommerce?
|
41
42
|
image_url
|
42
|
-
elsif
|
43
|
-
|
43
|
+
elsif is_a?(EPlat::ShopifyWebhook::Product::Variant)
|
44
|
+
images.to_a.find{ |i| i.id == image_id }.try(:src)
|
45
|
+
elsif is_a?(EPlat::Shopify::Product::Variant)
|
46
|
+
image&.src
|
44
47
|
end
|
45
48
|
end
|
46
49
|
|
data/lib/e_plat/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: e_plat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- oliwoodsuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|