trophonius 1.2.6.2 → 1.2.8
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_config.rb +1 -0
- data/lib/trophonius_connection.rb +13 -8
- data/lib/trophonius_date.rb +2 -0
- data/lib/trophonius_date_time.rb +5 -0
- data/lib/trophonius_model.rb +71 -27
- data/lib/trophonius_query.rb +5 -3
- data/lib/trophonius_record.rb +60 -18
- data/lib/trophonius_request.rb +69 -21
- data/lib/trophonius_single.rb +211 -0
- data/lib/trophonius_time.rb +1 -0
- metadata +8 -12
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_config.rb
CHANGED
@@ -13,6 +13,7 @@ module Trophonius
|
|
13
13
|
config_accessor(:username) { 'Admin' }
|
14
14
|
config_accessor(:password) { '' }
|
15
15
|
config_accessor(:ssl) { true }
|
16
|
+
config_accessor(:fm_18) { false }
|
16
17
|
config_accessor(:count_result_script) { '' }
|
17
18
|
config_accessor(:layout_name) { '' }
|
18
19
|
config_accessor(:non_modifiable_fields) { [] }
|
@@ -38,7 +38,9 @@ module Trophonius
|
|
38
38
|
ssl_verifypeer = !Trophonius.config.local_network
|
39
39
|
url =
|
40
40
|
URI(
|
41
|
-
|
41
|
+
URI.escape(
|
42
|
+
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/sessions"
|
43
|
+
)
|
42
44
|
)
|
43
45
|
request =
|
44
46
|
Typhoeus::Request.new(
|
@@ -83,11 +85,12 @@ module Trophonius
|
|
83
85
|
def self.disconnect
|
84
86
|
url =
|
85
87
|
URI(
|
86
|
-
|
87
|
-
Trophonius.config.
|
88
|
-
|
88
|
+
URI.escape(
|
89
|
+
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
90
|
+
Trophonius.config.database
|
91
|
+
}/sessions/#{Trophonius.config.redis_connection ? Trophonius::RedisManager.get_key(key: 'token') : @token}"
|
92
|
+
)
|
89
93
|
)
|
90
|
-
puts url
|
91
94
|
ssl_verifyhost = Trophonius.config.local_network ? 0 : 2
|
92
95
|
ssl_verifypeer = !Trophonius.config.local_network
|
93
96
|
|
@@ -136,9 +139,11 @@ module Trophonius
|
|
136
139
|
def self.test_connection
|
137
140
|
url =
|
138
141
|
URI(
|
139
|
-
|
140
|
-
Trophonius.config.
|
141
|
-
|
142
|
+
URI.escape(
|
143
|
+
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
144
|
+
Trophonius.config.database
|
145
|
+
}/layouts/#{Trophonius.config.layout_name}/records?_limit=1"
|
146
|
+
)
|
142
147
|
)
|
143
148
|
begin
|
144
149
|
request =
|
data/lib/trophonius_date.rb
CHANGED
data/lib/trophonius_model.rb
CHANGED
@@ -112,7 +112,16 @@ module Trophonius
|
|
112
112
|
#
|
113
113
|
# @return [Hash] translations of the fields Rails -> FileMaker
|
114
114
|
def self.create_translations
|
115
|
-
|
115
|
+
if Trophonius.config.fm_18
|
116
|
+
field_names = Trophonius::Request.get_layout_field_names(layout_name)
|
117
|
+
field_names.each do |field|
|
118
|
+
@configuration.translations.merge!(
|
119
|
+
{ "#{ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(field.to_s), separator: '_').downcase}" => "#{field}" }
|
120
|
+
)
|
121
|
+
end
|
122
|
+
else
|
123
|
+
self.first
|
124
|
+
end
|
116
125
|
@configuration.translations
|
117
126
|
end
|
118
127
|
|
@@ -166,12 +175,14 @@ module Trophonius
|
|
166
175
|
#
|
167
176
|
# @return [Record] the created record
|
168
177
|
# Model.create(fieldOne: "Data")
|
169
|
-
def self.create(fieldData)
|
178
|
+
def self.create(fieldData, portalData: {})
|
170
179
|
url =
|
171
180
|
URI(
|
172
|
-
|
173
|
-
|
174
|
-
|
181
|
+
URI.escape(
|
182
|
+
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
183
|
+
Trophonius.config.database
|
184
|
+
}/layouts/#{layout_name}/records"
|
185
|
+
)
|
175
186
|
)
|
176
187
|
new_field_data = {}
|
177
188
|
create_translations if @configuration.translations.keys.empty?
|
@@ -182,7 +193,26 @@ module Trophonius
|
|
182
193
|
new_field_data.merge!({ "#{k}" => fieldData[k] })
|
183
194
|
end
|
184
195
|
end
|
185
|
-
|
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
|
186
216
|
response = Request.make_request(url, "Bearer #{Request.get_token}", 'post', body)
|
187
217
|
if response['messages'][0]['code'] != '0'
|
188
218
|
if response['messages'][0]['code'] == '102'
|
@@ -199,9 +229,11 @@ module Trophonius
|
|
199
229
|
else
|
200
230
|
url =
|
201
231
|
URI(
|
202
|
-
|
203
|
-
Trophonius.config.
|
204
|
-
|
232
|
+
URI.escape(
|
233
|
+
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
234
|
+
Trophonius.config.database
|
235
|
+
}/layouts/#{layout_name}/records/#{response['response']['recordId']}"
|
236
|
+
)
|
205
237
|
)
|
206
238
|
ret_val = build_result(Request.make_request(url, "Bearer #{Request.get_token}", 'get', '{}')['response']['data'][0])
|
207
239
|
ret_val.send(:define_singleton_method, 'result_count') { 1 }
|
@@ -219,9 +251,11 @@ module Trophonius
|
|
219
251
|
def self.find_by(fieldData)
|
220
252
|
url =
|
221
253
|
URI(
|
222
|
-
|
223
|
-
|
224
|
-
|
254
|
+
URI.escape(
|
255
|
+
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
256
|
+
Trophonius.config.database
|
257
|
+
}/layouts/#{self.layout_name}/_find?_limit=1"
|
258
|
+
)
|
225
259
|
)
|
226
260
|
new_field_data = {}
|
227
261
|
create_translations if @configuration.translations.keys.empty?
|
@@ -260,9 +294,11 @@ module Trophonius
|
|
260
294
|
def self.find(record_id)
|
261
295
|
url =
|
262
296
|
URI(
|
263
|
-
|
264
|
-
|
265
|
-
|
297
|
+
URI.escape(
|
298
|
+
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
299
|
+
Trophonius.config.database
|
300
|
+
}/layouts/#{layout_name}/records/#{record_id}"
|
301
|
+
)
|
266
302
|
)
|
267
303
|
response = Request.make_request(url, "Bearer #{Request.get_token}", 'get', '{}')
|
268
304
|
if response['messages'][0]['code'] != '0'
|
@@ -283,9 +319,11 @@ module Trophonius
|
|
283
319
|
def self.delete(record_id)
|
284
320
|
url =
|
285
321
|
URI(
|
286
|
-
|
287
|
-
|
288
|
-
|
322
|
+
URI.escape(
|
323
|
+
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
324
|
+
Trophonius.config.database
|
325
|
+
}/layouts/#{layout_name}/records/#{record_id}"
|
326
|
+
)
|
289
327
|
)
|
290
328
|
response = Request.make_request(url, "Bearer #{Request.get_token}", 'delete', '{}')
|
291
329
|
if response['messages'][0]['code'] != '0'
|
@@ -306,9 +344,11 @@ module Trophonius
|
|
306
344
|
def self.edit(record_id, fieldData)
|
307
345
|
url =
|
308
346
|
URI(
|
309
|
-
|
310
|
-
|
311
|
-
|
347
|
+
URI.escape(
|
348
|
+
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
349
|
+
Trophonius.config.database
|
350
|
+
}/layouts/#{layout_name}/records/#{record_id}"
|
351
|
+
)
|
312
352
|
)
|
313
353
|
new_field_data = {}
|
314
354
|
create_translations if @configuration.translations.keys.empty?
|
@@ -431,16 +471,20 @@ module Trophonius
|
|
431
471
|
unless @limit.empty? || @offset.empty?
|
432
472
|
url =
|
433
473
|
URI(
|
434
|
-
|
435
|
-
Trophonius.config.
|
436
|
-
|
474
|
+
URI.escape(
|
475
|
+
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
476
|
+
Trophonius.config.database
|
477
|
+
}/layouts/#{layout_name}/records?_offset=#{@offset}&_limit=#{@limit}"
|
478
|
+
)
|
437
479
|
)
|
438
480
|
else
|
439
481
|
url =
|
440
482
|
URI(
|
441
|
-
|
442
|
-
Trophonius.config.
|
443
|
-
|
483
|
+
URI.escape(
|
484
|
+
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
485
|
+
Trophonius.config.database
|
486
|
+
}/layouts/#{layout_name}/records?_limit=#{count == 0 ? 1_000_000 : count}"
|
487
|
+
)
|
444
488
|
)
|
445
489
|
end
|
446
490
|
@limit = ''
|
data/lib/trophonius_query.rb
CHANGED
@@ -101,9 +101,11 @@ module Trophonius
|
|
101
101
|
def run_query(method, *args, &block)
|
102
102
|
url =
|
103
103
|
URI(
|
104
|
-
|
105
|
-
|
106
|
-
|
104
|
+
URI.escape(
|
105
|
+
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
106
|
+
Trophonius.config.database
|
107
|
+
}/layouts/#{@trophonius_model.layout_name}/_find"
|
108
|
+
)
|
107
109
|
)
|
108
110
|
new_field_data = @current_query.map { |_q| {} }
|
109
111
|
|
data/lib/trophonius_record.rb
CHANGED
@@ -34,9 +34,11 @@ module Trophonius
|
|
34
34
|
|
35
35
|
url =
|
36
36
|
URI(
|
37
|
-
|
38
|
-
Trophonius.config.
|
39
|
-
|
37
|
+
URI.escape(
|
38
|
+
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
39
|
+
Trophonius.config.database
|
40
|
+
}/layouts/#{layout}/_find"
|
41
|
+
)
|
40
42
|
)
|
41
43
|
|
42
44
|
if model.translations.key?(relation[:foreign_key])
|
@@ -94,9 +96,11 @@ module Trophonius
|
|
94
96
|
|
95
97
|
url =
|
96
98
|
URI(
|
97
|
-
|
98
|
-
Trophonius.config.
|
99
|
-
|
99
|
+
URI.escape(
|
100
|
+
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
101
|
+
Trophonius.config.database
|
102
|
+
}/layouts/#{layout}/_find"
|
103
|
+
)
|
100
104
|
)
|
101
105
|
|
102
106
|
if fk_model.translations.key?(relation[:foreign_key])
|
@@ -148,6 +152,36 @@ module Trophonius
|
|
148
152
|
end
|
149
153
|
end
|
150
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
|
+
|
151
185
|
##
|
152
186
|
# Saves the last changes made to the Record to FileMaker.
|
153
187
|
# Throws a FileMaker error if save failed
|
@@ -156,9 +190,11 @@ module Trophonius
|
|
156
190
|
def save
|
157
191
|
url =
|
158
192
|
URI(
|
159
|
-
|
160
|
-
|
161
|
-
|
193
|
+
URI.escape(
|
194
|
+
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
195
|
+
Trophonius.config.database
|
196
|
+
}/layouts/#{layout_name}/records/#{record_id}"
|
197
|
+
)
|
162
198
|
)
|
163
199
|
body = "{\"fieldData\": #{modified_fields.to_json}}"
|
164
200
|
response = Request.make_request(url, "Bearer #{Request.get_token}", 'patch', body)
|
@@ -173,9 +209,11 @@ module Trophonius
|
|
173
209
|
def delete
|
174
210
|
url =
|
175
211
|
URI(
|
176
|
-
|
177
|
-
|
178
|
-
|
212
|
+
URI.escape(
|
213
|
+
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
214
|
+
Trophonius.config.database
|
215
|
+
}/layouts/#{layout_name}/records/#{record_id}"
|
216
|
+
)
|
179
217
|
)
|
180
218
|
response = Request.make_request(url, "Bearer #{Request.get_token}", 'delete', '{}')
|
181
219
|
response['messages'][0]['code'] != '0' ? Error.throw_error(response['messages'][0]['code']) : true
|
@@ -191,9 +229,11 @@ module Trophonius
|
|
191
229
|
def update(fieldData)
|
192
230
|
url =
|
193
231
|
URI(
|
194
|
-
|
195
|
-
|
196
|
-
|
232
|
+
URI.escape(
|
233
|
+
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
234
|
+
Trophonius.config.database
|
235
|
+
}/layouts/#{layout_name}/records/#{record_id}"
|
236
|
+
)
|
197
237
|
)
|
198
238
|
fieldData.keys.each { |field| modifiable_fields[field] = fieldData[field] }
|
199
239
|
body = "{\"fieldData\": #{fieldData.to_json}}"
|
@@ -227,9 +267,11 @@ module Trophonius
|
|
227
267
|
def upload(container_name:, container_repetition: 1, file:)
|
228
268
|
url =
|
229
269
|
URI(
|
230
|
-
|
231
|
-
|
232
|
-
|
270
|
+
URI.escape(
|
271
|
+
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
272
|
+
Trophonius.config.database
|
273
|
+
}/layouts/#{layout_name}/records/#{record_id}/containers/#{container_name}/#{container_repetition}"
|
274
|
+
)
|
233
275
|
)
|
234
276
|
|
235
277
|
response = Request.upload_file_request(url, "Bearer #{Request.get_token}", file)
|
data/lib/trophonius_request.rb
CHANGED
@@ -4,7 +4,6 @@ require 'base64'
|
|
4
4
|
require 'trophonius_connection'
|
5
5
|
require 'uri'
|
6
6
|
require 'net/http'
|
7
|
-
|
8
7
|
module Trophonius
|
9
8
|
module Trophonius::Request
|
10
9
|
##
|
@@ -24,19 +23,20 @@ module Trophonius
|
|
24
23
|
def self.make_request(url_param, auth, method, body, params = '')
|
25
24
|
ssl_verifyhost = Trophonius.config.local_network ? 0 : 2
|
26
25
|
ssl_verifypeer = !Trophonius.config.local_network
|
27
|
-
request =
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
26
|
+
request =
|
27
|
+
Typhoeus::Request.new(
|
28
|
+
url_param,
|
29
|
+
method: method.to_sym,
|
30
|
+
body: body,
|
31
|
+
params: params,
|
32
|
+
ssl_verifyhost: ssl_verifyhost,
|
33
|
+
ssl_verifypeer: ssl_verifypeer,
|
34
|
+
headers: { 'Content-Type' => 'application/json', Authorization: auth.to_s }
|
35
|
+
)
|
36
36
|
temp = request.run
|
37
37
|
begin
|
38
38
|
JSON.parse(temp.response_body)
|
39
|
-
rescue Exception
|
39
|
+
rescue Exception => e
|
40
40
|
Error.throw_error('1631')
|
41
41
|
end
|
42
42
|
end
|
@@ -52,7 +52,7 @@ module Trophonius
|
|
52
52
|
#
|
53
53
|
# @return [JSON] parsed json of the response
|
54
54
|
def self.upload_file_request(url_param, auth, file)
|
55
|
-
url = URI(url_param)
|
55
|
+
url = URI(url_param.to_s)
|
56
56
|
|
57
57
|
https = Net::HTTP.new(url.host, url.port)
|
58
58
|
https.use_ssl = true
|
@@ -75,11 +75,7 @@ module Trophonius
|
|
75
75
|
#
|
76
76
|
# @return [String] a valid FileMaker token
|
77
77
|
def self.get_token
|
78
|
-
|
79
|
-
Connection.token
|
80
|
-
else
|
81
|
-
Connection.connect
|
82
|
-
end
|
78
|
+
Connection.valid_connection? ? Connection.token : Connection.connect
|
83
79
|
end
|
84
80
|
|
85
81
|
##
|
@@ -87,16 +83,50 @@ module Trophonius
|
|
87
83
|
#
|
88
84
|
# @return [JSON] The first record from FileMaker
|
89
85
|
def self.retrieve_first(layout_name)
|
90
|
-
url =
|
86
|
+
url =
|
87
|
+
URI(
|
88
|
+
URI.escape(
|
89
|
+
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
90
|
+
Trophonius.config.database
|
91
|
+
}/layouts/#{layout_name}/records?_limit=1"
|
92
|
+
)
|
93
|
+
)
|
91
94
|
make_request(url, "Bearer #{get_token}", 'get', '{}')
|
92
95
|
end
|
93
96
|
|
97
|
+
##
|
98
|
+
# Retrieves the fieldnames of a layout
|
99
|
+
#
|
100
|
+
# @return [JSON] The fieldnames of a layout
|
101
|
+
def self.get_layout_field_names(layout_name)
|
102
|
+
url =
|
103
|
+
URI(
|
104
|
+
URI.escape(
|
105
|
+
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
106
|
+
Trophonius.config.database
|
107
|
+
}/layouts/#{layout_name}"
|
108
|
+
)
|
109
|
+
)
|
110
|
+
begin
|
111
|
+
make_request(url, "Bearer #{get_token}", 'get', '{}')['response']['fieldMetaData'].map { |field| field['name'] }
|
112
|
+
rescue Exception
|
113
|
+
Error.throw_error('1631')
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
94
117
|
##
|
95
118
|
# Runs a FileMaker script
|
96
119
|
#
|
97
120
|
# @return [JSON] The script result from FileMaker
|
98
121
|
def self.run_script(script, scriptparameter, layout_name)
|
99
|
-
url =
|
122
|
+
url =
|
123
|
+
URI(
|
124
|
+
URI.escape(
|
125
|
+
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
126
|
+
Trophonius.config.database
|
127
|
+
}/layouts/#{layout_name}/records?_limit=1&script=#{script}&script.param=#{scriptparameter}"
|
128
|
+
)
|
129
|
+
)
|
100
130
|
make_request(url, "Bearer #{get_token}", 'get', '{}')
|
101
131
|
end
|
102
132
|
|
@@ -107,9 +137,27 @@ module Trophonius
|
|
107
137
|
def self.retrieve_all(layout_name, sort)
|
108
138
|
if !sort.empty?
|
109
139
|
sort_order = sort.to_json.to_s
|
110
|
-
url =
|
140
|
+
url =
|
141
|
+
URI(
|
142
|
+
URI.escape(
|
143
|
+
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
144
|
+
Trophonius.config.database
|
145
|
+
}/layouts/#{layout_name}/records?_limit=10000000_sort=#{sort_order}#{
|
146
|
+
Trophonius.config.count_result_script == '' ? '' : "&script=#{Trophonius.config.count_result_script}"
|
147
|
+
}"
|
148
|
+
)
|
149
|
+
)
|
111
150
|
else
|
112
|
-
url =
|
151
|
+
url =
|
152
|
+
URI(
|
153
|
+
URI.escape(
|
154
|
+
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
155
|
+
Trophonius.config.database
|
156
|
+
}/layouts/#{layout_name}/records?_limit=10000000#{
|
157
|
+
Trophonius.config.count_result_script == '' ? '' : "&script=#{Trophonius.config.count_result_script}"
|
158
|
+
}"
|
159
|
+
)
|
160
|
+
)
|
113
161
|
end
|
114
162
|
make_request(url, "Bearer #{get_token}", 'get', '{}')
|
115
163
|
end
|
@@ -0,0 +1,211 @@
|
|
1
|
+
require 'trophonius_date'
|
2
|
+
require 'trophonius_time'
|
3
|
+
require 'trophonius_error'
|
4
|
+
require 'trophonius_record'
|
5
|
+
require 'trophonius_recordset'
|
6
|
+
|
7
|
+
module Trophonius
|
8
|
+
class Trophonius::Single
|
9
|
+
attr_reader :query
|
10
|
+
def initialize(config:)
|
11
|
+
@config = config
|
12
|
+
@query = {}
|
13
|
+
@translations = {}
|
14
|
+
@all_fields = {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def where(fieldData)
|
18
|
+
url =
|
19
|
+
URI(
|
20
|
+
URI.escape(
|
21
|
+
"http#{@config[:ssl] == true ? 's' : ''}://#{@config[:host]}/fmi/data/v1/databases/#{@config[:database]}/layouts/#{
|
22
|
+
@config[:layout_name]
|
23
|
+
}/_find"
|
24
|
+
)
|
25
|
+
)
|
26
|
+
@query.merge!(query: [fieldData])
|
27
|
+
@query.merge!(limit: '10000000')
|
28
|
+
token = setup_connection
|
29
|
+
response = make_request(url, token, 'post', @query.to_json)
|
30
|
+
|
31
|
+
r_results = response['response']['data']
|
32
|
+
if response['messages'][0]['code'] != '0' && response['messages'][0]['code'] != '401'
|
33
|
+
Error.throw_error(response['messages'][0]['code'])
|
34
|
+
elsif response['messages'][0]['code'] == '401'
|
35
|
+
return RecordSet.new(@config[:layout_name], @config[:non_modifiable_fields])
|
36
|
+
else
|
37
|
+
ret_val = RecordSet.new(@config[:layout_name], @config[:non_modifiable_fields])
|
38
|
+
r_results.each do |r|
|
39
|
+
hash = build_result(r)
|
40
|
+
ret_val << hash
|
41
|
+
end
|
42
|
+
end
|
43
|
+
@query = {}
|
44
|
+
close_connection(token)
|
45
|
+
|
46
|
+
return ret_val
|
47
|
+
end
|
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
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def build_result(result)
|
79
|
+
hash = Trophonius::Record.new
|
80
|
+
hash.record_id = result['recordId']
|
81
|
+
hash.layout_name = @config[:layout_name]
|
82
|
+
hash.model_name = 'Single'
|
83
|
+
|
84
|
+
result['fieldData'].keys.each do |key|
|
85
|
+
# unless key[/\s/] || key[/\W/]
|
86
|
+
@translations.merge!(
|
87
|
+
{ "#{ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_').downcase}" => "#{key}" }
|
88
|
+
)
|
89
|
+
hash.send(:define_singleton_method, ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_')) do
|
90
|
+
hash[key]
|
91
|
+
end
|
92
|
+
unless @config[:non_modifiable_fields]&.include?(key)
|
93
|
+
@all_fields.merge!(
|
94
|
+
ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_').downcase =>
|
95
|
+
ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_')
|
96
|
+
)
|
97
|
+
hash.send(
|
98
|
+
:define_singleton_method,
|
99
|
+
"#{ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_')}="
|
100
|
+
) do |new_val|
|
101
|
+
hash[key] = new_val
|
102
|
+
hash.modifiable_fields[key] = new_val
|
103
|
+
hash.modified_fields[key] = new_val
|
104
|
+
end
|
105
|
+
end
|
106
|
+
# end
|
107
|
+
hash.merge!({ key => result['fieldData'][key] })
|
108
|
+
hash.modifiable_fields.merge!({ key => result['fieldData'][key] }) unless @config[:non_modifiable_fields]&.include?(key)
|
109
|
+
end
|
110
|
+
result['portalData'].keys.each do |key|
|
111
|
+
unless key[/\s/] || key[/\W/]
|
112
|
+
hash.send(:define_singleton_method, ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_')) do
|
113
|
+
hash[key]
|
114
|
+
end
|
115
|
+
end
|
116
|
+
result['portalData'][key].each_with_index do |inner_hash|
|
117
|
+
inner_hash.keys.each do |inner_key|
|
118
|
+
inner_method =
|
119
|
+
ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(inner_key.gsub(/\w+::/, '').to_s), separator: '_')
|
120
|
+
unless inner_method[/\s/] || inner_method[/\W/]
|
121
|
+
inner_hash.send(:define_singleton_method, inner_method.to_s) { inner_hash[inner_key] }
|
122
|
+
inner_hash.send(:define_singleton_method, 'record_id') { inner_hash['recordId'] }
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
hash.merge!({ key => result['portalData'][key] })
|
127
|
+
end
|
128
|
+
return hash
|
129
|
+
end
|
130
|
+
|
131
|
+
def make_request(url_param, token, method, body, params = '')
|
132
|
+
ssl_verifyhost = @config[:local_network] ? 0 : 2
|
133
|
+
ssl_verifypeer = !@config[:local_network]
|
134
|
+
request =
|
135
|
+
Typhoeus::Request.new(
|
136
|
+
url_param,
|
137
|
+
method: method.to_sym,
|
138
|
+
body: body,
|
139
|
+
params: params,
|
140
|
+
ssl_verifyhost: ssl_verifyhost,
|
141
|
+
ssl_verifypeer: ssl_verifypeer,
|
142
|
+
headers: { 'Content-Type' => 'application/json', Authorization: "Bearer #{token}" }
|
143
|
+
)
|
144
|
+
temp = request.run
|
145
|
+
begin
|
146
|
+
JSON.parse(temp.response_body)
|
147
|
+
rescue Exception => e
|
148
|
+
Error.throw_error('1631')
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def setup_connection
|
153
|
+
ssl_verifyhost = @config[:local_network] ? 0 : 2
|
154
|
+
ssl_verifypeer = !@config[:local_network]
|
155
|
+
url = URI(URI.escape("http#{@config[:ssl] == true ? 's' : ''}://#{@config[:host]}/fmi/data/v1/databases/#{@config[:database]}/sessions"))
|
156
|
+
request =
|
157
|
+
Typhoeus::Request.new(
|
158
|
+
url,
|
159
|
+
method: :post,
|
160
|
+
body:
|
161
|
+
if @config[:external_name].nil? || @config[:external_name].empty?
|
162
|
+
{}
|
163
|
+
else
|
164
|
+
{
|
165
|
+
fmDataSource: [{ database: @config[:external_name], username: @config[:external_username], password: @config[:external_password] }]
|
166
|
+
}.to_json
|
167
|
+
end,
|
168
|
+
params: {},
|
169
|
+
ssl_verifyhost: ssl_verifyhost,
|
170
|
+
ssl_verifypeer: ssl_verifypeer,
|
171
|
+
headers: {
|
172
|
+
'Content-Type' => 'application/json', Authorization: "Basic #{Base64.strict_encode64("#{@config[:username]}:#{@config[:password]}")}"
|
173
|
+
}
|
174
|
+
)
|
175
|
+
temp = request.run
|
176
|
+
begin
|
177
|
+
parsed = JSON.parse(temp.response_body)
|
178
|
+
rescue Exception => e
|
179
|
+
Error.throw_error('1631')
|
180
|
+
end
|
181
|
+
Error.throw_error(parsed['messages'][0]['code']) if parsed['messages'][0]['code'] != '0'
|
182
|
+
return parsed['response']['token']
|
183
|
+
end
|
184
|
+
|
185
|
+
def close_connection(token)
|
186
|
+
url =
|
187
|
+
URI(URI.escape("http#{@config[:ssl] == true ? 's' : ''}://#{@config[:host]}/fmi/data/v1/databases/#{@config[:database]}/sessions/#{token}"))
|
188
|
+
ssl_verifyhost = @config[:local_network] ? 0 : 2
|
189
|
+
ssl_verifypeer = !@config[:local_network]
|
190
|
+
|
191
|
+
request =
|
192
|
+
Typhoeus::Request.new(
|
193
|
+
url,
|
194
|
+
method: :delete,
|
195
|
+
params: {},
|
196
|
+
ssl_verifyhost: ssl_verifyhost,
|
197
|
+
ssl_verifypeer: ssl_verifypeer,
|
198
|
+
headers: { 'Content-Type' => 'application/json' }
|
199
|
+
)
|
200
|
+
temp = request.run
|
201
|
+
|
202
|
+
begin
|
203
|
+
parsed = JSON.parse(temp.response_body)
|
204
|
+
rescue Exception => e
|
205
|
+
Error.throw_error('1631')
|
206
|
+
end
|
207
|
+
Error.throw_error(parsed['messages'][0]['code']) if parsed['messages'][0]['code'] != '0'
|
208
|
+
return true
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
data/lib/trophonius_time.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trophonius
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kempen Automatisering
|
@@ -42,24 +42,18 @@ dependencies:
|
|
42
42
|
name: activesupport
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '6.0'
|
48
45
|
- - ">="
|
49
46
|
- !ruby/object:Gem::Version
|
50
|
-
version:
|
47
|
+
version: '5.0'
|
51
48
|
type: :runtime
|
52
49
|
prerelease: false
|
53
50
|
version_requirements: !ruby/object:Gem::Requirement
|
54
51
|
requirements:
|
55
|
-
- - "~>"
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
version: '6.0'
|
58
52
|
- - ">="
|
59
53
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
61
|
-
description:
|
62
|
-
Data-API.
|
54
|
+
version: '5.0'
|
55
|
+
description: A lightweight, easy to use link between Ruby (on Rails) and FileMaker
|
56
|
+
using the FileMaker Data-API.
|
63
57
|
email:
|
64
58
|
executables: []
|
65
59
|
extensions: []
|
@@ -69,6 +63,7 @@ files:
|
|
69
63
|
- lib/trophonius_config.rb
|
70
64
|
- lib/trophonius_connection.rb
|
71
65
|
- lib/trophonius_date.rb
|
66
|
+
- lib/trophonius_date_time.rb
|
72
67
|
- lib/trophonius_error.rb
|
73
68
|
- lib/trophonius_model.rb
|
74
69
|
- lib/trophonius_query.rb
|
@@ -76,6 +71,7 @@ files:
|
|
76
71
|
- lib/trophonius_recordset.rb
|
77
72
|
- lib/trophonius_redis_manager.rb
|
78
73
|
- lib/trophonius_request.rb
|
74
|
+
- lib/trophonius_single.rb
|
79
75
|
- lib/trophonius_time.rb
|
80
76
|
homepage: https://github.com/Willem-Jan/Trophonius
|
81
77
|
licenses:
|
@@ -96,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
92
|
- !ruby/object:Gem::Version
|
97
93
|
version: '0'
|
98
94
|
requirements: []
|
99
|
-
rubygems_version: 3.0.
|
95
|
+
rubygems_version: 3.0.3
|
100
96
|
signing_key:
|
101
97
|
specification_version: 4
|
102
98
|
summary: Link between Ruby (on Rails) and FileMaker.
|