e_plat 0.7.2 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -1
  3. data/lib/e_plat/client.rb +1 -0
  4. data/lib/e_plat/resource/base.rb +15 -6
  5. data/lib/e_plat/resource/concerns/graph_q_lable.rb +1 -1
  6. data/lib/e_plat/resource/concerns/overwrite_instance_methods.rb +1 -1
  7. data/lib/e_plat/resource/concerns/overwrite_request_methods.rb +10 -0
  8. data/lib/e_plat/resource/platform_specific/shopify/product/variant.rb +1 -1
  9. data/lib/e_plat/resource/platform_specific/shopify_webhook/metafield.rb +4 -0
  10. data/lib/e_plat/resource/platform_specific/shopify_webhook/order/Consignment.rb +2 -0
  11. data/lib/e_plat/resource/platform_specific/shopify_webhook/order/billing_address.rb +2 -0
  12. data/lib/e_plat/resource/platform_specific/shopify_webhook/order/fulfillment.rb +2 -0
  13. data/lib/e_plat/resource/platform_specific/shopify_webhook/order/line_item.rb +2 -0
  14. data/lib/e_plat/resource/platform_specific/shopify_webhook/order/shipping_address.rb +2 -0
  15. data/lib/e_plat/resource/platform_specific/shopify_webhook/order/shipping_line.rb +2 -0
  16. data/lib/e_plat/resource/platform_specific/shopify_webhook/order.rb +6 -0
  17. data/lib/e_plat/resource/platform_specific/shopify_webhook/product/image.rb +7 -0
  18. data/lib/e_plat/resource/platform_specific/shopify_webhook/product/option.rb +9 -0
  19. data/lib/e_plat/resource/platform_specific/shopify_webhook/product/variant/option_value.rb +7 -0
  20. data/lib/e_plat/resource/platform_specific/shopify_webhook/product/variant.rb +9 -0
  21. data/lib/e_plat/resource/platform_specific/shopify_webhook/product.rb +14 -0
  22. data/lib/e_plat/resource/platform_specific/shopify_webhook/recurring_application_charge/usage_charge.rb +2 -0
  23. data/lib/e_plat/resource/platform_specific/shopify_webhook/recurring_application_charge.rb +6 -0
  24. data/lib/e_plat/resource/platform_specific/shopify_webhook/script_tag.rb +4 -0
  25. data/lib/e_plat/resource/platform_specific/shopify_webhook/shop.rb +4 -0
  26. data/lib/e_plat/resource/platform_specific/shopify_webhook/webhook.rb +4 -0
  27. data/lib/e_plat/resource/product/image.rb +1 -0
  28. data/lib/e_plat/resource/product/variant.rb +10 -0
  29. data/lib/e_plat/version.rb +1 -1
  30. metadata +20 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5af5d23022fca18e27cc070f5975bd15c7aba8f7df53b3a764c9c1ba0a285284
4
- data.tar.gz: c4b5f3ad678da9135a7f840028ede728ea16b0ee15f66d0d5edac60f5b805bf0
3
+ metadata.gz: d034aa67ea9c09ef394c0f55c26bb2d41032e7a8c8e958fe4fdc0d2bd24222b5
4
+ data.tar.gz: 3ba4c808ae422b28a12470957f87f88283985dbaf193767e9a3d7ae5a1f9c58c
5
5
  SHA512:
6
- metadata.gz: d0bdc8f94fb56bf2f7b36ea92cfbe3664caeb7ebd200d9d6215247f61b92b90f0f7e4a48b1aa860e4a8d6de35621f20621fe6ba2824389580bfb3109c15ab428
7
- data.tar.gz: 801cd77a5959527f12b62d24a104e829069049a1d66664db2fbe18aa04cb09944d9971dbe8f78496684409e20efc4d5e298b0b289ddcc2087f07443051558b7c
6
+ metadata.gz: 394fc11195351f359b3c001b11e0a7fcab32763e8c5fd24a2c0a1be811690a0d736f5393a09e1f9d566b8bbdb06553c9df699e75d08b6b15f4e0172af546d561
7
+ data.tar.gz: ee2c4ad95ec889f72f0653a8167787457529ef505fcfdf31c4287b9d478914659915633e50d80b979cc22e01d506e6a108e2567966db347c87646f36236e4739
data/README.md CHANGED
@@ -267,6 +267,10 @@ EPlat is designed to let you mostly use it's universal interface, but then easil
267
267
  | inventory_quantity | integer | getter only: node.inventoryQuantity | inventory_level | nil |
268
268
  | tax_code | string | * | nil | nil |
269
269
  | requires_shipping | boolean | InventoryItem[requiresShipping] | nil | nil |
270
+
271
+ helper methods: <br>
272
+ `image_src` => `String | nil`, platforms supported: Shopify, Bigcommerce
273
+
270
274
  *Bigcommerce variant.title= setter is not supported
271
275
 
272
276
 
@@ -290,7 +294,6 @@ EPlat is designed to let you mostly use it's universal interface, but then easil
290
294
  | width | integer | * | nil | nil |
