e_plat 0.2.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +633 -135
- data/lib/active_resource/connection_error.rb +29 -0
- data/lib/active_resource/formats.rb +27 -0
- data/lib/current.rb +7 -0
- data/lib/e_plat/client/default_request_args.rb +27 -3
- data/lib/e_plat/client.rb +114 -87
- data/lib/e_plat/connection.rb +4 -0
- data/lib/e_plat/errors/missing_session_error.rb +1 -1
- data/lib/e_plat/mapping/base.rb +119 -12
- data/lib/e_plat/mapping/bigcommerce/v_3/metafield.rb +62 -0
- data/lib/e_plat/mapping/bigcommerce/v_3/order/billing_address.rb +14 -0
- data/lib/e_plat/mapping/bigcommerce/v_3/order/line_item.rb +85 -0
- data/lib/e_plat/mapping/bigcommerce/v_3/order/shipping_address.rb +73 -0
- data/lib/e_plat/mapping/bigcommerce/v_3/order.rb +160 -0
- data/lib/e_plat/mapping/bigcommerce/v_3/product/image.rb +12 -12
- data/lib/e_plat/mapping/bigcommerce/v_3/product/variant.rb +1 -1
- data/lib/e_plat/mapping/bigcommerce/v_3/script_tag.rb +78 -0
- data/lib/e_plat/mapping/bigcommerce/v_3/shop.rb +11 -6
- data/lib/e_plat/mapping/bigcommerce/v_3/webhook.rb +54 -0
- data/lib/e_plat/mapping/request_body_root.rb +38 -0
- data/lib/e_plat/mapping/shopify/v_2024_01/metafield.rb +26 -0
- data/lib/e_plat/mapping/shopify/v_2024_01/order/billing_address.rb +14 -0
- data/lib/e_plat/mapping/shopify/v_2024_01/order/shipping_address.rb +30 -0
- data/lib/e_plat/mapping/shopify/{v_2022_07/product.rb → v_2024_01/order.rb} +3 -3
- data/lib/e_plat/mapping/shopify/{v_2022_07 → v_2024_01}/product/image.rb +1 -1
- data/lib/e_plat/mapping/shopify/{v_2022_07 → v_2024_01}/product/variant.rb +2 -1
- data/lib/e_plat/mapping/shopify/v_2024_01/product.rb +26 -0
- data/lib/e_plat/mapping/shopify/v_2024_01/script_tag.rb +26 -0
- data/lib/e_plat/mapping/shopify/{v_2022_07 → v_2024_01}/shop.rb +1 -1
- data/lib/e_plat/mapping/shopify/v_2024_01/webhook.rb +29 -0
- data/lib/e_plat/mapping/virtual_collection/base.rb +14 -0
- data/lib/e_plat/mapping/virtual_collection/bigcommerce/order_line_items.rb +297 -0
- data/lib/e_plat/mapping.rb +3 -3
- data/lib/e_plat/resource/attribute_interface.rb +28 -28
- data/lib/e_plat/resource/base.rb +107 -68
- data/lib/e_plat/resource/collection.rb +92 -0
- data/lib/e_plat/resource/concerns/aliases.rb +102 -18
- data/lib/e_plat/resource/concerns/dirty.rb +54 -0
- data/lib/e_plat/resource/concerns/metafieldable.rb +43 -0
- data/lib/e_plat/resource/concerns/overwrite_instance_methods.rb +108 -6
- data/lib/e_plat/resource/concerns/overwrite_request_methods.rb +73 -37
- data/lib/e_plat/resource/countable.rb +43 -0
- data/lib/e_plat/resource/metafield.rb +70 -0
- data/lib/e_plat/resource/order/Consignment.rb +8 -0
- data/lib/e_plat/resource/order/billing_address.rb +6 -0
- data/lib/e_plat/resource/order/fulfillment.rb +1 -0
- data/lib/e_plat/resource/order/line_item.rb +1 -0
- data/lib/e_plat/resource/order/shipping_address.rb +44 -0
- data/lib/e_plat/resource/order/shipping_line.rb +15 -14
- data/lib/e_plat/resource/order.rb +32 -0
- data/lib/e_plat/resource/paginated/link_headers.rb +42 -0
- data/lib/e_plat/resource/paginated/link_params.rb +26 -0
- data/lib/e_plat/resource/product/image.rb +6 -0
- data/lib/e_plat/resource/product/option.rb +1 -0
- data/lib/e_plat/resource/product/variant.rb +8 -12
- data/lib/e_plat/resource/product.rb +8 -2
- data/lib/e_plat/resource/script_tag.rb +56 -0
- data/lib/e_plat/resource/shop.rb +17 -13
- data/lib/e_plat/resource/shopify_only/recurring_application_charge/usage_charge.rb +32 -0
- data/lib/e_plat/resource/shopify_only/recurring_application_charge.rb +47 -0
- data/lib/e_plat/resource/webhook.rb +50 -0
- data/lib/e_plat/session.rb +14 -14
- data/lib/e_plat/type_coercer.rb +15 -17
- data/lib/e_plat/types.rb +1 -1
- data/lib/e_plat/version.rb +1 -1
- data/lib/e_plat.rb +4 -4
- metadata +51 -19
- data/lib/e_plat/resource/order/customer.rb +0 -37
- data/lib/e_plat/session_state.rb +0 -25
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
module ActiveResource
|
3
|
+
class ConnectionError
|
4
|
+
|
5
|
+
def to_s
|
6
|
+
super << " - #{body_message}"
|
7
|
+
rescue
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def body_message
|
14
|
+
return '' unless response&.body
|
15
|
+
body = JSON.parse(response.body)
|
16
|
+
|
17
|
+
case body
|
18
|
+
when Hash
|
19
|
+
body['message'] || body['error'] || body.inspect
|
20
|
+
when Array
|
21
|
+
body.first['message']
|
22
|
+
else
|
23
|
+
''
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveResource
|
4
|
+
module Formats
|
5
|
+
autoload :XmlFormat, "active_resource/formats/xml_format"
|
6
|
+
autoload :JsonFormat, "active_resource/formats/json_format"
|
7
|
+
|
8
|
+
# Lookup the format class from a mime type reference symbol. Example:
|
9
|
+
#
|
10
|
+
# ActiveResource::Formats[:xml] # => ActiveResource::Formats::XmlFormat
|
11
|
+
# ActiveResource::Formats[:json] # => ActiveResource::Formats::JsonFormat
|
12
|
+
def self.[](mime_type_reference)
|
13
|
+
ActiveResource::Formats.const_get(ActiveSupport::Inflector.camelize(mime_type_reference.to_s) + "Format")
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.remove_root(data)
|
17
|
+
if data.is_a?(Hash) && data.keys.size <= 2 && data.values.first.is_a?(Enumerable) #bigcommerce returns {data:{}, meta:{}}, so we need to increase keys.size check to 2
|
18
|
+
data.values.first
|
19
|
+
else
|
20
|
+
data
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
data/lib/current.rb
ADDED
@@ -4,20 +4,44 @@ module EPlat
|
|
4
4
|
module DefaultRequestArgs
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
|
-
def
|
7
|
+
def product_default_request_args
|
8
8
|
case platform
|
9
9
|
when :shopify
|
10
10
|
{}
|
11
11
|
when :bigcommerce
|
12
12
|
{
|
13
|
-
"include" =>
|
13
|
+
"include" => "variants,images"
|
14
14
|
}
|
15
15
|
when :woocommerce
|
16
16
|
{}
|
17
17
|
end
|
18
18
|
end
|
19
|
+
|
20
|
+
def variant_default_request_args
|
21
|
+
case platform
|
22
|
+
when :shopify
|
23
|
+
{}
|
24
|
+
when :bigcommerce
|
25
|
+
{}
|
26
|
+
when :woocommerce
|
27
|
+
{}
|
28
|
+
end
|
29
|
+
end
|
19
30
|
|
20
|
-
def
|
31
|
+
def order_default_request_args
|
32
|
+
case platform
|
33
|
+
when :shopify
|
34
|
+
{}
|
35
|
+
when :bigcommerce
|
36
|
+
{
|
37
|
+
"include" => "consignments.line_items"
|
38
|
+
}
|
39
|
+
when :woocommerce
|
40
|
+
{}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def metafield_default_request_args
|
21
45
|
case platform
|
22
46
|
when :shopify
|
23
47
|
{}
|
data/lib/e_plat/client.rb
CHANGED
@@ -1,95 +1,122 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module EPlat
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
attr_accessor :platform, :store_url, :api_token, :api_version, :store_hash
|
4
|
+
class Client
|
5
|
+
include Client::PlatformConvenienceMethods, Client::DefaultRequestArgs
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
SHOPIFY_PAGINATION_PARAM = "page_info"
|
8
|
+
BIGCOMMERCE_PAGINATION_PARAM = "page"
|
9
|
+
|
10
|
+
attr_reader :platform, :store_url, :api_token, :api_version, :store_hash
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
def inspect
|
19
|
-
"#<#{self.class} platform=#{platform.inspect} store_url=#{store_url.inspect} api_version=#{api_version.inspect}>"
|
20
|
-
end
|
21
|
-
|
22
|
-
def inactive?
|
23
|
-
!valid?
|
24
|
-
end
|
25
|
-
|
26
|
-
def active?
|
27
|
-
valid?
|
28
|
-
end
|
12
|
+
def initialize(platform: nil, store_url: nil, api_token: nil, store_hash: nil)
|
13
|
+
@platform, @store_url, @api_token, @store_hash = platform&.to_sym, store_url, api_token, store_hash
|
14
|
+
end
|
29
15
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
def base_url
|
39
|
-
case platform
|
40
|
-
when :shopify
|
41
|
-
"https://#{ store_url }"
|
42
|
-
when :bigcommerce
|
43
|
-
"https://api.bigcommerce.com"
|
44
|
-
when :woocommerce
|
45
|
-
"/"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def url_prefix
|
50
|
-
case platform
|
51
|
-
when :shopify
|
52
|
-
"/admin/api/#{ api_version.dasherize }/"
|
53
|
-
when :bigcommerce
|
54
|
-
"/stores/#{ store_hash }/v#{ api_version }/catalog/"
|
55
|
-
when :woocommerce
|
56
|
-
"/"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def platform_headers
|
61
|
-
case platform
|
62
|
-
when :shopify
|
63
|
-
{
|
64
|
-
"Content-Type" => "application/json",
|
65
|
-
"X-Shopify-Access-Token" => api_token
|
66
|
-
}
|
67
|
-
when :bigcommerce
|
68
|
-
{
|
69
|
-
"Content-Type" => "application/json",
|
70
|
-
"X-Auth-Token" => api_token,
|
71
|
-
"host" => "api.bigcommerce.com"
|
72
|
-
}
|
73
|
-
when :woocommerce
|
74
|
-
{
|
75
|
-
"Content-Type" => "application/json",
|
76
|
-
"Authorization" => "Bearer #{ api_token }"
|
77
|
-
}
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def get_api_version
|
82
|
-
self.api_version =
|
83
|
-
case platform
|
84
|
-
when :shopify
|
85
|
-
EPlat.config.shopify_api_version
|
86
|
-
when :bigcommerce
|
87
|
-
EPlat.config.bigcommerce_api_version
|
88
|
-
when :woocommerce
|
89
|
-
EPlat.config.woocommerce_api_version
|
90
|
-
end
|
91
|
-
end
|
16
|
+
def headers
|
17
|
+
platform_headers
|
18
|
+
end
|
19
|
+
|
20
|
+
def inspect
|
21
|
+
"#<#{self.class} platform=#{platform.inspect} store_url=#{store_url.inspect} api_version=#{api_version.inspect}>"
|
22
|
+
end
|
92
23
|
|
93
|
-
|
94
|
-
|
24
|
+
def valid?
|
25
|
+
platform.present? && store_url.present? && api_token.present?
|
26
|
+
end
|
27
|
+
|
28
|
+
def clear!
|
29
|
+
self.platform = nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def base_url
|
33
|
+
case platform
|
34
|
+
when :shopify
|
35
|
+
"https://#{ store_url }"
|
36
|
+
when :bigcommerce
|
37
|
+
"https://api.bigcommerce.com"
|
38
|
+
when :woocommerce
|
39
|
+
"/"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def url_prefix(klass: nil)
|
44
|
+
# for nested resources like "/products/:product/variants/:id"
|
45
|
+
collection_path =
|
46
|
+
if klass.to_s.scan("::").length == 2
|
47
|
+
parent_klass = klass.to_s.split("::")[1].underscore
|
48
|
+
"#{ parent_klass.pluralize }/:#{ parent_klass }/"
|
49
|
+
else
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
|
53
|
+
return "/stores/#{ store_hash }/v2/#{ collection_path }" if bigcommerce? && klass == EPlat::Order
|
54
|
+
return "/stores/#{ store_hash }/v3/content/" if bigcommerce? && klass == EPlat::ScriptTag
|
55
|
+
return "/stores/#{ store_hash }/v3/" if bigcommerce? && klass == EPlat::Webhook
|
56
|
+
|
57
|
+
case platform
|
58
|
+
when :shopify
|
59
|
+
"/admin/api/#{ api_version.dasherize }/#{ collection_path }"
|
60
|
+
when :bigcommerce
|
61
|
+
"/stores/#{ store_hash }/v#{ api_version }/catalog/#{ collection_path }"
|
62
|
+
when :woocommerce
|
63
|
+
"/" # not yet supported
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def platform_headers
|
68
|
+
case platform
|
69
|
+
when :shopify
|
70
|
+
{
|
71
|
+
"Content-Type" => "application/json",
|
72
|
+
"X-Shopify-Access-Token" => api_token
|
73
|
+
}
|
74
|
+
when :bigcommerce
|
75
|
+
{
|
76
|
+
"Content-Type" => "application/json",
|
77
|
+
"Accept" => "application/json",
|
78
|
+
"X-Auth-Token" => api_token,
|
79
|
+
"host" => "api.bigcommerce.com"
|
80
|
+
}
|
81
|
+
when :woocommerce
|
82
|
+
{
|
83
|
+
"Content-Type" => "application/json",
|
84
|
+
"Authorization" => "Bearer #{ api_token }"
|
85
|
+
}
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def api_version
|
90
|
+
case platform
|
91
|
+
when :shopify
|
92
|
+
EPlat.config.shopify_api_version
|
93
|
+
when :bigcommerce
|
94
|
+
EPlat.config.bigcommerce_api_version
|
95
|
+
when :woocommerce
|
96
|
+
EPlat.config.woocommerce_api_version
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def can_update_nested_resources?
|
101
|
+
case platform
|
102
|
+
when :shopify then true
|
103
|
+
when :bigcommerce then false
|
104
|
+
else false
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def pagination_param
|
109
|
+
case platform
|
110
|
+
when :shopify then SHOPIFY_PAGINATION_PARAM
|
111
|
+
when :bigcommerce then BIGCOMMERCE_PAGINATION_PARAM
|
112
|
+
when :woocommerce then nil
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def include_format_in_path?
|
117
|
+
!bigcommerce?
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
end
|
95
122
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
module EPlat
|
3
3
|
class MissingSessionError < StandardError
|
4
|
-
def initialize(msg="Missing session state, did you
|
4
|
+
def initialize(msg="Missing session state, did you set EPlat::Session")
|
5
5
|
super
|
6
6
|
end
|
7
7
|
end
|
data/lib/e_plat/mapping/base.rb
CHANGED
@@ -1,7 +1,43 @@
|
|
1
1
|
module EPlat
|
2
2
|
class Mapping
|
3
3
|
class Base
|
4
|
+
include RequestBodyRoot
|
5
|
+
attr_accessor :resource, :virtual_collection
|
6
|
+
|
7
|
+
DEFAULT_VALUES = {} # {location: "head", auto_uninstall: true, ...}
|
4
8
|
|
9
|
+
class << self
|
10
|
+
attr_accessor :virtual_collections
|
11
|
+
|
12
|
+
# virtual_collection :line_items, class: EPlat::Mapping::VirtualCollection::Bigcommerce::OrderLineItems, map_from: "consignments"
|
13
|
+
def virtual_collection(name, **options)
|
14
|
+
self.virtual_collections ||= []
|
15
|
+
|
16
|
+
self.virtual_collections.push({
|
17
|
+
name: name,
|
18
|
+
class: options[:class],
|
19
|
+
map_from: options[:map_from]
|
20
|
+
})
|
21
|
+
|
22
|
+
define_method("init_#{name}") do |resource:, map_from:|
|
23
|
+
instance_variable_set "@#{name}", "#{ options[:class] }".constantize.new(resource: resource, map_from: map_from)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def initialize(resource_instance)
|
30
|
+
@resource = resource_instance
|
31
|
+
|
32
|
+
init_virtual_collections if @resource.present?
|
33
|
+
end
|
34
|
+
|
35
|
+
def inspect
|
36
|
+
"#<#{self.class} #{ self.instance_variable_names.join(' ') }>"
|
37
|
+
end
|
38
|
+
|
39
|
+
# The below three methods are added to via the individual mapping classes
|
40
|
+
|
5
41
|
def native_top_key
|
6
42
|
:itself # or top key of JSON response e.g. "data", "product",
|
7
43
|
end
|
@@ -14,36 +50,107 @@ module EPlat
|
|
14
50
|
[
|
15
51
|
# {
|
16
52
|
# alias_attribute: {native_key: "description", e_plat_key: "body_html"}
|
17
|
-
# },
|
18
|
-
# {
|
19
|
-
#
|
20
|
-
#
|
53
|
+
# }, {
|
54
|
+
# alias_attribute: {
|
55
|
+
# native_key: "description",
|
56
|
+
# e_plat_key: "body_html",
|
57
|
+
# custom_e_plat_getter: "-> (value) { value&.gsub(' ', '-') }",
|
58
|
+
# custom_native_setter: "-> (value) { value&.gsub('-', ' ') }"
|
59
|
+
# }
|
60
|
+
# }, {
|
61
|
+
# existing_entry: {native_key: "id", e_plat_key: "id"}
|
62
|
+
# }
|
21
63
|
]
|
22
64
|
end
|
65
|
+
|
66
|
+
# The below methods add support for getting/setting/converting via e_plat and native keys
|
23
67
|
|
24
|
-
def aliases
|
25
|
-
native_attribute_aliases.map do |alias_hash|
|
26
|
-
|
68
|
+
def aliases #e.g. {description: "body_html", native_key: "e_plat_key", ...}
|
69
|
+
@aliases ||= native_attribute_aliases.map do |alias_hash|
|
70
|
+
if alias_hash[:alias_attribute]
|
71
|
+
keys = alias_hash[:alias_attribute].values[0..1]
|
72
|
+
elsif alias_hash[:existing_entry]
|
73
|
+
keys = alias_hash[:existing_entry].values[0..1]
|
74
|
+
else
|
75
|
+
next
|
76
|
+
end
|
27
77
|
|
28
|
-
keys = alias_hash[:alias_attribute].values[0..1]
|
29
78
|
Hash[*keys]
|
30
79
|
end.compact_blank.inject(&:merge) || {}
|
31
80
|
end
|
81
|
+
|
82
|
+
def keys_aliased_to_native_keys
|
83
|
+
@e_plat_to_native_aliases ||= aliases.invert
|
84
|
+
end
|
85
|
+
|
86
|
+
def native_key_to(e_plat_key) #e.g. "description" => "body_html"
|
87
|
+
aliases.invert[e_plat_key]
|
88
|
+
end
|
89
|
+
|
90
|
+
def e_plat_key_to(native_key) #e.g. "body_html" => "description"
|
91
|
+
aliases[native_key]
|
92
|
+
end
|
32
93
|
|
33
|
-
def to_native_keys(attributes)
|
94
|
+
def to_native_keys(attributes) #e.g. {body_html: "A great t-shirt"} => {description: "A great t-shirt"}
|
34
95
|
as = aliases.invert
|
35
|
-
attributes.transform_keys{|key| (as[key]) ? as[key] : key }
|
96
|
+
attributes.with_indifferent_access.transform_keys{|key| (as[key]) ? as[key] : key }
|
36
97
|
end
|
37
98
|
|
38
|
-
def to_e_plat_keys(attributes)
|
99
|
+
def to_e_plat_keys(attributes) #e.g. {description: "A great t-shirt"} => {body_html: "A great t-shirt"}
|
39
100
|
as = aliases
|
40
|
-
attributes.transform_keys{|key| (as[key]) ? as[key] : key }
|
101
|
+
attributes.with_indifferent_access.transform_keys {|key| (as[key]) ? as[key] : key }
|
41
102
|
end
|
42
103
|
|
43
104
|
def mappable_keys
|
44
105
|
native_attribute_aliases.map{|a| a.values.first[:e_plat_key]}.presence || :all
|
45
106
|
end
|
46
107
|
|
108
|
+
def mappings #e.g. {e_plat_key: native_key, 'body_html' => 'description'}
|
109
|
+
@mapping ||= native_attribute_aliases.map{|a| a[:alias_attribute] }.compact_blank.inject(&:merge) || {}
|
110
|
+
end
|
111
|
+
|
112
|
+
def via_native_attributes_where_possible(params) # e.g. {financial_status: 'paid'} => {status_id: 11}
|
113
|
+
e_plat_key_mappings = keys_aliased_to_native_keys.with_indifferent_access # {e_plat_key: native_key}
|
114
|
+
translated_attributes = {}
|
115
|
+
|
116
|
+
params.each do |e_plat_key, value|
|
117
|
+
native_key = e_plat_key_mappings[e_plat_key]
|
118
|
+
|
119
|
+
if native_key
|
120
|
+
translated_attributes[native_key] = native_setter(e_plat_key.to_s, value) || value
|
121
|
+
else
|
122
|
+
translated_attributes[e_plat_key] = value
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
translated_attributes
|
127
|
+
end
|
128
|
+
|
129
|
+
def native_setter(e_plat_key, value) # str, proc.call(value) | nil
|
130
|
+
return unless keys_aliased_to_native_keys[e_plat_key]
|
131
|
+
value = value.to_s if value.is_a?(Symbol)
|
132
|
+
|
133
|
+
attribute_aliases = native_attribute_aliases.map{|a| a[:alias_attribute] }.compact_blank
|
134
|
+
|
135
|
+
proc = attribute_aliases.find do |a|
|
136
|
+
a[:e_plat_key].to_s == e_plat_key.to_s && a[:custom_native_setter]
|
137
|
+
end.try(:[], :custom_native_setter)
|
138
|
+
|
139
|
+
eval(proc).call(value) if proc
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
private
|
144
|
+
|
145
|
+
def init_virtual_collections
|
146
|
+
self.class.virtual_collections&.each do |virtual_collection|
|
147
|
+
name = virtual_collection[:name]
|
148
|
+
map_from = virtual_collection[:map_from]
|
149
|
+
|
150
|
+
send("init_#{ name }", resource: @resource, map_from: map_from)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
47
154
|
end
|
48
155
|
end
|
49
156
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module EPlat
|
2
|
+
class Mapping
|
3
|
+
module Bigcommerce
|
4
|
+
module V3
|
5
|
+
class Metafield < EPlat::Mapping::Base
|
6
|
+
|
7
|
+
def native_top_key
|
8
|
+
"data"
|
9
|
+
end
|
10
|
+
|
11
|
+
def native_attributes
|
12
|
+
super.concat([
|
13
|
+
"id",
|
14
|
+
"key",
|
15
|
+
"value",
|
16
|
+
"namespace",
|
17
|
+
"permission_set",
|
18
|
+
"resource_type",
|
19
|
+
"resource_id",
|
20
|
+
"description",
|
21
|
+
"date_created",
|
22
|
+
"date_modified"
|
23
|
+
])
|
24
|
+
end
|
25
|
+
|
26
|
+
def native_attribute_aliases
|
27
|
+
super.concat([
|
28
|
+
{
|
29
|
+
existing_entry: {native_key: "id", e_plat_key: "id"}
|
30
|
+
},
|
31
|
+
{
|
32
|
+
existing_entry: {native_key: "key", e_plat_key: "key"}
|
33
|
+
},
|
34
|
+
{
|
35
|
+
existing_entry: {native_key: "value", e_plat_key: "value"}
|
36
|
+
},
|
37
|
+
{
|
38
|
+
existing_entry: {native_key: "namespace", e_plat_key: "namespace"}
|
39
|
+
},
|
40
|
+
{
|
41
|
+
existing_entry: {native_key: "description", e_plat_key: "description"}
|
42
|
+
},
|
43
|
+
{
|
44
|
+
alias_attribute: {native_key: "date_created", e_plat_key: "created_at"}
|
45
|
+
},
|
46
|
+
{
|
47
|
+
alias_attribute: {native_key: "date_modified",e_plat_key: "updated_at"}
|
48
|
+
},
|
49
|
+
{
|
50
|
+
alias_attribute: {native_key: "resource_type",e_plat_key: "owner_resource"}
|
51
|
+
},
|
52
|
+
{
|
53
|
+
alias_attribute: {native_key: "resource_id", e_plat_key: "owner_id"}
|
54
|
+
}
|
55
|
+
])
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
|
2
|
+
module EPlat
|
3
|
+
class Mapping
|
4
|
+
module Bigcommerce
|
5
|
+
module V3
|
6
|
+
class Order::LineItem < EPlat::Mapping::Base
|
7
|
+
|
8
|
+
def native_top_key
|
9
|
+
"data"
|
10
|
+
end
|
11
|
+
|
12
|
+
def native_attributes
|
13
|
+
super.concat([
|
14
|
+
"id",
|
15
|
+
"order_id",
|
16
|
+
"product_id",
|
17
|
+
"variant_id",
|
18
|
+
"order_pickup_method_id",
|
19
|
+
"order_address_id",
|
20
|
+
"name",
|
21
|
+
"name_customer",
|
22
|
+
"name_merchant",
|
23
|
+
"sku",
|
24
|
+
"upc",
|
25
|
+
"type",
|
26
|
+
"base_price",
|
27
|
+
"price_ex_tax",
|
28
|
+
"price_inc_tax",
|
29
|
+
"price_tax",
|
30
|
+
"base_total",
|
31
|
+
"total_ex_tax",
|
32
|
+
"total_inc_tax",
|
33
|
+
"total_tax",
|
34
|
+
"weight",
|
35
|
+
"width",
|
36
|
+
"height",
|
37
|
+
"depth",
|
38
|
+
"quantity",
|
39
|
+
"base_cost_price",
|
40
|
+
"cost_price_inc_tax",
|
41
|
+
"cost_price_ex_tax",
|
42
|
+
"cost_price_tax",
|
43
|
+
"is_refunded",
|
44
|
+
"quantity_refunded",
|
45
|
+
"refund_amount",
|
46
|
+
"return_id",
|
47
|
+
"wrapping_id",
|
48
|
+
"wrapping_name",
|
49
|
+
"base_wrapping_cost",
|
50
|
+
"wrapping_cost_ex_tax",
|
51
|
+
"wrapping_cost_inc_tax",
|
52
|
+
"wrapping_cost_tax",
|
53
|
+
"wrapping_message",
|
54
|
+
"quantity_shipped",
|
55
|
+
"event_name",
|
56
|
+
"event_date",
|
57
|
+
"fixed_shipping_cost",
|
58
|
+
"ebay_item_id",
|
59
|
+
"ebay_transaction_id",
|
60
|
+
"option_set_id",
|
61
|
+
"parent_order_product_id",
|
62
|
+
"is_bundled_product",
|
63
|
+
"bin_picking_number",
|
64
|
+
"external_id",
|
65
|
+
"fulfillment_source",
|
66
|
+
"brand",
|
67
|
+
"gift_certificate_id",
|
68
|
+
"applied_discounts",
|
69
|
+
"product_options",
|
70
|
+
"configurable_fields",
|
71
|
+
"discounted_total_inc_tax"
|
72
|
+
])
|
73
|
+
end
|
74
|
+
|
75
|
+
def native_attribute_aliases
|
76
|
+
super.concat([
|
77
|
+
# see virtual_collection @ EPlat::Mapping::VirtualCollection::Bigcommerce::OrderLineItems
|
78
|
+
])
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|