e_plat 0.5.5 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +109 -60
  3. data/lib/e_plat/client/default_request_args.rb +1 -1
  4. data/lib/e_plat/client.rb +55 -9
  5. data/lib/e_plat/initializer.rb +26 -0
  6. data/lib/e_plat/mapping/bigcommerce/v_3/product/option.rb +58 -0
  7. data/lib/e_plat/mapping/bigcommerce/v_3/product/variant/option_value.rb +42 -0
  8. data/lib/e_plat/mapping/shopify/v_2024_07/metafield.rb +26 -0
  9. data/lib/e_plat/mapping/shopify/v_2024_07/order/billing_address.rb +14 -0
  10. data/lib/e_plat/mapping/shopify/v_2024_07/order/shipping_address.rb +30 -0
  11. data/lib/e_plat/mapping/shopify/v_2024_07/order.rb +26 -0
  12. data/lib/e_plat/mapping/shopify/v_2024_07/product/image.rb +52 -0
  13. data/lib/e_plat/mapping/shopify/v_2024_07/product/option.rb +45 -0
  14. data/lib/e_plat/mapping/shopify/v_2024_07/product/variant/option_value.rb +58 -0
  15. data/lib/e_plat/mapping/shopify/v_2024_07/product/variant.rb +180 -0
  16. data/lib/e_plat/mapping/shopify/v_2024_07/product.rb +100 -0
  17. data/lib/e_plat/mapping/shopify/v_2024_07/script_tag.rb +26 -0
  18. data/lib/e_plat/mapping/shopify/v_2024_07/shop.rb +26 -0
  19. data/lib/e_plat/mapping/shopify/v_2024_07/webhook.rb +29 -0
  20. data/lib/e_plat/mapping/virtual_collection/shopify/product/variant/option_value.rb +272 -0
  21. data/lib/e_plat/mapping.rb +39 -15
  22. data/lib/e_plat/resource/base.rb +39 -5
  23. data/lib/e_plat/resource/collection.rb +45 -16
  24. data/lib/e_plat/resource/concerns/aliases.rb +39 -19
  25. data/lib/e_plat/resource/concerns/dirty.rb +12 -8
  26. data/lib/e_plat/resource/concerns/graph_q_lable.rb +253 -0
  27. data/lib/e_plat/resource/concerns/overwrite_instance_methods.rb +4 -4
  28. data/lib/e_plat/resource/concerns/overwrite_request_methods.rb +64 -21
  29. data/lib/e_plat/resource/countable.rb +37 -10
  30. data/lib/e_plat/resource/metafield.rb +2 -2
  31. data/lib/e_plat/resource/platform_specific/bigcommerce/metafield.rb +4 -0
  32. data/lib/e_plat/resource/platform_specific/bigcommerce/order/Consignment.rb +2 -0
  33. data/lib/e_plat/resource/platform_specific/bigcommerce/order/billing_address.rb +2 -0
  34. data/lib/e_plat/resource/platform_specific/bigcommerce/order/fulfillment.rb +2 -0
  35. data/lib/e_plat/resource/platform_specific/bigcommerce/order/line_item.rb +2 -0
  36. data/lib/e_plat/resource/platform_specific/bigcommerce/order/shipping_address.rb +2 -0
  37. data/lib/e_plat/resource/platform_specific/bigcommerce/order/shipping_line.rb +2 -0
  38. data/lib/e_plat/resource/platform_specific/bigcommerce/order.rb +4 -0
  39. data/lib/e_plat/resource/platform_specific/bigcommerce/product/image.rb +2 -0
  40. data/lib/e_plat/resource/platform_specific/bigcommerce/product/option.rb +2 -0
  41. data/lib/e_plat/resource/platform_specific/bigcommerce/product/variant/option_value.rb +2 -0
  42. data/lib/e_plat/resource/platform_specific/bigcommerce/product/variant.rb +2 -0
  43. data/lib/e_plat/resource/platform_specific/bigcommerce/product.rb +4 -0
  44. data/lib/e_plat/resource/platform_specific/bigcommerce/script_tag.rb +4 -0
  45. data/lib/e_plat/resource/platform_specific/bigcommerce/shop.rb +4 -0
  46. data/lib/e_plat/resource/platform_specific/bigcommerce/webhook.rb +4 -0
  47. data/lib/e_plat/resource/platform_specific/shopify/graph_q_l/v_2024_07/input/product/variant.rb +47 -0
  48. data/lib/e_plat/resource/platform_specific/shopify/graph_q_l/v_2024_07/input/product/variants_bulk.rb +47 -0
  49. data/lib/e_plat/resource/platform_specific/shopify/graph_q_l/v_2024_07/input/product.rb +23 -0
  50. data/lib/e_plat/resource/platform_specific/shopify/graph_q_l/v_2024_07/input.rb +98 -0
  51. data/lib/e_plat/resource/platform_specific/shopify/graph_q_l/v_2024_07/mutation/product/variant.rb +78 -0
  52. data/lib/e_plat/resource/platform_specific/shopify/graph_q_l/v_2024_07/mutation/product.rb +55 -0
  53. data/lib/e_plat/resource/platform_specific/shopify/graph_q_l/v_2024_07/mutation.rb +5 -0
  54. data/lib/e_plat/resource/platform_specific/shopify/graph_q_l/v_2024_07/query/product/variant.rb +44 -0
  55. data/lib/e_plat/resource/platform_specific/shopify/graph_q_l/v_2024_07/query/product.rb +58 -0
  56. data/lib/e_plat/resource/platform_specific/shopify/graph_q_l/v_2024_07/query.rb +5 -0
  57. data/lib/e_plat/resource/platform_specific/shopify/metafield.rb +4 -0
  58. data/lib/e_plat/resource/platform_specific/shopify/order/Consignment.rb +2 -0
  59. data/lib/e_plat/resource/platform_specific/shopify/order/billing_address.rb +2 -0
  60. data/lib/e_plat/resource/platform_specific/shopify/order/fulfillment.rb +2 -0
  61. data/lib/e_plat/resource/platform_specific/shopify/order/line_item.rb +2 -0
  62. data/lib/e_plat/resource/platform_specific/shopify/order/shipping_address.rb +2 -0
  63. data/lib/e_plat/resource/platform_specific/shopify/order/shipping_line.rb +2 -0
  64. data/lib/e_plat/resource/platform_specific/shopify/order.rb +4 -0
  65. data/lib/e_plat/resource/platform_specific/shopify/product/image.rb +14 -0
  66. data/lib/e_plat/resource/platform_specific/shopify/product/option.rb +14 -0
  67. data/lib/e_plat/resource/platform_specific/shopify/product/variant/option_value.rb +14 -0
  68. data/lib/e_plat/resource/platform_specific/shopify/product/variant.rb +66 -0
  69. data/lib/e_plat/resource/platform_specific/shopify/product.rb +79 -0
  70. data/lib/e_plat/resource/platform_specific/shopify/recurring_application_charge/usage_charge.rb +2 -0
  71. data/lib/e_plat/resource/platform_specific/shopify/recurring_application_charge.rb +4 -0
  72. data/lib/e_plat/resource/platform_specific/shopify/script_tag.rb +4 -0
  73. data/lib/e_plat/resource/platform_specific/shopify/shop.rb +4 -0
  74. data/lib/e_plat/resource/platform_specific/shopify/webhook.rb +4 -0
  75. data/lib/e_plat/resource/product/image.rb +8 -5
  76. data/lib/e_plat/resource/product/option.rb +2 -3
  77. data/lib/e_plat/resource/product/variant/option_value.rb +17 -0
  78. data/lib/e_plat/resource/product/variant.rb +6 -14
  79. data/lib/e_plat/resource/product.rb +23 -11
  80. data/lib/e_plat/session.rb +3 -2
  81. data/lib/e_plat/type_coercer.rb +4 -2
  82. data/lib/e_plat/version.rb +1 -1
  83. data/lib/e_plat.rb +33 -4
  84. data/lib/hash.rb +39 -0
  85. metadata +163 -27
