e_plat 0.7.3 → 0.9.1
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/client.rb +1 -0
- data/lib/e_plat/resource/base.rb +13 -5
- 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/concerns/overwrite_request_methods.rb +10 -0
- data/lib/e_plat/resource/platform_specific/shopify_webhook/metafield.rb +4 -0
- data/lib/e_plat/resource/platform_specific/shopify_webhook/order/Consignment.rb +2 -0
- data/lib/e_plat/resource/platform_specific/shopify_webhook/order/billing_address.rb +2 -0
- data/lib/e_plat/resource/platform_specific/shopify_webhook/order/fulfillment.rb +2 -0
- data/lib/e_plat/resource/platform_specific/shopify_webhook/order/line_item.rb +2 -0
- data/lib/e_plat/resource/platform_specific/shopify_webhook/order/shipping_address.rb +2 -0
- data/lib/e_plat/resource/platform_specific/shopify_webhook/order/shipping_line.rb +2 -0
- data/lib/e_plat/resource/platform_specific/shopify_webhook/order.rb +6 -0
- data/lib/e_plat/resource/platform_specific/shopify_webhook/product/image.rb +7 -0
- data/lib/e_plat/resource/platform_specific/shopify_webhook/product/option.rb +9 -0
- data/lib/e_plat/resource/platform_specific/shopify_webhook/product/variant/option_value.rb +7 -0
- data/lib/e_plat/resource/platform_specific/shopify_webhook/product/variant.rb +9 -0
- data/lib/e_plat/resource/platform_specific/shopify_webhook/product.rb +14 -0
- data/lib/e_plat/resource/platform_specific/shopify_webhook/recurring_application_charge/usage_charge.rb +2 -0
- data/lib/e_plat/resource/platform_specific/shopify_webhook/recurring_application_charge.rb +6 -0
- data/lib/e_plat/resource/platform_specific/shopify_webhook/script_tag.rb +4 -0
- data/lib/e_plat/resource/platform_specific/shopify_webhook/shop.rb +4 -0
- data/lib/e_plat/resource/platform_specific/shopify_webhook/webhook.rb +4 -0
- data/lib/e_plat/resource/product/image.rb +1 -1
- data/lib/e_plat/resource/product/variant.rb +6 -2
- data/lib/e_plat/version.rb +1 -1
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd6ef96f210a4ce19e39876714cf947410ad47c6a93794c5f06aee1d8ec1f0f4
|
4
|
+
data.tar.gz: 6b83f5036d786165bfc0a36e3a651bea55679f1cf3c2c0672adc9b3b90ca26a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7dc8395400075cc15f5e2437257b7147ff6331dc92c78ea93377b70b85d7711d5ce0c6dd9f2557608b2425834a5d2f68881b8b62a132d1053bbfd6c102bac0ca
|
7
|
+
data.tar.gz: a5cbdad7ccfaad6d49d633225665ee920124ecf12f2a20a8533fb8244a93db0988a66a47f9e2bc081c279ee249e3e9b83caa449744cd9a2b20650027cf958534
|
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
|
|
data/lib/e_plat/client.rb
CHANGED
@@ -23,6 +23,7 @@ module EPlat
|
|
23
23
|
# needs to return nil if there isn't a more specific class than the klass passed in
|
24
24
|
def platform_klass(klass)
|
25
25
|
return if klass.to_s.include? "EPlat::#{platform.capitalize}"
|
26
|
+
|
26
27
|
platform_specific_class_name = klass.to_s.gsub("EPlat::", "EPlat::#{platform.capitalize}::")
|
27
28
|
|
28
29
|
platform_specific_class = platform_specific_class_name.safe_constantize
|
data/lib/e_plat/resource/base.rb
CHANGED
@@ -18,7 +18,7 @@ module EPlat
|
|
18
18
|
attr_accessor :read_only
|
19
19
|
|
20
20
|
threadsafe_attribute :_headers, :_connection, :_user, :_password, :_bearer_token, :_site, :_proxy, # active resource
|
21
|
-
:mapping, :include_root_in_json, :include_format_in_path # e_plat specific
|
21
|
+
:mapping, :include_root_in_json, :include_format_in_path, :mapping_class # e_plat specific
|
22
22
|
|
23
23
|
def inherited(subclass)
|
24
24
|
super
|
@@ -33,7 +33,7 @@ module EPlat
|
|
33
33
|
self.timeout = 5
|
34
34
|
self.include_format_in_path = client.include_format_in_path?
|
35
35
|
self.mapping = mapping_instance
|
36
|
-
|
36
|
+
|
37
37
|
client.platform_headers.each {|name, value| self.headers[name] = value}
|
38
38
|
end
|
39
39
|
|
@@ -71,12 +71,18 @@ module EPlat
|
|
71
71
|
def platform_specific_class?
|
72
72
|
self.class.to_s.include? client.platform.to_s.capitalize
|
73
73
|
end
|
74
|
+
|
75
|
+
def cached_shopify_webhook?
|
76
|
+
self.to_s.include?("EPlat::ShopifyWebhook")
|
77
|
+
end
|
78
|
+
|
74
79
|
|
75
80
|
private
|
76
81
|
|
77
82
|
def mapping_instance
|
78
|
-
|
79
|
-
|
83
|
+
api_version = (client.shopify? && self.to_s.include?("EPlat::ShopifyWebhook")) ? "2024_01" : client.api_version
|
84
|
+
mapping_class_name = "EPlat::Mapping::#{ client.platform.capitalize }::V#{ api_version.camelize }::#{ element_name.classify }"
|
85
|
+
|
80
86
|
EPlat::Mapping.new_instance(specifc_mapping: mapping_class_name, resource: nil)
|
81
87
|
end
|
82
88
|
|
@@ -164,7 +170,9 @@ module EPlat
|
|
164
170
|
|
165
171
|
def mapping_instance
|
166
172
|
class_constant_string = self.class.to_s.gsub("EPlat::", "")
|
167
|
-
|
173
|
+
class_constant_string.gsub!("ShopifyWebhook", "Shopify")
|
174
|
+
api_version = (client.shopify? && self.class.to_s.include?("EPlat::ShopifyWebhook")) ? "2024_01" : client.api_version
|
175
|
+
mapping_class_name = "EPlat::Mapping::#{ client.platform.capitalize }::V#{ api_version.camelize }::#{ class_constant_string }"
|
168
176
|
|
169
177
|
EPlat::Mapping.new_instance(specifc_mapping: mapping_class_name, resource: self)
|
170
178
|
end
|
@@ -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
|
@@ -9,6 +9,7 @@ module EPlat
|
|
9
9
|
module ClassMethods
|
10
10
|
def find(*arguments)
|
11
11
|
client = EPlat::Current.e_plat_session
|
12
|
+
cached_shopify_webhook_warning if cached_shopify_webhook?
|
12
13
|
|
13
14
|
if client.platform_klass(self) and not platform_specific_class?
|
14
15
|
client.platform_klass(self).find(*arguments)
|
@@ -54,6 +55,7 @@ module EPlat
|
|
54
55
|
|
55
56
|
def create(attributes = {})
|
56
57
|
client = EPlat::Current.e_plat_session
|
58
|
+
cached_shopify_webhook_warning if cached_shopify_webhook?
|
57
59
|
|
58
60
|
if client.platform_klass(self)
|
59
61
|
client.platform_klass(self).create(attributes)
|
@@ -66,6 +68,7 @@ module EPlat
|
|
66
68
|
|
67
69
|
def update(attributes = {})
|
68
70
|
client = EPlat::Current.e_plat_session
|
71
|
+
cached_shopify_webhook_warning if cached_shopify_webhook?
|
69
72
|
|
70
73
|
if client.platform_klass(self)
|
71
74
|
client.platform_klass(self).update(attributes)
|
@@ -79,6 +82,7 @@ module EPlat
|
|
79
82
|
|
80
83
|
def delete(id, options = {})
|
81
84
|
client = EPlat::Current.e_plat_session
|
85
|
+
cached_shopify_webhook_warning if cached_shopify_webhook?
|
82
86
|
|
83
87
|
if client.platform_klass(self)
|
84
88
|
client.platform_klass(self).delete(id, options)
|
@@ -90,6 +94,7 @@ module EPlat
|
|
90
94
|
|
91
95
|
def exists?(id, options = {})
|
92
96
|
client = EPlat::Current.e_plat_session
|
97
|
+
cached_shopify_webhook_warning if cached_shopify_webhook?
|
93
98
|
|
94
99
|
if client.platform_klass(self)
|
95
100
|
client.platform_klass(self).exists?(id, options)
|
@@ -109,6 +114,11 @@ module EPlat
|
|
109
114
|
class_constant_string = self.name.gsub("EPlat::", "")
|
110
115
|
"EPlat::Mapping::#{client.platform.capitalize}::V#{client.api_version.camelize}::#{class_constant_string}"
|
111
116
|
end
|
117
|
+
|
118
|
+
def cached_shopify_webhook_warning
|
119
|
+
warn "***EPlat Warning this is a cached webhook. request a live resource instead to request with***"
|
120
|
+
end
|
121
|
+
|
112
122
|
end
|
113
123
|
|
114
124
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
module EPlat::ShopifyWebhook
|
3
|
+
class Product < EPlat::Product
|
4
|
+
has_many :variants, class_name: "EPlat::ShopifyWebhook::Product::Variant"
|
5
|
+
has_many :images, class_name: "EPlat::ShopifyWebhook::Product::Image"
|
6
|
+
has_many :options, class_name: "EPlat::ShopifyWebhook::Product::Option"
|
7
|
+
|
8
|
+
def self.graphql_fields
|
9
|
+
warn "this is a cached webhook. request a live resource instead"
|
10
|
+
EPlat::Shopify::Product.graphql_fields
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -28,6 +28,8 @@ module EPlat
|
|
28
28
|
string :tax_code
|
29
29
|
boolean :requires_shipping
|
30
30
|
string :admin_graphql_api_id
|
31
|
+
array :option_values
|
32
|
+
# hash :image # default: {}, just for Shopify Webhooks
|
31
33
|
end
|
32
34
|
|
33
35
|
def save
|
@@ -35,10 +37,12 @@ module EPlat
|
|
35
37
|
super
|
36
38
|
end
|
37
39
|
|
38
|
-
def image_src
|
40
|
+
def image_src(images=[]) # EPlat::Product::Image => string
|
39
41
|
if client.bigcommerce?
|
40
42
|
image_url
|
41
|
-
elsif
|
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)
|
42
46
|
image&.src
|
43
47
|
end
|
44
48
|
end
|
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.1
|
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-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -382,6 +382,24 @@ files:
|
|
382
382
|
- lib/e_plat/resource/platform_specific/shopify/script_tag.rb
|
383
383
|
- lib/e_plat/resource/platform_specific/shopify/shop.rb
|
384
384
|
- lib/e_plat/resource/platform_specific/shopify/webhook.rb
|
385
|
+
- lib/e_plat/resource/platform_specific/shopify_webhook/metafield.rb
|
386
|
+
- lib/e_plat/resource/platform_specific/shopify_webhook/order.rb
|
387
|
+
- lib/e_plat/resource/platform_specific/shopify_webhook/order/Consignment.rb
|
388
|
+
- lib/e_plat/resource/platform_specific/shopify_webhook/order/billing_address.rb
|
389
|
+
- lib/e_plat/resource/platform_specific/shopify_webhook/order/fulfillment.rb
|
390
|
+
- lib/e_plat/resource/platform_specific/shopify_webhook/order/line_item.rb
|
391
|
+
- lib/e_plat/resource/platform_specific/shopify_webhook/order/shipping_address.rb
|
392
|
+
- lib/e_plat/resource/platform_specific/shopify_webhook/order/shipping_line.rb
|
393
|
+
- lib/e_plat/resource/platform_specific/shopify_webhook/product.rb
|
394
|
+
- lib/e_plat/resource/platform_specific/shopify_webhook/product/image.rb
|
395
|
+
- lib/e_plat/resource/platform_specific/shopify_webhook/product/option.rb
|
396
|
+
- lib/e_plat/resource/platform_specific/shopify_webhook/product/variant.rb
|
397
|
+
- lib/e_plat/resource/platform_specific/shopify_webhook/product/variant/option_value.rb
|
398
|
+
- lib/e_plat/resource/platform_specific/shopify_webhook/recurring_application_charge.rb
|
399
|
+
- lib/e_plat/resource/platform_specific/shopify_webhook/recurring_application_charge/usage_charge.rb
|
400
|
+
- lib/e_plat/resource/platform_specific/shopify_webhook/script_tag.rb
|
401
|
+
- lib/e_plat/resource/platform_specific/shopify_webhook/shop.rb
|
402
|
+
- lib/e_plat/resource/platform_specific/shopify_webhook/webhook.rb
|
385
403
|
- lib/e_plat/resource/product.rb
|
386
404
|
- lib/e_plat/resource/product/image.rb
|
387
405
|
- lib/e_plat/resource/product/option.rb
|