trophonius 1.0.1 → 1.0.2
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/lib/trophonius_model.rb +13 -12
- data/lib/trophonius_record.rb +3 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46ff946aac98bf9fb8c0ca6494978e68d672f192221983faea8dd5246fd2444e
|
4
|
+
data.tar.gz: 1e8e038d4ea4fb5f2dededa7da2d69fa772f7f8570379957d768a1c5afd1590d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58a38bedf53572f415b5fd204035d38840b3bc0be9a1985a12f1083843727451dee2a21b5e55c0a9f90331bb8afe9903e3db98e46d7e5afd3f5851dcce39e02a
|
7
|
+
data.tar.gz: 34cd621f24880fd6475d5bc350a18a18632e54f6fb4787637996c080c9123a561e6fdc177397528abf69bee9b5633bfa3360511864c5d729ae2748073de34233
|
data/lib/trophonius_model.rb
CHANGED
@@ -148,18 +148,19 @@ module Trophonius
|
|
148
148
|
hash.id = result["recordId"]
|
149
149
|
hash.layout_name = layout_name
|
150
150
|
result["fieldData"].keys.each do |key|
|
151
|
-
unless key[/\s/] || key[/\W/]
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
151
|
+
# unless key[/\s/] || key[/\W/]
|
152
|
+
hash.send(:define_singleton_method, ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_')) do
|
153
|
+
hash[key]
|
154
|
+
end
|
155
|
+
unless non_modifiable_fields&.include?(key)
|
156
|
+
@all_fields.merge!(ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_').downcase => ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_'))
|
157
|
+
hash.send(:define_singleton_method, "#{ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_')}=") do |new_val|
|
158
|
+
hash[key] = new_val
|
159
|
+
hash.modifiable_fields[key] = new_val
|
160
|
+
hash.modified_fields[key] = new_val
|
161
161
|
end
|
162
162
|
end
|
163
|
+
# end
|
163
164
|
hash.merge!({key => result["fieldData"][key]})
|
164
165
|
unless non_modifiable_fields&.include?(key)
|
165
166
|
hash.modifiable_fields.merge!({key => result["fieldData"][key]})
|
@@ -167,13 +168,13 @@ module Trophonius
|
|
167
168
|
end
|
168
169
|
result["portalData"].keys.each do |key|
|
169
170
|
unless key[/\s/] || key[/\W/]
|
170
|
-
hash.send(:define_singleton_method, key.to_s) do
|
171
|
+
hash.send(:define_singleton_method, ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_')) do
|
171
172
|
hash[key]
|
172
173
|
end
|
173
174
|
end
|
174
175
|
result["portalData"][key].each_with_index do |inner_hash|
|
175
176
|
inner_hash.keys.each do |inner_key|
|
176
|
-
inner_method = inner_key.gsub(/\w+::/, "")
|
177
|
+
inner_method = ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(inner_key.gsub(/\w+::/, "").to_s), separator: '_')
|
177
178
|
unless inner_method[/\s/] || inner_method[/\W/]
|
178
179
|
inner_hash.send(:define_singleton_method, inner_method.to_s) { inner_hash[inner_key] }
|
179
180
|
inner_hash.send(:define_singleton_method, "id") { inner_hash["recordId"] }
|
data/lib/trophonius_record.rb
CHANGED
@@ -6,12 +6,13 @@ module Trophonius
|
|
6
6
|
#
|
7
7
|
# A Record is contained in a RecordSet and has methods to retrieve data from the fields inside the Record-hash
|
8
8
|
class Trophonius::Record < Hash
|
9
|
-
attr_accessor :id, :layout_name, :modifiable_fields
|
9
|
+
attr_accessor :id, :layout_name, :modifiable_fields, :modified_fields
|
10
10
|
|
11
11
|
##
|
12
12
|
# Initializes a new Record
|
13
13
|
def initialize
|
14
14
|
@modifiable_fields = {}
|
15
|
+
@modified_fields = {}
|
15
16
|
end
|
16
17
|
|
17
18
|
def []=(field, new_val)
|
@@ -26,7 +27,7 @@ module Trophonius
|
|
26
27
|
# @return [True] if successful
|
27
28
|
def save
|
28
29
|
url = URI("http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/layouts/#{layout_name}/records/#{id}")
|
29
|
-
body = "{\"fieldData\": #{
|
30
|
+
body = "{\"fieldData\": #{modified_fields.to_json}}"
|
30
31
|
response = Request.make_request(url, "Bearer #{Request.get_token}", 'patch', body)
|
31
32
|
if response['messages'][0]['code'] != '0'
|
32
33
|
Error.throw_error(response['messages'][0]['code'])
|