291
295
  | height | integer | * | nil | nil |
292
296
  | src | string | * | url_standard | nil |
293
- | variant_ids | array | * | nil | nil |
294
297
 
295
298
 
296
299
  ### EPlat::Product::Variant::OptionValue
@@ -835,6 +838,7 @@ EPlat::Product.find(my_id).destroy
835
838
  product = EPlat::Product.new(title: 't-shirt')
836
839
  product.save # true or false
837
840
  product.errors # active record like errors if .save returned false
841
+ product.formatted_id #returns the resource ID in the platform's format. i.e. Shopify Product would be "gid://shopify/Product/xxx", Shopify Order would be 123, BC order: 123
838
842
 
839
843
  product.full_response # <Net::HTTPOK>
840
844
  product.headers # { "date"=>"Fri, 17 Nov 2023 14:25:53 GMT", ...}
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
@@ -8,6 +8,7 @@ module EPlat
8
8
 
9
9
  self.connection_class = EPlat::Connection
10
10
  self.collection_parser = EPlat::Collection
11
+ self.timeout = 10
11
12
  self.site = "/" # this is overwritten below in initialize_singleton! when EPlat::Session is initialized
12
13
  add_response_method :full_response #full response of the request
13
14
 
@@ -17,7 +18,7 @@ module EPlat
17
18
  attr_accessor :read_only
18
19
 
19
20
  threadsafe_attribute :_headers, :_connection, :_user, :_password, :_bearer_token, :_site, :_proxy, # active resource
20
- :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
21
22
 
22
23
  def inherited(subclass)
23
24
  super
@@ -32,7 +33,7 @@ module EPlat
32
33
  self.timeout = 5
33
34
  self.include_format_in_path = client.include_format_in_path?
34
35
  self.mapping = mapping_instance
35
-
36
+
36
37
  client.platform_headers.each {|name, value| self.headers[name] = value}
37
38
  end
38
39
 
@@ -70,12 +71,18 @@ module EPlat
70
71
  def platform_specific_class?
71
72
  self.class.to_s.include? client.platform.to_s.capitalize
72
73
  end
74
+
75
+ def cached_shopify_webhook?
76
+ self.to_s.include?("EPlat::ShopifyWebhook")
77
+ end
78
+
73
79
 
74
80
  private
75
81
 
76
82
  def mapping_instance
77
- mapping_class_name = "EPlat::Mapping::#{ client.platform.capitalize }::V#{ client.api_version.camelize }::#{ element_name.classify }"
78
-
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
+
79
86
  EPlat::Mapping.new_instance(specifc_mapping: mapping_class_name, resource: nil)
80
87
  end
81
88
 
@@ -129,7 +136,7 @@ module EPlat
129
136
  top_level_resource?
130
137
  end
131
138
 
132
- def formatted_id(id)
139
+ def formatted_id
133
140
  return id unless client.shopify? && client.api_version != "2024_01"
134
141
  return if id.to_s.include?("gid://")
135
142
 
@@ -163,7 +170,9 @@ module EPlat
163
170
 
164
171
  def mapping_instance
165
172
  class_constant_string = self.class.to_s.gsub("EPlat::", "")
166
- mapping_class_name = "EPlat::Mapping::#{ client.platform.capitalize }::V#{ client.api_version.camelize }::#{ class_constant_string }"
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 }"
167
176
 
168
177
  EPlat::Mapping.new_instance(specifc_mapping: mapping_class_name, resource: self)
169
178
  end
@@ -236,7 +236,7 @@ module EPlat
236
236
  additional_graphql = self.class.before_graphql_callbacks[action.to_sym]&.call(self)
237
237
  input =
238
238
  if action == :delete
239
- self.is_a?(EPlat::Product::Variant) ? graphql_input.new(id: formatted_id(id)) : graphql_input.new({id: formatted_id(id)})
239
+ self.is_a?(EPlat::Product::Variant) ? graphql_input.new(id: formatted_id) : graphql_input.new({id: formatted_id})
240
240
  else
241
241
  graphql_input.new mapping.via_native_attributes_where_possible(self.class.remove_root_from as_json)
242
242
  end
@@ -90,7 +90,7 @@ module EPlat
90
90
  def unrepresented_collection_ids(key, array_of_hashes)
91
91
  return [] unless client.can_update_nested_resources?
92
92
 
93
- all_instance_ids = send(key).map{|resource| resource.formatted_id resource.id} || []
93
+ all_instance_ids = send(key).map{|resource| resource.formatted_id} || []
94
94
  represented_instance_ids = array_of_hashes.map{|item| item["id"] }
95
95
 
96
96
  all_instance_ids.compact - represented_instance_ids.compact
@@ -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
 
@@ -29,7 +29,7 @@ class EPlat::Shopify::Product::Variant < EPlat::Product::Variant
29
29
  barcode
30
30
  weight
31
31
  image {
32
- id
32
+ #{ EPlat::Shopify::Product::Image.graphql_fields }
33
33
  }