@@ -0,0 +1,52 @@
1
+
2
+
3
+ module EPlat
4
+ class Mapping
5
+ module Shopify
6
+ module V202407
7
+ class Product
8
+ class Image < EPlat::Mapping::Base
9
+
10
+ def native_top_key
11
+ :itself
12
+ end
13
+
14
+ def native_attributes
15
+ super.concat([
16
+ "id",
17
+ "alt_text", #would be altText before and after EPlat processes it
18
+ "width",
19
+ "height",
20
+ "url"
21
+ ])
22
+ end
23
+
24
+ def native_attribute_aliases
25
+ super.concat([
26
+ {
27
+ existing_entry: {native_key: "id", e_plat_key: "id",
28
+ custom_e_plat_getter: '-> { _1.try(:split, "/")&.last || _1 }',
29
+ custom_native_setter: '-> { "gid://shopify/ProductImage/#{_1}" }'
30
+ }
31
+ },
32
+ {
33
+ alias_attribute: {native_key: "alt_text", e_plat_key: "alt"}
34
+ },
35
+ {
36
+ existing_entry: {native_key: "width", e_plat_key: "width"}
37
+ },
38
+ {
39
+ existing_entry: {native_key: "height", e_plat_key: "height"}
40
+ },
41
+ {
42
+ alias_attribute: {native_key: "url", e_plat_key: "src"}
43
+ }
44
+ ])
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,45 @@
1
+
2
+
3
+ module EPlat
4
+ class Mapping
5
+ module Shopify
6
+ module V202407
7
+ class Product
8
+ class Option < EPlat::Mapping::Base
9
+ include_root_in_request_body true
10
+
11
+ def native_top_key
12
+ :itself
13
+ end
14
+
15
+ def native_attributes
16
+ super
17
+ end
18
+
19
+ def native_attribute_aliases
20
+ super.concat([
21
+
22
+ {
23
+ existing_entry: {native_key: "id", e_plat_key: "id",
24
+ custom_e_plat_getter: '-> { _1&.split("/")&.last }',
25
+ custom_native_setter: '-> { "gid://shopify/ProductOption/#{_1}" }'
26
+ }
27
+ },
28
+ {
29
+ existing_entry: {native_key: "name", e_plat_key: "name"}
30
+ },
31
+ {
32
+ existing_entry: {native_key: "position", e_plat_key: "position"}
33
+ },
34
+ {
35
+ existing_entry: {native_key: "values", e_plat_key: "values"}
36
+ }
37
+ ])
38
+ end
39
+
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,58 @@
1
+
2
+
3
+ module EPlat
4
+ class Mapping
5
+ module Shopify
6
+ module V202407
7
+ class Product::Variant
8
+ class OptionValue < EPlat::Mapping::Base
9
+ include_root_in_request_body true
10
+
11
+ def native_top_key
12
+ :itself
13
+ end
14
+
15
+ def native_attributes
16
+ super.concat([
17
+ ])
18
+ end
19
+
20
+
21
+ def native_attribute_aliases
22
+ super.concat([
23
+ # see virtual_collection @ EPlat::Mapping::VirtualCollection::Shopify::Product::Variant::OptionValue
24
+ ])
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+
35
+ # bigcommerce
36
+ # option_values => [{
37
+ # "id": 174,
38
+ # "label": "Beige",
39
+ # "option_id": 220,
40
+ # "option_display_name": "Color"
41
+ # }]
42
+
43
+ # shopify
44
+ # selected_options => [{
45
+ # "name"=>"Size",
46
+ # "value"=>"green",
47
+ # "option_value" => {
48
+ # "id"=>"gid://shopify/ProductOptionValue/657155129475",
49
+ # "name"=>"green"
50
+ # }
51
+ # }]
52
+
53
+ # target e_plat schema
54
+ # option_values => [{
55
+ # "id": 174,
56
+ # "name": "Color",
57
+ # "value": "Beige",
58
+ # }]
@@ -0,0 +1,180 @@
1
+
2
+
3
+ module EPlat
4
+ class Mapping
5
+ module Shopify
6
+ module V202407
7
+ class Product
8
+ class Variant < EPlat::Mapping::Base
9
+ include_root_in_request_body true
10
+ virtual_collection :option_values, class: EPlat::Mapping::VirtualCollection::Shopify::Product::Variant::OptionValue, map_from: "selected_options"
11
+
12
+ def native_top_key
13
+ :itself
14
+ end
15
+
16
+ def native_attributes
17
+ super
18
+ end
19
+
20
+ def native_attribute_aliases
21
+ super.concat([
22
+ {
23
+ existing_entry: {native_key: "id", e_plat_key: "id",
24
+ custom_e_plat_getter: '-> { (_1.is_a? Integer) ? _1 : _1&.split("/")&.last }',
25
+ custom_native_setter: '-> { (_1.is_a? String) ? _1 : "gid://shopify/ProductVariant/#{_1}" }'
26
+ }
27
+ },
28
+ {
29
+ existing_entry: {native_key: "title", e_plat_key: "title"}
30
+ },
31
+ {
32
+ existing_entry: {native_key: "price", e_plat_key: "price"}
33
+ },
34
+ {
35
+ existing_entry: {native_key: "sku", e_plat_key: "sku",
36
+ custom_e_plat_getter: '-> { _1 }',
37
+ custom_native_setter: '-> do
38
+ inventory_item.sku = _1;
39
+ inventory_item.attribute_will_change!("sku");
40
+ _1
41
+ end'
42
+ }
43
+ },
44
+ {
45
+ existing_entry: {native_key: "position", e_plat_key: "position"}
46
+ },
47
+ {
48
+ existing_entry: {native_key: "inventory_policy", e_plat_key: "inventory_policy",
49
+ custom_e_plat_getter: '-> { _1&.downcase }',
50
+ custom_native_setter: '-> { _1&.upcase }'
51
+ }
52
+ },
53
+ {
54
+ existing_entry: {native_key: "compare_at_price", e_plat_key: "compare_at_price"}
55
+ },
56
+ {
57
+ alias_attribute: {native_key: "inventory_item[tracked]", e_plat_key: "inventory_management"}
58
+ },
59
+ {
60
+
61
+ existing_entry: {native_key: "created_at", e_plat_key: "created_at"}
62
+ },
63
+ {
64
+ existing_entry: {native_key: "updated_at", e_plat_key: "updated_at"}
65
+ },
66
+ {
67
+ existing_entry: {native_key: "taxable", e_plat_key: "taxable"}
68
+ },
69
+ {
70
+ existing_entry: {native_key: "barcode", e_plat_key: "barcode"}
71
+ },
72
+ {
73
+ alias_attribute: {native_key: "inventory_item[measurement][weight][unit]", e_plat_key: "weight_unit",
74
+ custom_native_setter: '-> { warn("Setting weight_unit directly is not supported on ProductVariant via GraphQL."); _1 }'
75
+ }
76
+ },
77
+ {
78
+ alias_attribute: {native_key: "inventory_item[measurement][weight][value]", e_plat_key: "weight",
79
+ custom_native_setter: '-> { warn("Setting weight directly is not supported on ProductVariant via GraphQL."); _1 }'
80
+ }
81
+ },
82
+ {
83
+ alias_attribute: {native_key: "inventory_item[id]", e_plat_key: "inventory_item_id",
84
+ custom_e_plat_getter: '-> { _1&.split("/")&.last }',
85
+ custom_native_setter: '-> { "gid://shopify/InventoryItem/#{_1}" }'
86
+ }
87
+ },
88
+ {
89
+ existing_entry: {native_key: "inventory_quantity", e_plat_key: "inventory_quantity",
90
+ custom_native_setter: '-> { warn("Setting inventory_quantity directly is not supported on ProductVariant via GraphQL."); _1 }'
91
+ }
92
+ },
93
+ {
94
+ existing_entry: {native_key: "tax_code", e_plat_key: "tax_code"}
95
+ },
96
+ {
97
+ alias_attribute: {native_key: "inventory_item[requires_shipping]", e_plat_key: "requires_shipping",
98
+ custom_native_setter: '-> { warn("Setting requires_shipping directly is not supported on ProductVariant via GraphQL."); _1 }'
99
+ }
100
+ },
101
+ {
102
+ existing_entry: {native_key: "fulfillment_service", e_plat_key: "fulfillment_service"}
103
+ },
104
+ {
105
+ existing_entry: {native_key: "grams", e_plat_key: "grams", # doesnt exist on any current API but we create it
106
+ custom_e_plat_getter: '-> {
107
+ _1
108
+ case weight_unit
109
+ when "GRAMS", "grams", "g"
110
+ weight
111
+ when "KILOGRAMS", "kilograms", "kg"
112
+ weight * 1000
113
+ when "OUNCES", "ounces", "oz"
114
+ weight * 28.3495
115
+ when "POUNDS", "pounds", "lb"
116
+ weight * 453.592
117
+ else
118
+ weight
119
+ end
120
+ }',
121
+ custom_native_setter: '-> {
122
+ warn("Setting grams directly is not supported on ProductVariant via GraphQL. Mutate the inventoryItem.measurement.weight object `value` field instead")
123
+ case weight_unit
124
+ when "GRAMS", "grams", "g"
125
+ _1
126
+ when "KILOGRAMS", "kilograms", "kg"
127
+ _1 / 1000
128
+ when "OUNCES", "ounces", "oz"
129
+ _1 / 28.3495
130
+ when "POUNDS", "pounds", "lb"
131
+ _1 / 453.592
132
+ else
133
+ _1
134
+ end
135
+ }'
136
+ }
137
+ }
138
+
139
+ ])
140
+ end
141
+
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
148
+
149
+ # RESOURCE
150
+ # integer :id
151
+ # integer :product_id
152
+ # string :title
153
+ # string :price
154
+ # string :sku
155
+ # integer :position
156
+ # string :inventory_policy
157
+ # string :compare_at_price
158
+ # string :fulfillment_service
159
+ # string :inventory_management
160
+ # datetime :created_at
161
+ # datetime :updated_at
162
+ # boolean :taxable
163
+ # string :barcode
164
+ # integer :grams
165
+ # integer :image_id
166
+ # float :weight
167
+ # string :weight_unit
168
+ # integer :inventory_item_id
169
+ # integer :inventory_quantity
170
+ # string :tax_code
171
+ # boolean :requires_shipping
172
+ # string :admin_graphql_api_id
173
+
174
+
175
+ # fields without setter support
176
+ # | grams | integer | getter only: converted node.inventoryItem[measurement][weight][value] | nil | nil |
177
+ # | weight | float | getter only: node.inventoryItem[measurement][weight][value] | weight |
178
+ # | weight_unit | string | getter only: node.inventoryItem[measurement][weight][unit] | nil |
179
+ # | inventory_item_id | integer | getter only: node.inventoryItem[id]| nil | nil |
180
+ # | inventory_quantity | integer | getter only: node.inventoryQuantity | inventory_level
@@ -0,0 +1,100 @@
1
+ module EPlat
2
+ class Mapping
3
+ module Shopify
4
+ module V202407 #< :module
5
+ class Product < EPlat::Mapping::Base
6
+
7
+ def native_top_key
8
+ "product"
9
+ end
10
+
11
+ def native_attributes
12
+ super.concat([
13
+ "id",
14
+ "descriptionHtml",
15
+ "createdAt",
16
+ "updatedAt",
17
+ "handle",
18
+ "productType",
19
+ "publishedAt",
20
+ "publishedScope",
21
+ "status",
22
+ "tags",
23
+ "templateSuffix",
24
+ "title",
25
+ "vendor"
26
+ ])
27
+ end
28
+
29
+ def native_attribute_aliases
30
+ super.concat([
31
+ {
32
+ alias_attribute: {native_key: "description_html", e_plat_key: "body_html"}
33
+ },
34
+ {
35
+ existing_entry: {native_key: "created_at", e_plat_key: "created_at"}
36
+ },
37
+ {
38
+ existing_entry: {native_key: "updated_at", e_plat_key: "updated_at"}
39
+ },
40
+ {
41
+ existing_entry: {native_key: "handle", e_plat_key: "handle"}
42
+ },
43
+ {
44
+ existing_entry: {native_key: "product_type", e_plat_key: "product_type"}
45
+ },
46
+ {
47
+ existing_entry: {native_key: "published_at", e_plat_key: "published_at"}
48
+ },
49
+ {
50
+ existing_entry: {native_key: "status", e_plat_key: "status",
51
+ custom_e_plat_getter: '-> { _1&.downcase }',
52
+ custom_native_setter: '-> { _1&.upcase }'
53
+ }
54
+ },
55
+ {
56
+ existing_entry: {native_key: "tags", e_plat_key: "tags",
57
+ custom_e_plat_getter: "-> { _1&.join(',') }",
58
+ custom_native_setter: "-> { _1&.split(',') }"
59
+ }
60
+ },
61
+ {
62
+ existing_entry: {native_key: "id", e_plat_key: "id",
63
+ custom_e_plat_getter: '-> { (_1.is_a? Integer) ? _1 : _1&.split("/")&.last }',
64
+ custom_native_setter: '-> { (_1.is_a? String) ? _1 : "gid://shopify/Product/#{_1}" }'
65
+ }
66
+ },
67
+ {
68
+ existing_entry: {native_key: "template_suffix", e_plat_key: "template_suffix"}
69
+ },
70
+ {
71
+ existing_entry: {native_key: "title", e_plat_key: "title"}
72
+ },
73
+ {
74
+ existing_entry: {native_key: "vendor", e_plat_key: "vendor"}
75
+ }
76
+ ])
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+
85
+ # string :body_html
86
+ # datetime :created_at
87
+ # string :handle
88
+ # integer :id
89
+ # array :images
90
+ # array :options
91
+ # string :product_type
92
+ # datetime :published_at
93
+ # string :status
94
+ # string :tags
95
+ # string :admin_graphql_api_id
96
+ # string :template_suffix
97
+ # string :title
98
+ # datetime :updated_at
99
+ # array :variants
100
+ # string :vendor
@@ -0,0 +1,26 @@
1
+ module EPlat
2
+ class Mapping
3
+ module Shopify
4
+ module V202407 #< :module
5
+ class ScriptTag < EPlat::Mapping::Base
6
+
7
+ def native_top_key
8
+ "script_tag"
9
+ end
10
+
11
+ def native_attributes
12
+ super.concat([
13
+ ])
14
+ end
15
+
16
+ def native_attribute_aliases
17
+ super.concat([
18
+ ])
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+
@@ -0,0 +1,26 @@
1
+ module EPlat
2
+ class Mapping
3
+ module Shopify
4
+ module V202407 #< :module
5
+ class Shop < EPlat::Mapping::Base
6
+
7
+ def native_top_key
8
+ "shop"
9
+ end
10
+
11
+ def native_attributes
12
+ super.concat([
13
+ ])
14
+ end
15
+
16
+ def native_attribute_aliases
17
+ super.concat([
18
+ ])
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+
@@ -0,0 +1,29 @@
1
+ module EPlat
2
+ class Mapping
3
+ module Shopify
4
+ module V202407 #< :module
5
+ class Webhook < EPlat::Mapping::Base
6
+ DEFAULT_VALUES = {
7
+ format: "json"
8
+ }
9
+
10
+ def native_top_key
11
+ "webhook"
12
+ end
13
+
14
+ def native_attributes
15
+ super.concat([
16
+ ])
17
+ end
18
+
19
+ def native_attribute_aliases
20
+ super.concat([
21
+ ])
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+