trophonius 1.2.7.1 → 1.4.1
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/generators/trophonius_generator.rb +30 -0
- data/lib/generators/trophonius_model_generator.rb +23 -0
- data/lib/trophonius_model.rb +21 -2
- data/lib/trophonius_query.rb +29 -8
- data/lib/trophonius_record.rb +30 -0
- data/lib/trophonius_single.rb +64 -0
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cf39904e7500cbacbd16e8f3a78a1df4efa2ded1d64b4c6703c2a1a28c62c9c
|
4
|
+
data.tar.gz: d14b38291d4f6a49b3cd825fabdc82ce676c14d27afc738c80c42c6f61ee7144
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9508bca471f2602c71c1d8be927ed848e19d5d937f66a90bb2b71eb8d34bb59f904d3dbc1ffabaa1053c244e29d89ec25e333d83a01c9b6716f91871fee86732
|
7
|
+
data.tar.gz: 2a98ea6373a6c7ac63ba72b0f13a3852ebbaffbbfca9bab5f8e6c4aabd40e534bbc4ac05249bdd5f0c183674444977c5a2e8853e4d8bfd2ec6dd8bcb5d27afac
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
module Trophonius
|
4
|
+
class InstallGenerator < ::Rails::Generators::Base
|
5
|
+
namespace 'trophonius'
|
6
|
+
|
7
|
+
class_option :host, type: :string, default: 'location_to.your_filemakerserver.com'
|
8
|
+
class_option :database, type: :string, default: 'Name_of_your_database'
|
9
|
+
|
10
|
+
source_root File.expand_path('../templates', __FILE__)
|
11
|
+
|
12
|
+
desc 'add the config file'
|
13
|
+
|
14
|
+
def copy_initializer_file
|
15
|
+
@host = options['host']
|
16
|
+
@database = options['database']
|
17
|
+
create_file 'config/initializers/trophonius.rb',
|
18
|
+
"Trophonius.configure do |config|
|
19
|
+
config.host = '#{@host}'
|
20
|
+
config.database = '#{@database}'
|
21
|
+
config.username = Rails.application.credentials.dig(:username) # (requires >= Rails 5.2) otherwise use old secrets
|
22
|
+
config.password = Rails.application.credentials.dig(:password) # (requires >= Rails 5.2) otherwise use old secrets
|
23
|
+
config.redis_connection = false # default false, true if you want to store the token in redis
|
24
|
+
config.ssl = true # or false depending on whether https or http should be used
|
25
|
+
# USE THE NEXT OPTION WITH CAUTION
|
26
|
+
config.local_network = false # if true the ssl certificate will not be verified to allow for self-signed certificates
|
27
|
+
end"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
module Trophonius
|
4
|
+
class ModelGenerator < ::Rails::Generators::Base
|
5
|
+
namespace 'trophonius_model'
|
6
|
+
|
7
|
+
class_option :model, type: :string, default: 'MyModel'
|
8
|
+
class_option :layout, type: :string, default: 'MyModelsLayout'
|
9
|
+
|
10
|
+
source_root File.expand_path('../templates', __FILE__)
|
11
|
+
|
12
|
+
desc 'add the config file'
|
13
|
+
|
14
|
+
def copy_model_file
|
15
|
+
@model = options['model']
|
16
|
+
@layout = options['layout']
|
17
|
+
create_file "app/models/#{@model.downcase}.rb",
|
18
|
+
"class #{@model.humanize} < Trophonius::Model
|
19
|
+
config layout_name: '#{@layout}'
|
20
|
+
end"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
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_query.rb
CHANGED
@@ -42,6 +42,24 @@ module Trophonius
|
|
42
42
|
@current_query
|
43
43
|
end
|
44
44
|
|
45
|
+
##
|
46
|
+
# Returns the current portal limits
|
47
|
+
#
|
48
|
+
# @return [Hash] Hash representing the portal limits
|
49
|
+
def build_portal_limits()
|
50
|
+
@portal_limits ||= {}
|
51
|
+
end
|
52
|
+
|
53
|
+
##
|
54
|
+
# Adds a portal limit to the request
|
55
|
+
#
|
56
|
+
# @param [args] arguments containing a Hash with the format {portalName: requiredLimit}
|
57
|
+
# @return [Trophonius::Model] updated base model
|
58
|
+
def set_portal_limits(args)
|
59
|
+
args[1].current_query.build_portal_limits.merge!(args[0])
|
60
|
+
args[1]
|
61
|
+
end
|
62
|
+
|
45
63
|
##
|
46
64
|
# Adds a find request to the original query, resulting in an "Or" find-request for FileMaker
|
47
65
|
#
|
@@ -107,6 +125,7 @@ module Trophonius
|
|
107
125
|
}/layouts/#{@trophonius_model.layout_name}/_find"
|
108
126
|
)
|
109
127
|
)
|
128
|
+
|
110
129
|
new_field_data = @current_query.map { |_q| {} }
|
111
130
|
|
112
131
|
@trophonius_model.create_translations if @trophonius_model.translations.keys.empty?
|
@@ -120,21 +139,23 @@ module Trophonius
|
|
120
139
|
end
|
121
140
|
end
|
122
141
|
if @offset.nil? || @limit.nil? || @offset == '' || @limit == '' || @offset == 0 || @limit == 0
|
123
|
-
body =
|
124
|
-
if @current_sort.nil?
|
125
|
-
{ query: new_field_data, limit: '100000' }.to_json
|
126
|
-
else
|
127
|
-
{ query: new_field_data, sort: @current_sort, limit: '100000' }.to_json
|
128
|
-
end
|
142
|
+
body = @current_sort.nil? ? { query: new_field_data, limit: '100000' } : { query: new_field_data, sort: @current_sort, limit: '100000' }
|
129
143
|
else
|
130
144
|
body =
|
131
145
|
if @current_sort.nil?
|
132
|
-
{ query: new_field_data, limit: @limit.to_s, offset: @offset.to_s }
|
146
|
+
{ query: new_field_data, limit: @limit.to_s, offset: @offset.to_s }
|
133
147
|
else
|
134
|
-
{ query: new_field_data, sort: @current_sort, limit: @limit.to_s, offset: @offset.to_s }
|
148
|
+
{ query: new_field_data, sort: @current_sort, limit: @limit.to_s, offset: @offset.to_s }
|
135
149
|
end
|
136
150
|
end
|
137
151
|
|
152
|
+
if @portal_limits
|
153
|
+
portal_hash = { portal: @portal_limits.map { |portal_name, limit| "#{portal_name}" } }
|
154
|
+
body.merge!(portal_hash)
|
155
|
+
@portal_limits.each { |portal_name, limit| body.merge!({ "limit.#{portal_name}" => limit.to_s }) }
|
156
|
+
end
|
157
|
+
|
158
|
+
body = body.to_json
|
138
159
|
response = Request.make_request(url, "Bearer #{Request.get_token}", 'post', body)
|
139
160
|
if response['messages'][0]['code'] != '0'
|
140
161
|
if response['messages'][0]['code'] == '101' || response['messages'][0]['code'] == '401'
|
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
@@ -30,8 +30,10 @@ module Trophonius
|
|
30
30
|
|
31
31
|
r_results = response['response']['data']
|
32
32
|
if response['messages'][0]['code'] != '0' && response['messages'][0]['code'] != '401'
|
33
|
+
close_connection(token)
|
33
34
|
Error.throw_error(response['messages'][0]['code'])
|
34
35
|
elsif response['messages'][0]['code'] == '401'
|
36
|
+
close_connection(token)
|
35
37
|
return RecordSet.new(@config[:layout_name], @config[:non_modifiable_fields])
|
36
38
|
else
|
37
39
|
ret_val = RecordSet.new(@config[:layout_name], @config[:non_modifiable_fields])
|
@@ -46,6 +48,67 @@ module Trophonius
|
|
46
48
|
return ret_val
|
47
49
|
end
|
48
50
|
|
51
|
+
def first
|
52
|
+
url =
|
53
|
+
URI(
|
54
|
+
URI.escape(
|
55
|
+
"http#{@config[:ssl] == true ? 's' : ''}://#{@config[:host]}/fmi/data/v1/databases/#{@config[:database]}/layouts/#{
|
56
|
+
@config[:layout_name]
|
57
|
+
}/records?_limit=1"
|
58
|
+
)
|
59
|
+
)
|
60
|
+
|
61
|
+
token = setup_connection
|
62
|
+
response = make_request(url, token, 'get', @query.to_json)
|
63
|
+
|
64
|
+
r_results = response['response']['data']
|
65
|
+
if response['messages'][0]['code'] != '0' && response['messages'][0]['code'] != '401'
|
66
|
+
close_connection(token)
|
67
|
+
Error.throw_error(response['messages'][0]['code'])
|
68
|
+
elsif response['messages'][0]['code'] == '401'
|
69
|
+
close_connection(token)
|
70
|
+
return RecordSet.new(@config[:layout_name], @config[:non_modifiable_fields])
|
71
|
+
else
|
72
|
+
ret_val = RecordSet.new(@config[:layout_name], @config[:non_modifiable_fields])
|
73
|
+
r_results.each do |r|
|
74
|
+
hash = build_result(r)
|
75
|
+
ret_val << hash
|
76
|
+
end
|
77
|
+
end
|
78
|
+
close_connection(token)
|
79
|
+
|
80
|
+
return ret_val
|
81
|
+
end
|
82
|
+
|
83
|
+
def run_script(script:, scriptparameter:)
|
84
|
+
url =
|
85
|
+
URI(
|
86
|
+
URI.escape(
|
87
|
+
"http#{@config[:ssl] == true ? 's' : ''}://#{@config[:host]}/fmi/data/v1/databases/#{@config[:database]}/layouts/#{
|
88
|
+
@config[:layout_name]
|
89
|
+
}/records?_limit=1&script=#{script}&script.param=#{scriptparameter}"
|
90
|
+
)
|
91
|
+
)
|
92
|
+
|
93
|
+
token = setup_connection
|
94
|
+
result = make_request(url, "Bearer #{token}", 'get', '{}')
|
95
|
+
ret_val = ''
|
96
|
+
|
97
|
+
if result['messages'][0]['code'] != '0'
|
98
|
+
close_connection(token)
|
99
|
+
Error.throw_error(result['messages'][0]['code'])
|
100
|
+
elsif result['response']['scriptResult'] == '403'
|
101
|
+
close_connection(token)
|
102
|
+
Error.throw_error(403)
|
103
|
+
else
|
104
|
+
ret_val = result['response']['scriptResult']
|
105
|
+
end
|
106
|
+
|
107
|
+
close_connection(token)
|
108
|
+
|
109
|
+
return ret_val
|
110
|
+
end
|
111
|
+
|
49
112
|
private
|
50
113
|
|
51
114
|
def build_result(result)
|
@@ -118,6 +181,7 @@ module Trophonius
|
|
118
181
|
begin
|
119
182
|
JSON.parse(temp.response_body)
|
120
183
|
rescue Exception => e
|
184
|
+
close_connection(token)
|
121
185
|
Error.throw_error('1631')
|
122
186
|
end
|
123
187
|
end
|
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trophonius
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kempen Automatisering
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2019-12-16 00:00:00.000000000 Z
|
@@ -54,11 +54,13 @@ dependencies:
|
|
54
54
|
version: '5.0'
|
55
55
|
description: A lightweight, easy to use link between Ruby (on Rails) and FileMaker
|
56
56
|
using the FileMaker Data-API.
|
57
|
-
email:
|
57
|
+
email:
|
58
58
|
executables: []
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- lib/generators/trophonius_generator.rb
|
63
|
+
- lib/generators/trophonius_model_generator.rb
|
62
64
|
- lib/trophonius.rb
|
63
65
|
- lib/trophonius_config.rb
|
64
66
|
- lib/trophonius_connection.rb
|
@@ -77,7 +79,7 @@ homepage: https://github.com/Willem-Jan/Trophonius
|
|
77
79
|
licenses:
|
78
80
|
- MIT
|
79
81
|
metadata: {}
|
80
|
-
post_install_message:
|
82
|
+
post_install_message:
|
81
83
|
rdoc_options: []
|
82
84
|
require_paths:
|
83
85
|
- lib
|
@@ -93,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
95
|
version: '0'
|
94
96
|
requirements: []
|
95
97
|
rubygems_version: 3.0.3
|
96
|
-
signing_key:
|
98
|
+
signing_key:
|
97
99
|
specification_version: 4
|
98
100
|
summary: Link between Ruby (on Rails) and FileMaker.
|
99
101
|
test_files: []
|