34
34
  inventoryItem {
35
35
  id
@@ -0,0 +1,4 @@
1
+
2
+ module EPlat::ShopifyWebhook
3
+ class Metafield < EPlat::Metafield; end
4
+ end
@@ -0,0 +1,2 @@
1
+
2
+ class EPlat::ShopifyWebhook::Order::Consignment < EPlat::Order::Consignment; end
@@ -0,0 +1,2 @@
1
+
2
+ class EPlat::ShopifyWebhook::Order::BillingAddress < EPlat::Order::BillingAddress; end
@@ -0,0 +1,2 @@
1
+
2
+ class EPlat::ShopifyWebhook::Order::Fulfillment < EPlat::Order::Fulfillment; end
@@ -0,0 +1,2 @@
1
+
2
+ class EPlat::ShopifyWebhook::Order::LineItem < EPlat::Order::LineItem; end
@@ -0,0 +1,2 @@
1
+
2
+ class EPlat::ShopifyWebhook::Order::ShippingAddress < EPlat::Order::ShippingAddress; end
@@ -0,0 +1,2 @@
1
+
2
+ class EPlat::ShopifyWebhook::Order::ShippingLine < EPlat::Order::ShippingLine; end
@@ -0,0 +1,6 @@
1
+
2
+ module EPlat::ShopifyWebhook
3
+ class Order < EPlat::Order
4
+ has_many :line_items, class_name: "EPlat::ShopifyWebhook::Order::LineItem"
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+
2
+ class EPlat::ShopifyWebhook::Product::Image < EPlat::Product::Image
3
+ def self.graphql_fields
4
+ warn "this is a cached webhook. request a live resource instead"
5
+ EPlat::Shopify::Product::Image.graphql_fields
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+
2
+ class EPlat::ShopifyWebhook::Product::Option < EPlat::Product::Option
3
+
4
+ def self.graphql_fields
5
+ warn "this is a cached webhook. request a live resource instead"
6
+ EPlat::Shopify::Product::Option.graphql_fields
7
+ end
8
+
9
+ end
@@ -0,0 +1,7 @@
1
+
2
+ class EPlat::ShopifyWebhook::Product::Variant::OptionValue < EPlat::Product::Variant::OptionValue
3
+ def self.graphql_fields
4
+ warn "this is a cached webhook. request a live resource instead"
5
+ EPlat::Shopify::Product::Variant::OptionValue.graphql_fields
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+
2
+ class EPlat::ShopifyWebhook::Product::Variant < EPlat::Product::Variant
3
+
4
+ def self.graphql_fields
5
+ warn "this is a cached webhook. request a live resource instead"
6
+ EPlat::Shopify::Product::Variant.graphql_fields
7
+ end
8
+
9
+ end
@@ -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
@@ -0,0 +1,2 @@
1
+
2
+ class EPlat::ShopifyWebhook::RecurringApplicationCharge::UsageCharge < EPlat::RecurringApplicationCharge::UsageCharge; end
@@ -0,0 +1,6 @@
1
+
2
+ module EPlat::ShopifyWebhook
3
+ class RecurringApplicationCharge < EPlat::RecurringApplicationCharge
4
+ has_many :usage_charges, class_name: "EPlat::ShopifyWebhook::RecurringApplicationCharge::UsageCharge"
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+
2
+ module EPlat::ShopifyWebhook
3
+ class ScriptTag < EPlat::ScriptTag; end
4
+ end
@@ -0,0 +1,4 @@
1
+
2
+ module EPlat::ShopifyWebhook
3
+ class Shop < EPlat::Shop; end
4
+ end
@@ -0,0 +1,4 @@
1
+
2
+ module EPlat::ShopifyWebhook
3
+ class Webhook < EPlat::Webhook; end
4
+ end
@@ -9,6 +9,7 @@ module EPlat
9
9
 
10
10
  schema do
11
11
  integer :id
12
+ integer :product_id # nil-able because of Shopify GraphQL
12
13
  string :alt
13
14
  integer :width
14
15
  integer :height
@@ -28,12 +28,22 @@ module EPlat
28
28
  string :tax_code
29
29
  boolean :requires_shipping
30
30
  string :admin_graphql_api_id
31
+ hash :image # default: {}, just for Shopify Webhooks
31
32
  end
32
33
 
33
34
  def save
34
35
  prefix_options[:product] ||= try(:product)&.id
35
36
  super
36
37
  end
38
+
39
+ def image_src
40
+ if client.bigcommerce?
41
+ image_url
42
+ elsif client.shopify? && client.uses_graphql_for_products?
43
+ image.try(:src)
44
+ end
45
+ end
46
+
37
47
  end
38
48
  end
39
49
  end
@@ -1,3 +1,3 @@
1
1
  module EPlat
2
- VERSION = "0.7.2"
2
+ VERSION = "0.7.4"
3
3
  end
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.7.2
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - oliwoodsuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-30 00:00:00.000000000 Z
11
+ date: 2024-05-31 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