trophonius 1.4.5.5 → 2.1.5
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 → config.rb} +10 -3
- data/lib/{trophonius_connection.rb → connectors/connection.rb} +115 -101
- data/lib/connectors/connection_manager.rb +39 -0
- data/lib/connectors/database_request.rb +151 -0
- data/lib/{trophonius_redis_manager.rb → connectors/redis_manager.rb} +9 -8
- data/lib/debug_printer.rb +11 -0
- data/lib/{trophonius_error.rb → error.rb} +3 -3
- data/lib/{trophonius_date.rb → fm_date.rb} +1 -1
- data/lib/fm_time.rb +11 -0
- data/lib/generators/trophonius_generator.rb +1 -0
- data/lib/model.rb +394 -0
- data/lib/{trophonius_query.rb → query.rb} +44 -57
- data/lib/{trophonius_record.rb → record.rb} +104 -116
- data/lib/{trophonius_recordset.rb → recordset.rb} +5 -6
- data/lib/{trophonius_single.rb → single.rb} +13 -59
- data/lib/translator.rb +15 -0
- data/lib/trophonius.rb +14 -8
- metadata +19 -16
- data/lib/trophonius_model.rb +0 -511
- data/lib/trophonius_request.rb +0 -173
- data/lib/trophonius_time.rb +0 -6
- /data/lib/{trophonius_date_time.rb → fm_date_time.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ecc1055be56103548bd16bca808ff5a939e0ee7bbb2650d92f14cfb8e4d18da
|
4
|
+
data.tar.gz: 5b7319bc6b276601a9208db83771f7e2b94c1a981d43f752f5af74370ddad44d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2922556fcf044ffd33a83f7b2645d866e22f4be011813c833eecbb087e9563e9c9f15c72954645544ffc6bad2982b1f66057de0696f35febd3be9878f6bdf006
|
7
|
+
data.tar.gz: bf26bdb6b2ce439f4d302fdd3075c9fc07d73acbdfe0dd0ec5981e2ebad5c2ef89735a69d419e812b77bc965f72f730c8fef1335fae0f04d8355d95597ef93d8
|
@@ -1,7 +1,12 @@
|
|
1
|
+
# require 'time'
|
2
|
+
# require 'date_time'
|
3
|
+
# require 'date'
|
4
|
+
|
1
5
|
require 'active_support/configurable'
|
6
|
+
require 'ethon'
|
2
7
|
|
3
8
|
module Trophonius
|
4
|
-
class
|
9
|
+
class Configuration # :nodoc:
|
5
10
|
include ActiveSupport::Configurable
|
6
11
|
|
7
12
|
config_accessor(:host) { '127.0.0.1' }
|
@@ -13,15 +18,17 @@ module Trophonius
|
|
13
18
|
config_accessor(:username) { 'Admin' }
|
14
19
|
config_accessor(:password) { '' }
|
15
20
|
config_accessor(:ssl) { true }
|
16
|
-
config_accessor(:fm_18) {
|
21
|
+
config_accessor(:fm_18) { true }
|
17
22
|
config_accessor(:count_result_script) { '' }
|
18
23
|
config_accessor(:layout_name) { '' }
|
19
24
|
config_accessor(:non_modifiable_fields) { [] }
|
20
|
-
config_accessor(:all_fields) { {} }
|
21
25
|
config_accessor(:translations) { {} }
|
22
26
|
config_accessor(:has_many_relations) { {} }
|
23
27
|
config_accessor(:belongs_to_relations) { {} }
|
24
28
|
config_accessor(:local_network) { false }
|
25
29
|
config_accessor(:redis_connection) { false }
|
30
|
+
config_accessor(:redis_no_verify) { false }
|
31
|
+
config_accessor(:pool_size) { 5 }
|
32
|
+
config_accessor(:debug) { false }
|
26
33
|
end
|
27
34
|
end
|
@@ -1,139 +1,167 @@
|
|
1
1
|
require 'time'
|
2
2
|
require 'base64'
|
3
|
-
require '
|
4
|
-
require '
|
3
|
+
require 'securerandom'
|
4
|
+
require 'connectors/redis_manager'
|
5
|
+
require 'debug_printer'
|
6
|
+
|
5
7
|
module Trophonius
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
#
|
10
|
-
# @return [String] the *token* used to connect with the FileMaker data api
|
8
|
+
class Connection
|
9
|
+
include DebugPrinter
|
10
|
+
attr_reader :id
|
11
11
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
Trophonius::RedisManager.get_key(key: 'token')
|
17
|
-
else
|
18
|
-
@token = setup_connection
|
19
|
-
@last_connection = Time.now
|
20
|
-
@token
|
21
|
-
end
|
12
|
+
def initialize
|
13
|
+
@id = SecureRandom.uuid
|
14
|
+
@token = ''
|
15
|
+
connect
|
22
16
|
end
|
23
17
|
|
24
18
|
##
|
25
|
-
#
|
26
|
-
#
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
if Trophonius.config.redis_connection
|
31
|
-
Trophonius::RedisManager.set_key(key: 'token', value: '')
|
32
|
-
Trophonius::RedisManager.set_key(key: 'last_connection', value: nil)
|
19
|
+
# Returns the last received token
|
20
|
+
# @return [String] the last valid *token* used to connect with the FileMaker data api
|
21
|
+
def token
|
22
|
+
if valid_connection?
|
23
|
+
Trophonius.config.redis_connection ? Trophonius::RedisManager.get_key(key: 'token') : @token
|
33
24
|
else
|
34
|
-
|
25
|
+
connect
|
35
26
|
end
|
36
|
-
|
37
|
-
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# Disconnects from the FileMaker server
|
31
|
+
#
|
32
|
+
def disconnect
|
38
33
|
uri = URI::RFC2396_Parser.new
|
39
34
|
url =
|
40
35
|
URI(
|
41
36
|
uri.escape(
|
42
|
-
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
37
|
+
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
38
|
+
Trophonius.config.database
|
39
|
+
}/sessions/#{Trophonius.config.redis_connection ? Trophonius::RedisManager.get_key(key: 'token') : @token}"
|
43
40
|
)
|
44
41
|
)
|
42
|
+
ssl_verifyhost = Trophonius.config.local_network ? 0 : 2
|
43
|
+
ssl_verifypeer = !Trophonius.config.local_network
|
44
|
+
|
45
45
|
request =
|
46
46
|
Typhoeus::Request.new(
|
47
47
|
url,
|
48
|
-
method: :
|
49
|
-
body:
|
50
|
-
if Trophonius.config.external_name.empty?
|
51
|
-
{}
|
52
|
-
else
|
53
|
-
{
|
54
|
-
fmDataSource: [
|
55
|
-
{
|
56
|
-
database: Trophonius.config.external_name,
|
57
|
-
username: Trophonius.config.external_username,
|
58
|
-
password: Trophonius.config.external_password
|
59
|
-
}
|
60
|
-
]
|
61
|
-
}.to_json
|
62
|
-
end,
|
48
|
+
method: :delete,
|
63
49
|
params: {},
|
64
50
|
ssl_verifyhost: ssl_verifyhost,
|
65
51
|
ssl_verifypeer: ssl_verifypeer,
|
66
|
-
headers: {
|
67
|
-
'Content-Type' => 'application/json',
|
68
|
-
Authorization: "Basic #{Base64.strict_encode64("#{Trophonius.config.username}:#{Trophonius.config.password}")}"
|
69
|
-
}
|
52
|
+
headers: { 'Content-Type' => 'application/json' }
|
70
53
|
)
|
71
54
|
temp = request.run
|
72
|
-
body = temp.response_body
|
73
|
-
headers = temp.headers
|
74
|
-
code = temp.code
|
75
55
|
|
76
56
|
begin
|
77
|
-
parsed = JSON.parse(
|
78
|
-
|
57
|
+
parsed = JSON.parse(temp.response_body)
|
58
|
+
|
59
|
+
DebugPrinter.print_debug('RECEIVED DISCONNECT', parsed)
|
60
|
+
rescue StandardError => e
|
79
61
|
puts e
|
80
62
|
puts e.backtrace
|
81
63
|
Error.throw_error('1631')
|
82
64
|
end
|
83
65
|
Error.throw_error(parsed['messages'][0]['code']) if parsed['messages'][0]['code'] != '0'
|
84
|
-
|
66
|
+
Trophonius::RedisManager.disconnect! if Trophonius.config.redis_connection
|
67
|
+
@token = nil
|
68
|
+
@last_connection = nil
|
69
|
+
true
|
85
70
|
end
|
86
71
|
|
72
|
+
private
|
73
|
+
|
87
74
|
##
|
88
|
-
#
|
75
|
+
# Creates a new connection to FileMaker
|
89
76
|
#
|
90
|
-
|
77
|
+
# @return [String] the *token* used to connect with the FileMaker data api
|
78
|
+
|
79
|
+
def connect
|
80
|
+
if Trophonius.config.redis_connection
|
81
|
+
Trophonius::RedisManager.set_key(key: 'token', value: setup_connection)
|
82
|
+
Trophonius::RedisManager.set_key(key: 'last_connection', value: Time.now)
|
83
|
+
Trophonius::RedisManager.get_key(key: 'token')
|
84
|
+
else
|
85
|
+
@token = setup_connection
|
86
|
+
@last_connection = Time.now
|
87
|
+
@token
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def reset_token
|
92
|
+
if Trophonius.config.redis_connection
|
93
|
+
Trophonius::RedisManager.set_key(key: 'token', value: '')
|
94
|
+
Trophonius::RedisManager.set_key(key: 'last_connection', value: nil)
|
95
|
+
else
|
96
|
+
@token = ''
|
97
|
+
@last_connection = nil
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def fm_external_data_source
|
102
|
+
if Trophonius.config.external_name.empty?
|
103
|
+
{}
|
104
|
+
else
|
105
|
+
{
|
106
|
+
fmDataSource: [
|
107
|
+
{
|
108
|
+
database: Trophonius.config.external_name,
|
109
|
+
username: Trophonius.config.external_username,
|
110
|
+
password: Trophonius.config.external_password
|
111
|
+
}
|
112
|
+
]
|
113
|
+
}.to_json
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
##
|
118
|
+
# Creates and runs a HTTP request to create a new data api connection
|
119
|
+
# This method throws an error when the request returns with a HTTP error or a FileMaker error
|
120
|
+
# @return [String] the *token* used to connect with the FileMaker data api if successful
|
121
|
+
|
122
|
+
def setup_connection
|
123
|
+
reset_token
|
124
|
+
|
91
125
|
uri = URI::RFC2396_Parser.new
|
92
126
|
url =
|
93
127
|
URI(
|
94
128
|
uri.escape(
|
95
|
-
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
96
|
-
Trophonius.config.database
|
97
|
-
}/sessions/#{Trophonius.config.redis_connection ? Trophonius::RedisManager.get_key(key: 'token') : @token}"
|
129
|
+
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/sessions"
|
98
130
|
)
|
99
131
|
)
|
100
132
|
ssl_verifyhost = Trophonius.config.local_network ? 0 : 2
|
101
133
|
ssl_verifypeer = !Trophonius.config.local_network
|
102
|
-
|
103
134
|
request =
|
104
135
|
Typhoeus::Request.new(
|
105
136
|
url,
|
106
|
-
method: :
|
137
|
+
method: :post,
|
138
|
+
body: fm_external_data_source,
|
107
139
|
params: {},
|
108
140
|
ssl_verifyhost: ssl_verifyhost,
|
109
141
|
ssl_verifypeer: ssl_verifypeer,
|
110
|
-
headers: {
|
142
|
+
headers: {
|
143
|
+
'Content-Type' => 'application/json',
|
144
|
+
Authorization: "Basic #{Base64.strict_encode64("#{Trophonius.config.username}:#{Trophonius.config.password}")}"
|
145
|
+
}
|
111
146
|
)
|
112
147
|
temp = request.run
|
148
|
+
body = temp.response_body
|
113
149
|
|
114
150
|
begin
|
115
|
-
parsed = JSON.parse(
|
116
|
-
rescue
|
151
|
+
parsed = JSON.parse(body)
|
152
|
+
rescue StandardError => e
|
153
|
+
puts e
|
154
|
+
puts e.backtrace
|
117
155
|
Error.throw_error('1631')
|
118
156
|
end
|
119
157
|
Error.throw_error(parsed['messages'][0]['code']) if parsed['messages'][0]['code'] != '0'
|
120
|
-
|
121
|
-
@token = nil
|
122
|
-
@last_connection = nil
|
123
|
-
true
|
124
|
-
end
|
125
|
-
|
126
|
-
##
|
127
|
-
# Returns the last received token
|
128
|
-
# @return [String] the last valid *token* used to connect with the FileMaker data api
|
129
|
-
def self.token
|
130
|
-
Trophonius.config.redis_connection ? Trophonius::RedisManager.get_key(key: 'token') : @token
|
158
|
+
parsed['response']['token']
|
131
159
|
end
|
132
160
|
|
133
161
|
##
|
134
162
|
# Returns the receive time of the last received token
|
135
163
|
# @return [Time] Returns the receive time of the last received token
|
136
|
-
def
|
164
|
+
def last_connection
|
137
165
|
last = Trophonius.config.redis_connection ? Trophonius::RedisManager.get_key(key: 'last_connection') : nil
|
138
166
|
last = last.nil? ? nil : Time.parse(last)
|
139
167
|
Trophonius.config.redis_connection ? last : @last_connection
|
@@ -142,37 +170,23 @@ module Trophonius
|
|
142
170
|
##
|
143
171
|
# Tests whether the FileMaker token is still valid
|
144
172
|
# @return [Boolean] True if the token is valid False if invalid
|
145
|
-
def
|
146
|
-
|
147
|
-
url =
|
148
|
-
URI(
|
149
|
-
uri.escape(
|
150
|
-
"http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
|
151
|
-
Trophonius.config.database
|
152
|
-
}/layouts/#{Trophonius.config.layout_name}/records?_limit=1"
|
153
|
-
)
|
154
|
-
)
|
155
|
-
begin
|
156
|
-
request =
|
157
|
-
Typhoeus::Request.new(
|
158
|
-
url,
|
159
|
-
method: :get, body: {}, params: {}, headers: { 'Content-Type' => 'application/json', Authorization: "Bearer #{token}" }
|
160
|
-
)
|
161
|
-
temp = request.run
|
162
|
-
json_parsed = JSON.parse(temp.response_body)
|
173
|
+
def test_connection
|
174
|
+
return last_connection.nil? || last_connection < Time.now - (15 * 60) if Trophonius.config.layout_name == ''
|
163
175
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
176
|
+
path = "/layouts/#{Trophonius.config.layout_name}/records?_limit=1"
|
177
|
+
response =
|
178
|
+
Trophonius::DatabaseRequest.make_request(path, :get, {}, bypass_queue_with: "Bearer #{@token}")
|
179
|
+
response['messages'][0]['code'] == '0'
|
180
|
+
rescue StandardError => e
|
181
|
+
puts e
|
182
|
+
puts e.backtrace
|
183
|
+
false
|
170
184
|
end
|
171
185
|
|
172
186
|
##
|
173
187
|
# Returns whether the current connection is still valid
|
174
188
|
# @return [Boolean] True if the connection is valid False if invalid
|
175
|
-
def
|
189
|
+
def valid_connection?
|
176
190
|
if Trophonius.config.layout_name != '' && test_connection == false
|
177
191
|
false
|
178
192
|
else
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'debug_printer'
|
2
|
+
module Trophonius
|
3
|
+
class ConnectionManager
|
4
|
+
include DebugPrinter
|
5
|
+
def initialize
|
6
|
+
@connections = {}
|
7
|
+
Trophonius.config.pool_size.times do
|
8
|
+
connection = Connection.new
|
9
|
+
@connections[connection.id] = { connection: connection, queue: [] }
|
10
|
+
|
11
|
+
DebugPrinter.print_debug('CONNECTION CREATED', @connections[connection.id].inspect)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def enqueue(id)
|
16
|
+
connection = @connections.values.min_by { |c| c[:queue].length }
|
17
|
+
connection[:queue].push(id)
|
18
|
+
puts "in,#{connection[:connection].id},#{connection[:connection].token},#{connection[:queue].length}" if Trophonius.config.debug == true
|
19
|
+
auth_header_bearer(connection[:connection].id)
|
20
|
+
end
|
21
|
+
|
22
|
+
def dequeue(id)
|
23
|
+
connection = @connections.values.find { |c| c[:queue].include?(id) }
|
24
|
+
connection[:queue].delete_if { |q_id| q_id == id }
|
25
|
+
puts "out,#{connection[:connection].id},#{connection[:connection].token},#{connection[:queue].length}" if Trophonius.config.debug == true
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
|
29
|
+
def disconnect_all
|
30
|
+
@connections.each { |_connection_id, connection| connection[:connection].disconnect }
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def auth_header_bearer(id)
|
36
|
+
"Bearer #{@connections.dig(id, :connection).token}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'base64'
|
4
|
+
require 'connectors/connection_manager'
|
5
|
+
require 'debug_printer'
|
6
|
+
require 'typhoeus'
|
7
|
+
require 'uri'
|
8
|
+
require 'securerandom'
|
9
|
+
require 'net/http'
|
10
|
+
|
11
|
+
module Trophonius
|
12
|
+
module DatabaseRequest
|
13
|
+
include DebugPrinter
|
14
|
+
##
|
15
|
+
# Crafts and runs a HTTP request of any type
|
16
|
+
#
|
17
|
+
# @param [URI] url_path: the url to make the request to
|
18
|
+
#
|
19
|
+
# @param [String] method: the type of HTTP request to make (i.e. get)
|
20
|
+
#
|
21
|
+
# @param [JSONString] body: the body of the HTTP request
|
22
|
+
#
|
23
|
+
# @param [String] params: optional parameters added to the request
|
24
|
+
#
|
25
|
+
# @param [String] bypass_queue_with: optional way to bypass the ConnectionManager
|
26
|
+
#
|
27
|
+
# @return [JSON] parsed json of the response
|
28
|
+
def self.make_request(url_path, method, body, params = '', bypass_queue_with: '')
|
29
|
+
ssl_verifyhost = Trophonius.config.local_network ? 0 : 2
|
30
|
+
ssl_verifypeer = !Trophonius.config.local_network
|
31
|
+
base_url = "http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}"
|
32
|
+
uri = URI::RFC2396_Parser.new
|
33
|
+
url =
|
34
|
+
URI(
|
35
|
+
uri.escape("#{base_url}/#{url_path}")
|
36
|
+
)
|
37
|
+
|
38
|
+
id = SecureRandom.uuid
|
39
|
+
auth = bypass_queue_with.empty? ? auth_header_bearer(id) : bypass_queue_with
|
40
|
+
|
41
|
+
request =
|
42
|
+
Typhoeus::Request.new(
|
43
|
+
url,
|
44
|
+
method: method.to_sym,
|
45
|
+
body: body,
|
46
|
+
params: params,
|
47
|
+
ssl_verifyhost: ssl_verifyhost,
|
48
|
+
ssl_verifypeer: ssl_verifypeer,
|
49
|
+
headers: { 'Content-Type' => 'application/json', Authorization: auth }
|
50
|
+
)
|
51
|
+
|
52
|
+
DebugPrinter.print_debug('USED URL', url)
|
53
|
+
DebugPrinter.print_debug('SENT BODY', body)
|
54
|
+
|
55
|
+
temp = request.run
|
56
|
+
|
57
|
+
Trophonius.connection_manager.dequeue(id) if bypass_queue_with.empty?
|
58
|
+
|
59
|
+
begin
|
60
|
+
response_body = JSON.parse(temp.response_body)
|
61
|
+
DebugPrinter.print_debug('RECEIVED BODY', JSON.pretty_generate(response_body))
|
62
|
+
response_body
|
63
|
+
rescue StandardError => e
|
64
|
+
puts e
|
65
|
+
puts e.backtrace
|
66
|
+
Error.throw_error('1631')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# Crafts and runs a HTTP request for uploading a file to a container
|
72
|
+
#
|
73
|
+
# @param [URI] urlparam: the url to make the request to
|
74
|
+
#
|
75
|
+
# @param [String] auth: the authentication required for the request
|
76
|
+
#
|
77
|
+
# @param [Tempfile or File] file: file to upload
|
78
|
+
#
|
79
|
+
# @return [JSON] parsed json of the response
|
80
|
+
def self.upload_file_request(url_param, file)
|
81
|
+
base_url = "http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}"
|
82
|
+
url = URI("#{base_url}/#{url_param}")
|
83
|
+
|
84
|
+
https = Net::HTTP.new(url.host, url.port)
|
85
|
+
https.use_ssl = true
|
86
|
+
|
87
|
+
id = SecureRandom.uuid
|
88
|
+
request = Net::HTTP::Post.new(url)
|
89
|
+
request['Authorization'] = auth_header_bearer(id)
|
90
|
+
request['Content-Type'] = 'multipart/form-data;'
|
91
|
+
form_data = [['upload', file]]
|
92
|
+
request.set_form form_data, 'multipart/form-data'
|
93
|
+
response = https.request(request)
|
94
|
+
Trophonius.connection_manager.dequeue(id)
|
95
|
+
begin
|
96
|
+
JSON.parse(response.read_body)
|
97
|
+
rescue StandardError
|
98
|
+
Error.throw_error('1631')
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
##
|
103
|
+
# Gets a valid auth header containing the access token
|
104
|
+
#
|
105
|
+
# @return [String] a valid auth header containing the access token
|
106
|
+
def self.auth_header_bearer(id)
|
107
|
+
Trophonius.connection_manager.enqueue(id)
|
108
|
+
end
|
109
|
+
|
110
|
+
##
|
111
|
+
# Retrieves the first record from FileMaker
|
112
|
+
#
|
113
|
+
# @return [JSON] The first record from FileMaker
|
114
|
+
def self.retrieve_first(layout_name)
|
115
|
+
make_request("layouts/#{layout_name}/records?_limit=1", 'get', '{}')
|
116
|
+
end
|
117
|
+
|
118
|
+
##
|
119
|
+
# Retrieves the fieldnames of a layout
|
120
|
+
#
|
121
|
+
# @return [JSON] The fieldnames of a layout
|
122
|
+
def self.get_layout_field_names(layout_name)
|
123
|
+
make_request("layouts/#{layout_name}", 'get', '{}')['response']['fieldMetaData'].map { |field| field['name'] }
|
124
|
+
rescue StandardError => e
|
125
|
+
puts e
|
126
|
+
puts e.backtrace
|
127
|
+
Error.throw_error('1631')
|
128
|
+
end
|
129
|
+
|
130
|
+
##
|
131
|
+
# Runs a FileMaker script
|
132
|
+
#
|
133
|
+
# @return [JSON] The script result from FileMaker
|
134
|
+
def self.run_script(script, scriptparameter, layout_name)
|
135
|
+
make_request("/layouts/#{layout_name}/records?_limit=1&script=#{script}&script.param=#{scriptparameter}", 'get', '{}')
|
136
|
+
end
|
137
|
+
|
138
|
+
##
|
139
|
+
# Retrieves the 10000000 records from FileMaker
|
140
|
+
#
|
141
|
+
# @return [JSON] The first 10000000 records from FileMaker
|
142
|
+
def self.retrieve_all(layout_name, sort)
|
143
|
+
path = "layouts/#{layout_name}/records?_limit=10000000#{
|
144
|
+
Trophonius.config.count_result_script == '' ? '' : "&script=#{Trophonius.config.count_result_script}"
|
145
|
+
}"
|
146
|
+
path += "&_sort=#{sort_order}" if sort.present?
|
147
|
+
path += "&script=#{Trophonius.config.count_result_script}" if Trophonius.config.count_result_script.present?
|
148
|
+
make_request(path, 'get', '{}')
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
@@ -2,14 +2,15 @@ module Trophonius
|
|
2
2
|
# the RedisManager module is used to create a (single) connection to a redis store.
|
3
3
|
module Trophonius::RedisManager
|
4
4
|
def self.connect
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
return unless Trophonius.config.redis_connection
|
6
|
+
|
7
|
+
redis_url = ENV.fetch('REDIS_URL')
|
8
|
+
options = {}
|
9
|
+
options.merge!(url: redis_url) if redis_url && redis_url != ''
|
10
|
+
options.merge!(ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE }) if Trophonius.config.redis_no_verify
|
11
|
+
@redis ||= Redis.new(options)
|
12
|
+
|
13
|
+
nil
|
13
14
|
end
|
14
15
|
|
15
16
|
##
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Trophonius
|
2
|
+
module DebugPrinter
|
3
|
+
def self.print_debug(open_close_message, message)
|
4
|
+
return unless Trophonius.config.debug == true
|
5
|
+
|
6
|
+
puts "======== #{open_close_message} ========"
|
7
|
+
puts message
|
8
|
+
puts "======== #{open_close_message} ========"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'json'
|
2
|
-
require '
|
2
|
+
require 'config'
|
3
3
|
|
4
4
|
module Trophonius
|
5
|
-
module
|
5
|
+
module Error
|
6
6
|
class RecordNotFoundError < StandardError; end # :nodoc:
|
7
7
|
class FieldUnexistingError < NoMethodError; end # :nodoc:
|
8
8
|
class ScriptUnexistingError < NoMethodError; end # :nodoc:
|
@@ -89,7 +89,7 @@ module Trophonius
|
|
89
89
|
when '101'
|
90
90
|
raise RecordNotFoundError.new, "Record #{more_info} was not found"
|
91
91
|
when '102'
|
92
|
-
raise FieldUnexistingError.new, 'Field does not exist' if more_info.zero?
|
92
|
+
raise FieldUnexistingError.new, 'Field does not exist' if more_info.is_a?(Integer) && more_info.zero?
|
93
93
|
|
94
94
|
raise FieldUnexistingError.new, "Following field(s) #{more_info} do not exist on layout #{layout_info}"
|
95
95
|
when '103'
|
data/lib/fm_time.rb
ADDED
@@ -22,6 +22,7 @@ module Trophonius
|
|
22
22
|
config.password = Rails.application.credentials.dig(:password) # (requires >= Rails 5.2) otherwise use old secrets
|
23
23
|
config.redis_connection = false # default false, true if you want to store the token in redis
|
24
24
|
config.ssl = true # or false depending on whether https or http should be used
|
25
|
+
config.fm_18 = true
|
25
26
|
# USE THE NEXT OPTION WITH CAUTION
|
26
27
|
config.local_network = false # if true the ssl certificate will not be verified to allow for self-signed certificates
|
27
28
|
end"
|