trophonius 1.2.7.1 → 1.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/trophonius_model.rb +21 -2
- data/lib/trophonius_record.rb +30 -0
- data/lib/trophonius_single.rb +27 -0
- 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: 3bab56e5694a58dfcb36972cd8a7f24b16960b7a6efe520b2ba1c29dbc5a650b
|
4
|
+
data.tar.gz: a525c8cda877a52cc8f5d2afe4dbdaf6297c26abd52b738305b78fd28d34dbd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14f3fa2154b15daec4104705c81a77f3e44f4301add7764580e6c9a534c14952ce1bba44a4154258fd06e343e3cb7f8747c5fb7cb16d4475b843af05a96338bb
|
7
|
+
data.tar.gz: 852d63509a6ec296d9818fdcd688f478b4afc94ced0dd834d09201ba2ec7f2a96fdb54d04e7cf11f7f8753c6559cf5afee4ffd4ad1dfd972b2167c81b7f65e4b
|
data/lib/trophonius_model.rb
CHANGED
@@ -175,7 +175,7 @@ module Trophonius
|
|
175
175
|
#
|
176
176
|
# @return [Record] the created record
|
177
177
|
# Model.create(fieldOne: "Data")
|
178
|
-
def self.create(fieldData)
|
178
|
+
def self.create(fieldData, portalData: {})
|
179
179
|
url =
|
180
180
|
URI(
|
181
181
|
URI.escape(
|
@@ -193,7 +193,26 @@ module Trophonius
|
|
193
193
|
new_field_data.merge!({ "#{k}" => fieldData[k] })
|
194
194
|
end
|
195
195
|
end
|
196
|
-
|
196
|
+
|
197
|
+
new_portal_data = {}
|
198
|
+
portalData.each do |portal_name, portal_values|
|
199
|
+
new_portal_data.merge!(
|
200
|
+
portal_name =>
|
201
|
+
portal_values.map do |record|
|
202
|
+
record.inject({}) do |new_hash, (key, value)|
|
203
|
+
new_hash["#{portal_name}::#{key}"] = value
|
204
|
+
new_hash
|
205
|
+
end
|
206
|
+
end
|
207
|
+
)
|
208
|
+
end
|
209
|
+
|
210
|
+
body =
|
211
|
+
if new_portal_data != {}
|
212
|
+
"{\"fieldData\": #{new_field_data.to_json}, \"portalData\": #{new_portal_data.to_json}}"
|
213
|
+
else
|
214
|
+
"{\"fieldData\": #{new_field_data.to_json} }"
|
215
|
+
end
|
197
216
|
response = Request.make_request(url, "Bearer #{Request.get_token}", 'post', body)
|
198
217
|
if response['messages'][0]['code'] != '0'
|
199
218
|
if response['messages'][0]['code'] == '102'
|
data/lib/trophonius_record.rb
CHANGED
@@ -152,6 +152,36 @@ module Trophonius
|
|
152
152
|
end
|
153
153
|
end
|
154
154
|
|
155
|
+
##
|
156
|
+
# Runs a FileMaker script from the context of the Model.
|
157
|
+
#
|
158
|
+
# @param [String] script: the FileMaker script to run
|
159
|
+
#
|
160
|
+
# @param [String] scriptparameter: the parameter required by the FileMaker script
|
161
|
+
#
|
162
|
+
# @return [String]: string representing the script result returned by FileMaker
|
163
|
+
def run_script(script: '', scriptparameter: '')
|
164
|
+
url =
|
165
|
+
URI(
|
166
|
+
URI.escape(
|
167
|
+
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
168
|
+
Trophonius.config.database
|
169
|
+
}/layouts/#{layout_name}/records/#{record_id}?script=#{script}&script.param=#{scriptparameter}"
|
170
|
+
)
|
171
|
+
)
|
172
|
+
|
173
|
+
result = Request.make_request(url, "Bearer #{Request.get_token}", 'get', '{}')
|
174
|
+
|
175
|
+
if result['messages'][0]['code'] != '0'
|
176
|
+
Error.throw_error(result['messages'][0]['code'])
|
177
|
+
elsif result['response']['scriptResult'] == '403'
|
178
|
+
Error.throw_error(403)
|
179
|
+
else
|
180
|
+
ret_val = result['response']['scriptResult']
|
181
|
+
return ret_val || true
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
155
185
|
##
|
156
186
|
# Saves the last changes made to the Record to FileMaker.
|
157
187
|
# Throws a FileMaker error if save failed
|
data/lib/trophonius_single.rb
CHANGED
@@ -46,6 +46,33 @@ module Trophonius
|
|
46
46
|
return ret_val
|
47
47
|
end
|
48
48
|
|
49
|
+
def run_script(script:, scriptparameter:)
|
50
|
+
url =
|
51
|
+
URI(
|
52
|
+
URI.escape(
|
53
|
+
"http#{@config[:ssl] == true ? 's' : ''}://#{@config[:host]}/fmi/data/v1/databases/#{@config[:database]}/layouts/#{
|
54
|
+
@config[:layout_name]
|
55
|
+
}/records?_limit=1&script=#{script}&script.param=#{scriptparameter}"
|
56
|
+
)
|
57
|
+
)
|
58
|
+
|
59
|
+
token = setup_connection
|
60
|
+
result = make_request(url, "Bearer #{token}", 'get', '{}')
|
61
|
+
ret_val = ''
|
62
|
+
|
63
|
+
if result['messages'][0]['code'] != '0'
|
64
|
+
Error.throw_error(result['messages'][0]['code'])
|
65
|
+
elsif result['response']['scriptResult'] == '403'
|
66
|
+
Error.throw_error(403)
|
67
|
+
else
|
68
|
+
ret_val = result['response']['scriptResult']
|
69
|
+
end
|
70
|
+
|
71
|
+
close_connection(token)
|
72
|
+
|
73
|
+
return ret_val
|
74
|
+
end
|
75
|
+
|
49
76
|
private
|
50
77
|
|
51
78
|
def build_result(result)
|