fera-api 0.1.0 → 0.1.3
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/.rubocop.yml +10 -56
- data/.ruby-version +1 -0
- data/.spellr.yml +9 -0
- data/.spellr_wordlists/english.txt +774 -0
- data/.spellr_wordlists/html.txt +1 -0
- data/.spellr_wordlists/javascript.txt +3 -0
- data/.spellr_wordlists/ruby.txt +22 -0
- data/Gemfile +7 -4
- data/Gemfile.lock +69 -21
- data/README.md +5 -2
- data/lib/fera/api/version.rb +1 -1
- data/lib/fera/api.rb +8 -3
- data/lib/fera/app.rb +3 -0
- data/lib/fera/models/base.rb +44 -32
- data/lib/fera/models/collection.rb +1 -1
- data/lib/fera/models/concerns/belongs_to_customer.rb +2 -7
- data/lib/fera/models/concerns/belongs_to_order.rb +16 -20
- data/lib/fera/models/concerns/belongs_to_product.rb +14 -18
- data/lib/fera/models/concerns/belongs_to_review.rb +9 -13
- data/lib/fera/models/concerns/belongs_to_submission.rb +0 -3
- data/lib/fera/models/concerns/has_subject.rb +3 -5
- data/lib/fera/models/media.rb +8 -8
- metadata +91 -18
- data/.idea/fera-api.iml +0 -86
- data/.idea/modules.xml +0 -8
- data/.idea/vcs.xml +0 -6
- data/.idea/workspace.xml +0 -91
@@ -0,0 +1 @@
|
|
1
|
+
clearfix
|
data/Gemfile
CHANGED
@@ -5,10 +5,13 @@ source "https://rubygems.org"
|
|
5
5
|
# Specify your gem's dependencies in fera.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
gem "rake", "~> 13.0"
|
9
|
-
|
10
8
|
group :development, :test do
|
11
|
-
gem "
|
12
|
-
|
9
|
+
gem "pry"
|
10
|
+
gem "pry-byebug"
|
11
|
+
gem "pry-rails"
|
12
|
+
gem "pry-remote"
|
13
|
+
gem "pry-rescue"
|
14
|
+
gem "pry-stack_explorer"
|
13
15
|
gem "rubocop"
|
16
|
+
gem "rubocop-rspec"
|
14
17
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fera-api (0.1.
|
4
|
+
fera-api (0.1.3)
|
5
5
|
activemodel (>= 4)
|
6
6
|
activeresource (>= 6)
|
7
|
-
activesupport (>=
|
7
|
+
activesupport (>= 4.0)
|
8
8
|
json-jwt (>= 1)
|
9
9
|
require_all (>= 2)
|
10
10
|
|
11
11
|
GEM
|
12
12
|
remote: https://rubygems.org/
|
13
13
|
specs:
|
14
|
-
activemodel (
|
15
|
-
activesupport (=
|
14
|
+
activemodel (7.0.3.1)
|
15
|
+
activesupport (= 7.0.3.1)
|
16
16
|
activemodel-serializers-xml (1.0.2)
|
17
17
|
activemodel (> 5.x)
|
18
18
|
activesupport (> 5.x)
|
@@ -21,31 +21,62 @@ GEM
|
|
21
21
|
activemodel (>= 6.0)
|
22
22
|
activemodel-serializers-xml (~> 1.0)
|
23
23
|
activesupport (>= 6.0)
|
24
|
-
activesupport (
|
24
|
+
activesupport (7.0.3.1)
|
25
25
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
26
26
|
i18n (>= 1.6, < 2)
|
27
27
|
minitest (>= 5.1)
|
28
28
|
tzinfo (~> 2.0)
|
29
|
-
|
29
|
+
addressable (2.8.0)
|
30
|
+
public_suffix (>= 2.0.2, < 5.0)
|
30
31
|
aes_key_wrap (1.1.0)
|
31
32
|
ast (2.4.2)
|
32
33
|
bindata (2.4.10)
|
34
|
+
binding_of_caller (1.0.0)
|
35
|
+
debug_inspector (>= 0.0.1)
|
33
36
|
builder (3.2.4)
|
37
|
+
byebug (11.1.3)
|
38
|
+
coderay (1.1.3)
|
34
39
|
concurrent-ruby (1.1.10)
|
40
|
+
crack (0.4.5)
|
41
|
+
rexml
|
42
|
+
debug_inspector (1.1.0)
|
35
43
|
diff-lcs (1.5.0)
|
36
|
-
|
44
|
+
hashdiff (1.0.1)
|
45
|
+
httpclient (2.8.3)
|
46
|
+
i18n (1.12.0)
|
37
47
|
concurrent-ruby (~> 1.0)
|
38
|
-
|
48
|
+
interception (0.5)
|
49
|
+
json (2.6.2)
|
50
|
+
json-jwt (1.15.3)
|
39
51
|
activesupport (>= 4.2)
|
40
52
|
aes_key_wrap
|
41
53
|
bindata
|
42
|
-
|
54
|
+
httpclient
|
55
|
+
method_source (1.0.0)
|
56
|
+
minitest (5.16.3)
|
43
57
|
parallel (1.22.1)
|
44
|
-
parser (3.1.2.
|
58
|
+
parser (3.1.2.1)
|
45
59
|
ast (~> 2.4.1)
|
60
|
+
pry (0.14.1)
|
61
|
+
coderay (~> 1.1)
|
62
|
+
method_source (~> 1.0)
|
63
|
+
pry-byebug (3.10.1)
|
64
|
+
byebug (~> 11.0)
|
65
|
+
pry (>= 0.13, < 0.15)
|
66
|
+
pry-rails (0.3.9)
|
67
|
+
pry (>= 0.10.4)
|
68
|
+
pry-remote (0.1.8)
|
69
|
+
pry (~> 0.9)
|
70
|
+
slop (~> 3.0)
|
71
|
+
pry-rescue (1.5.2)
|
72
|
+
interception (>= 0.5)
|
73
|
+
pry (>= 0.12.0)
|
74
|
+
pry-stack_explorer (0.6.1)
|
75
|
+
binding_of_caller (~> 1.0)
|
76
|
+
pry (~> 0.13)
|
77
|
+
public_suffix (4.0.7)
|
46
78
|
rainbow (3.1.1)
|
47
|
-
|
48
|
-
regexp_parser (2.4.0)
|
79
|
+
regexp_parser (2.5.0)
|
49
80
|
require_all (3.0.0)
|
50
81
|
rexml (3.2.5)
|
51
82
|
rspec (3.11.0)
|
@@ -61,32 +92,49 @@ GEM
|
|
61
92
|
diff-lcs (>= 1.2.0, < 2.0)
|
62
93
|
rspec-support (~> 3.11.0)
|
63
94
|
rspec-support (3.11.0)
|
64
|
-
rubocop (1.
|
95
|
+
rubocop (1.35.0)
|
96
|
+
json (~> 2.3)
|
65
97
|
parallel (~> 1.10)
|
66
|
-
parser (>= 3.1.
|
98
|
+
parser (>= 3.1.2.1)
|
67
99
|
rainbow (>= 2.2.2, < 4.0)
|
68
100
|
regexp_parser (>= 1.8, < 3.0)
|
69
101
|
rexml (>= 3.2.5, < 4.0)
|
70
|
-
rubocop-ast (>= 1.
|
102
|
+
rubocop-ast (>= 1.20.1, < 2.0)
|
71
103
|
ruby-progressbar (~> 1.7)
|
72
104
|
unicode-display_width (>= 1.4.0, < 3.0)
|
73
|
-
rubocop-ast (1.
|
105
|
+
rubocop-ast (1.21.0)
|
74
106
|
parser (>= 3.1.1.0)
|
107
|
+
rubocop-rspec (2.12.1)
|
108
|
+
rubocop (~> 1.31)
|
75
109
|
ruby-progressbar (1.11.0)
|
76
|
-
|
110
|
+
slop (3.6.0)
|
111
|
+
to_bool (2.0.0)
|
112
|
+
tzinfo (2.0.5)
|
77
113
|
concurrent-ruby (~> 1.0)
|
78
|
-
unicode-display_width (2.
|
79
|
-
|
114
|
+
unicode-display_width (2.2.0)
|
115
|
+
webmock (3.18.0)
|
116
|
+
addressable (>= 2.8.0)
|
117
|
+
crack (>= 0.3.2)
|
118
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
80
119
|
|
81
120
|
PLATFORMS
|
82
121
|
x86_64-darwin-18
|
83
122
|
x86_64-darwin-20
|
123
|
+
x86_64-linux
|
84
124
|
|
85
125
|
DEPENDENCIES
|
86
126
|
fera-api!
|
87
|
-
|
88
|
-
|
127
|
+
pry
|
128
|
+
pry-byebug
|
129
|
+
pry-rails
|
130
|
+
pry-remote
|
131
|
+
pry-rescue
|
132
|
+
pry-stack_explorer
|
133
|
+
rspec (>= 3.0)
|
89
134
|
rubocop
|
135
|
+
rubocop-rspec
|
136
|
+
to_bool
|
137
|
+
webmock (>= 3.0)
|
90
138
|
|
91
139
|
BUNDLED WITH
|
92
140
|
2.3.13
|
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
|
1
|
+
[](https://github.com/feracommerce/fera-api-ruby/actions/workflows/checks.yml)
|
2
|
+
[](https://github.com/feracommerce/fera-api-ruby/actions/workflows/tests.yml)
|
3
|
+
|
4
|
+
# Fera API Ruby Client
|
2
5
|
|
3
6
|
Welcome to the Fera API gem for Ruby. This gem is Fera's official Ruby SDK and make it easy to interact with the Fera API.
|
4
7
|
|
@@ -9,7 +12,7 @@ Fera API Developer Docs and API Reference can be found at: [https://developers.f
|
|
9
12
|
Install the gem and add to the application's Gemfile by executing:
|
10
13
|
|
11
14
|
```ruby
|
12
|
-
gem 'fera'
|
15
|
+
gem 'fera-api'
|
13
16
|
```
|
14
17
|
|
15
18
|
# Configuration
|
data/lib/fera/api/version.rb
CHANGED
data/lib/fera/api.rb
CHANGED
@@ -18,11 +18,15 @@ module Fera
|
|
18
18
|
|
19
19
|
##
|
20
20
|
# @param api_key [String] Public API key, Secret API key or Auth Token (if app)
|
21
|
-
|
21
|
+
# @return [Object, ::Fera::API] Result of the block operation if given, otherwise self
|
22
|
+
def self.configure(api_key, api_url: nil, strict_mode: false, debug_mode: false)
|
22
23
|
previous_base_site = Base.site
|
23
24
|
previous_base_headers = Base.headers
|
24
25
|
|
25
|
-
|
26
|
+
api_url ||= 'https://api.fera.ai'
|
27
|
+
Base.site = "#{ api_url.chomp('/') }/v3/private"
|
28
|
+
|
29
|
+
@debug_mode = debug_mode
|
26
30
|
|
27
31
|
if api_key =~ /^sk_/
|
28
32
|
Base.headers['Secret-Key'] = api_key
|
@@ -48,9 +52,10 @@ module Fera
|
|
48
52
|
else
|
49
53
|
self
|
50
54
|
end
|
51
|
-
|
52
55
|
end
|
53
56
|
|
57
|
+
def self.debug_mode?; @debug_mode; end
|
58
|
+
|
54
59
|
def self.revoke_token!(client_id:, client_secret:, auth_token:)
|
55
60
|
previous_site = Base.site
|
56
61
|
|
data/lib/fera/app.rb
CHANGED
data/lib/fera/models/base.rb
CHANGED
@@ -2,11 +2,10 @@ require_relative './collection'
|
|
2
2
|
|
3
3
|
module Fera
|
4
4
|
class Base < ActiveResource::Base
|
5
|
-
# include ActiveModel::Dirty
|
6
|
-
|
7
5
|
attr_reader :last_response, :last_response_body, :last_response_message, :last_response_exception, :options
|
8
6
|
|
9
7
|
self.collection_parser = ::Fera::Collection
|
8
|
+
self.site ||= "https://api.fera.ai/v3/private"
|
10
9
|
|
11
10
|
class << self
|
12
11
|
def belongs_to(name, options = {})
|
@@ -33,13 +32,11 @@ module Fera
|
|
33
32
|
elsif superclass != Object && superclass.headers
|
34
33
|
superclass.headers
|
35
34
|
else
|
36
|
-
_headers ||= {}
|
35
|
+
_headers ||= {} # rubocop:disable Lint/UnderscorePrefixedVariableName
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
40
|
-
|
41
|
-
@default_params = default_params
|
42
|
-
end
|
39
|
+
attr_writer :default_params
|
43
40
|
|
44
41
|
##
|
45
42
|
# @override to support extra_params
|
@@ -80,7 +77,7 @@ module Fera
|
|
80
77
|
end
|
81
78
|
|
82
79
|
def new_element_path(prefix_options = {}, extra_params = {})
|
83
|
-
url = "#{prefix(prefix_options)}#{collection_name}/new#{format_extension}"
|
80
|
+
url = "#{ prefix(prefix_options) }#{ collection_name }/new#{ format_extension }"
|
84
81
|
url += "?#{ extra_params.to_param }" if extra_params.present?
|
85
82
|
url
|
86
83
|
end
|
@@ -108,12 +105,14 @@ module Fera
|
|
108
105
|
|
109
106
|
super(dynamic_attributes, persisted)
|
110
107
|
|
111
|
-
|
108
|
+
return unless attributes.present?
|
109
|
+
|
110
|
+
association_keys.each do |name, _opts|
|
112
111
|
if attributes.key?(name.to_s) || attributes.key?(name.to_sym)
|
113
112
|
val = attributes.to_h[name.to_s] || attributes.to_h[name.to_sym]
|
114
113
|
self.send("#{ name }=", val) if respond_to?("#{ name }=")
|
115
114
|
end
|
116
|
-
end
|
115
|
+
end
|
117
116
|
end
|
118
117
|
|
119
118
|
def load(attributes, *args)
|
@@ -135,18 +134,24 @@ module Fera
|
|
135
134
|
end
|
136
135
|
|
137
136
|
def created_at=(new_created_at)
|
138
|
-
|
139
|
-
|
137
|
+
if new_created_at.is_a?(String)
|
138
|
+
super(Time.parse(new_created_at))
|
139
|
+
else
|
140
|
+
super
|
141
|
+
end
|
140
142
|
end
|
141
143
|
|
142
144
|
def updated_at=(new_updated_at)
|
143
|
-
|
144
|
-
|
145
|
+
if new_updated_at.is_a?(String)
|
146
|
+
super(Time.parse(new_updated_at))
|
147
|
+
else
|
148
|
+
super
|
149
|
+
end
|
145
150
|
end
|
146
151
|
|
147
|
-
def update(changed_attributes, extra_params = {}, raise
|
152
|
+
def update(changed_attributes, extra_params = {}, raise: false)
|
148
153
|
run_callbacks(:update) do
|
149
|
-
connection.put(element_path(prefix_options, extra_params),
|
154
|
+
connection.put(element_path(prefix_options, extra_params), changed_attributes.to_json, self.class.headers).tap do |response|
|
150
155
|
load_attributes_from_response(response)
|
151
156
|
end
|
152
157
|
|
@@ -165,21 +170,21 @@ module Fera
|
|
165
170
|
end
|
166
171
|
|
167
172
|
def update!(changed_attributes, extra_params = {})
|
168
|
-
update(changed_attributes, extra_params, true)
|
173
|
+
update(changed_attributes, extra_params, raise: true)
|
169
174
|
end
|
170
175
|
|
171
|
-
def valid?(
|
176
|
+
def valid?(_context = nil)
|
172
177
|
super()
|
173
178
|
end
|
174
179
|
|
175
180
|
##
|
176
|
-
# @override to add
|
177
|
-
def create(extra_params = {}, raise
|
181
|
+
# @override to add extra params
|
182
|
+
def create(extra_params = {}, raise: false)
|
178
183
|
run_callbacks :create do
|
179
|
-
|
180
184
|
data = as_json
|
181
|
-
|
185
|
+
self.class.belongs_tos.merge(self.class.has_ones).each do |name, _opts|
|
182
186
|
next unless instance_variable_defined?(:"@#{ name }")
|
187
|
+
|
183
188
|
nested_resource = self.send(name)
|
184
189
|
if nested_resource.present? && !nested_resource.persisted?
|
185
190
|
nested_resource.validate!
|
@@ -187,8 +192,9 @@ module Fera
|
|
187
192
|
end
|
188
193
|
end
|
189
194
|
|
190
|
-
self.class.has_manys.each do |name,
|
195
|
+
self.class.has_manys.each do |name, _opts|
|
191
196
|
next unless instance_variable_defined?(:"@#{ name }")
|
197
|
+
|
192
198
|
nested_resource = self.send(name)
|
193
199
|
|
194
200
|
next if nested_resource.nil?
|
@@ -203,7 +209,7 @@ module Fera
|
|
203
209
|
end
|
204
210
|
end
|
205
211
|
|
206
|
-
connection.post(collection_path(nil, extra_params), data.to_json, self.class.headers).tap do |response|
|
212
|
+
connection.post(collection_path(nil, extra_params), { data: data }.to_json, self.class.headers).tap do |response|
|
207
213
|
self.id = id_from_response(response)
|
208
214
|
load_attributes_from_response(response)
|
209
215
|
end
|
@@ -221,13 +227,13 @@ module Fera
|
|
221
227
|
end
|
222
228
|
|
223
229
|
def create!(extra_params = {})
|
224
|
-
create(extra_params, true)
|
230
|
+
create(extra_params, raise: true)
|
225
231
|
end
|
226
232
|
|
227
|
-
def save(extra_params = {}, raise
|
233
|
+
def save(extra_params = {}, raise: false)
|
228
234
|
run_callbacks :save do
|
229
235
|
if new?
|
230
|
-
create(extra_params, raise) # We'll raise the error below
|
236
|
+
create(extra_params, raise: raise) # We'll raise the error below
|
231
237
|
else
|
232
238
|
# find changes
|
233
239
|
changed_attributes = attributes.filter { |key, value| !@clean_copy.attributes.key?(key) || (@clean_copy.attributes[key] != value) || (key == self.class.primary_key) }
|
@@ -235,23 +241,22 @@ module Fera
|
|
235
241
|
return false unless changed_attributes.keys.any?
|
236
242
|
|
237
243
|
# save
|
238
|
-
update(changed_attributes, extra_params, raise)
|
244
|
+
update(changed_attributes, extra_params, raise: raise)
|
239
245
|
end
|
240
246
|
|
241
247
|
@clean_copy = clone_with_nil # Clear changes
|
242
248
|
|
243
249
|
self
|
244
250
|
end
|
245
|
-
|
246
251
|
end
|
247
252
|
|
248
253
|
def save!(extra_params = {})
|
249
|
-
save(extra_params, true)
|
254
|
+
save(extra_params, raise: true)
|
250
255
|
end
|
251
256
|
|
252
257
|
def clone_with_nil
|
253
258
|
# Clone all attributes except the pk and any nested ARes
|
254
|
-
cloned =
|
259
|
+
cloned = attributes.reject { |k, v| k == self.class.primary_key || v.is_a?(ActiveResource::Base) }.map { |k, v| [k, v.clone] }.to_h
|
255
260
|
# Form the new resource - bypass initialize of resource with 'new' as that will call 'load' which
|
256
261
|
# attempts to convert hashes into member objects and arrays into collections of objects. We want
|
257
262
|
# the raw objects to be cloned so we bypass load by directly setting the attributes hash.
|
@@ -288,9 +293,11 @@ module Fera
|
|
288
293
|
if matcher.present?
|
289
294
|
attribute_name = matcher[1]
|
290
295
|
return super if attribute_name.blank?
|
296
|
+
|
291
297
|
attribute_name = "is_#{ attribute_name }" unless attribute_name =~ /^is_/
|
292
298
|
return super unless known_attribute?(attribute_name.to_s)
|
293
|
-
|
299
|
+
|
300
|
+
return !!send(attribute_name.to_sym).presence
|
294
301
|
end
|
295
302
|
|
296
303
|
super
|
@@ -301,6 +308,7 @@ module Fera
|
|
301
308
|
if matcher.present?
|
302
309
|
attribute_name = matcher[1]
|
303
310
|
return super if attribute_name.blank?
|
311
|
+
|
304
312
|
attribute_name = "is_#{ attribute_name }" unless attribute_name =~ /^is_/
|
305
313
|
return true if known_attribute?(attribute_name)
|
306
314
|
end
|
@@ -312,7 +320,7 @@ module Fera
|
|
312
320
|
known_attributes.map(&:to_s).include?(attribute_name.to_s)
|
313
321
|
end
|
314
322
|
|
315
|
-
def set_last_response(result)
|
323
|
+
def set_last_response(result) # rubocop:disable Naming/AccessorMethodName
|
316
324
|
response = if result.is_a?(StandardError)
|
317
325
|
@last_response_exception = result
|
318
326
|
@last_response_exception.response
|
@@ -370,5 +378,9 @@ module Fera
|
|
370
378
|
sub_fields = sub_fields.drop(1)
|
371
379
|
changed_attributes[sub_key] = values.map { |value| clone_selected_fields(value, sub_fields) }
|
372
380
|
end
|
381
|
+
|
382
|
+
def debug(message)
|
383
|
+
puts "[Fera-Api] #{ message }" if ::Fera::Api.debug_mode?
|
384
|
+
end
|
373
385
|
end
|
374
386
|
end
|
@@ -5,7 +5,7 @@ module Fera
|
|
5
5
|
attr_reader :result_count, :total_count, :page, :total_pages, :page_size, :offset, :limit
|
6
6
|
|
7
7
|
def initialize(parsed = {})
|
8
|
-
|
8
|
+
super(parsed['data'])
|
9
9
|
@result_count = parsed['result_count']
|
10
10
|
@total_count = parsed['total_count']
|
11
11
|
|
@@ -10,8 +10,8 @@ module Fera
|
|
10
10
|
|
11
11
|
def customer=(customer)
|
12
12
|
if customer.is_a?(Customer)
|
13
|
-
@customer
|
14
|
-
self.attributes['customer_id']
|
13
|
+
@customer = customer
|
14
|
+
self.attributes['customer_id'] = customer.id
|
15
15
|
self.attributes['external_customer_id'] = customer.try(:external_id)
|
16
16
|
self.attributes.delete('customer')
|
17
17
|
elsif customer.is_a?(Hash)
|
@@ -32,9 +32,6 @@ module Fera
|
|
32
32
|
@customer = Customer.new(customer, customer_id.present?)
|
33
33
|
self.attributes.delete('customer')
|
34
34
|
end
|
35
|
-
|
36
|
-
|
37
|
-
@customer
|
38
35
|
end
|
39
36
|
|
40
37
|
def customer_id=(new_id)
|
@@ -62,8 +59,6 @@ module Fera
|
|
62
59
|
Customer.find(customer_id)
|
63
60
|
elsif attributes.key?('external_customer_id') && external_customer_id.present?
|
64
61
|
Customer.find(external_customer_id)
|
65
|
-
else
|
66
|
-
nil
|
67
62
|
end
|
68
63
|
end
|
69
64
|
end
|
@@ -9,29 +9,28 @@ module Fera
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def order=(order)
|
12
|
-
order_id
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
order_id = if order.is_a?(Order)
|
13
|
+
order.id
|
14
|
+
else
|
15
|
+
order.try(:with_indifferent_access).try(:[], :id)
|
16
|
+
end
|
17
17
|
external_order_id = if order.is_a?(Order)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
@order
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
18
|
+
order.external_id
|
19
|
+
else
|
20
|
+
order.try(:with_indifferent_access).try(:[], :external_id)
|
21
|
+
end
|
22
|
+
@order = if order.is_a?(Order)
|
23
|
+
order
|
24
|
+
else
|
25
|
+
Order.new(order, order_id.present?)
|
26
|
+
end
|
27
27
|
self.attributes['order_id'] = order_id
|
28
28
|
self.attributes['external_order_id'] = external_order_id
|
29
29
|
self.attributes.delete('order')
|
30
|
-
@order
|
31
30
|
end
|
32
31
|
|
33
32
|
def order_id=(new_id)
|
34
|
-
return
|
33
|
+
return if order_id == new_id
|
35
34
|
|
36
35
|
if new_id.nil?
|
37
36
|
reset_order_instance_assoc
|
@@ -41,7 +40,7 @@ module Fera
|
|
41
40
|
end
|
42
41
|
|
43
42
|
def external_order_id=(new_id)
|
44
|
-
return
|
43
|
+
return if external_order_id == new_id
|
45
44
|
|
46
45
|
if new_id.nil?
|
47
46
|
reset_order_instance_assoc
|
@@ -78,10 +77,7 @@ module Fera
|
|
78
77
|
Order.find(order_id)
|
79
78
|
elsif attributes.key?('external_order_id') && external_order_id.present?
|
80
79
|
Order.find(external_order_id)
|
81
|
-
else
|
82
|
-
nil
|
83
80
|
end
|
84
81
|
end
|
85
|
-
|
86
82
|
end
|
87
83
|
end
|
@@ -9,25 +9,24 @@ module Fera
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def product=(product)
|
12
|
-
product_id
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
product_id = if product.is_a?(Product)
|
13
|
+
product.id
|
14
|
+
else
|
15
|
+
product.try(:with_indifferent_access).try(:[], :id)
|
16
|
+
end
|
17
17
|
external_product_id = if product.is_a?(Product)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
@product
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
18
|
+
product.external_id
|
19
|
+
else
|
20
|
+
product.try(:with_indifferent_access).try(:[], :external_id)
|
21
|
+
end
|
22
|
+
@product = if product.is_a?(Product)
|
23
|
+
product
|
24
|
+
else
|
25
|
+
Product.new(product, product_id.present?)
|
26
|
+
end
|
27
27
|
self.attributes['product_id'] = product_id
|
28
28
|
self.attributes['external_product_id'] = external_product_id
|
29
29
|
self.attributes.delete('product')
|
30
|
-
@product
|
31
30
|
end
|
32
31
|
|
33
32
|
def product
|
@@ -39,10 +38,7 @@ module Fera
|
|
39
38
|
Product.find(product_id)
|
40
39
|
elsif attributes.key?('external_product_id') && external_product_id.present?
|
41
40
|
Product.find(external_product_id)
|
42
|
-
else
|
43
|
-
nil
|
44
41
|
end
|
45
42
|
end
|
46
|
-
|
47
43
|
end
|
48
44
|
end
|
@@ -10,18 +10,17 @@ module Fera
|
|
10
10
|
|
11
11
|
def review=(review)
|
12
12
|
review_id = if review.is_a?(Review)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
@review
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
13
|
+
review.id
|
14
|
+
else
|
15
|
+
review.try(:with_indifferent_access).try(:[], :id)
|
16
|
+
end
|
17
|
+
@review = if review.is_a?(Review)
|
18
|
+
review
|
19
|
+
else
|
20
|
+
Review.new(review, review_id.present?)
|
21
|
+
end
|
22
22
|
self.attributes['review_id'] = review_id
|
23
23
|
self.attributes.delete('review')
|
24
|
-
@review
|
25
24
|
end
|
26
25
|
|
27
26
|
def review
|
@@ -31,10 +30,7 @@ module Fera
|
|
31
30
|
Review.new(attributes['review'], true)
|
32
31
|
elsif attributes.key?('review_id') && review_id.present?
|
33
32
|
Review.find(review_id)
|
34
|
-
else
|
35
|
-
nil
|
36
33
|
end
|
37
34
|
end
|
38
|
-
|
39
35
|
end
|
40
36
|
end
|