trophonius 1.3.0 → 1.4.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8cddd8754bce7e159a2e6930652e3ee4579e5c2ec1b10e2dc8559c7d4c07ec9
4
- data.tar.gz: 66bbed12eacca09ebea09541ea5698e5910afa6110f4da00f7d588d1a41d2f27
3
+ metadata.gz: a0949793d21332ffb6c5af748bfa63343381852320139c87d0ac42eebb081e9a
4
+ data.tar.gz: 9a15a879d7aa1ba1cec4429922336d455cc0b7ceb9976dc0eb5208a4e596ba61
5
5
  SHA512:
6
- metadata.gz: 9aa8781709105e8485d56cc7c34f0f40558f34a664eb2707eb7047518896e2676624fda3e34af4153b43bbcf15fce48ea8c4e355144e52e4bff9a59cc9a7e22e
7
- data.tar.gz: cef048e4cd82415827901a735c256f55cd0b3c5741b34b19c4922bb3178985e9c3dc4de3b88ca6a0bcd8c18682af2f03fcd7059a24649d7320f21133c01135e8
6
+ metadata.gz: fbc67931cd98a46274da0d322d8d3e7e5a5a45e65cce58f38e24eb151d9ff27967272f64000b66b33afdf3ad56266db63a3965b32ffaa1568204f373639f9928
7
+ data.tar.gz: c4311588cec27ccaa4af3f5112cc90a65d266395e54d27d0e105a25ee17aeff07ec260cb788fa430343338308f9526b743c0830fa8aa213da26ee98d424d97b2
@@ -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
@@ -7,6 +7,7 @@ require 'trophonius_error'
7
7
  module Trophonius
8
8
  class Trophonius::Query
9
9
  attr_reader :response
10
+ attr_accessor :presort_script, :presort_scriptparam, :prerequest_script, :prerequest_scriptparam, :post_request_script, :post_request_scriptparam
10
11
 
11
12
  ##
12
13
  # Creates a new instance of the Trophonius::Query class
@@ -20,6 +21,12 @@ module Trophonius
20
21
  @trophonius_model = trophonius_model
21
22
  @limit = limit
22
23
  @offset = offset
24
+ @presort_script = ''
25
+ @presort_scriptparam = ''
26
+ @prerequest_script = ''
27
+ @prerequest_scriptparam = ''
28
+ @post_request_script = ''
29
+ @post_request_scriptparam = ''
23
30
  end
24
31
 
25
32
  ##
@@ -42,6 +49,84 @@ module Trophonius
42
49
  @current_query
43
50
  end
44
51
 
52
+ ##
53
+ # Returns the current portal limits
54
+ #
55
+ # @return [Hash] Hash representing the portal limits
56
+ def build_portal_limits()
57
+ @portal_limits ||= {}
58
+ end
59
+
60
+ ##
61
+ # Adds a portal limit to the request
62
+ #
63
+ # @param [args] arguments containing a Hash with the format {portalName: requiredLimit}
64
+ # @return [Trophonius::Model] updated base model
65
+ def set_portal_limits(args)
66
+ args[1].current_query.build_portal_limits.merge!(args[0])
67
+ args[1]
68
+ end
69
+
70
+ ##
71
+ # Adds a post-request script to the request
72
+ #
73
+ # @param [args] arguments containing a String with the name of the script
74
+ # @return [Trophonius::Model] updated base model
75
+ def set_post_request_script(args)
76
+ args[1].current_query.post_request_script = args[0]
77
+ args[1]
78
+ end
79
+
80
+ ##
81
+ # Adds a post-request scriptparameter to the request
82
+ #
83
+ # @param [args] arguments containing a String with the name of the scriptparameter
84
+ # @return [Trophonius::Model] updated base model
85
+ def set_post_request_script_param(args)
86
+ args[1].current_query.post_request_scriptparam = args[0]
87
+ args[1]
88
+ end
89
+
90
+ ##
91
+ # Adds a pre-request script to the request
92
+ #
93
+ # @param [args] arguments containing a String with the name of the script
94
+ # @return [Trophonius::Model] updated base model
95
+ def set_prerequest_script(args)
96
+ args[1].current_query.prerequest_script = args[0]
97
+ args[1]
98
+ end
99
+
100
+ ##
101
+ # Adds a pre-request scriptparameter to the request
102
+ #
103
+ # @param [args] arguments containing a String with the name of the scriptparameter
104
+ # @return [Trophonius::Model] updated base model
105
+ def set_prerequest_script_param(args)
106
+ args[1].current_query.prerequest_scriptparam = args[0]
107
+ args[1]
108
+ end
109
+
110
+ ##
111
+ # Adds a pre-sort script to the request
112
+ #
113
+ # @param [args] arguments containing a String with the name of the script
114
+ # @return [Trophonius::Model] updated base model
115
+ def set_presort_script(args)
116
+ args[1].current_query.presort_script = args[0]
117
+ args[1]
118
+ end
119
+
120
+ ##
121
+ # Adds a pre-request scriptparameter to the request
122
+ #
123
+ # @param [args] arguments containing a String with the name of the scriptparameter
124
+ # @return [Trophonius::Model] updated base model
125
+ def set_presort_script_param(args)
126
+ args[1].current_query.presort_scriptparam = args[0]
127
+ args[1]
128
+ end
129
+
45
130
  ##
46
131
  # Adds a find request to the original query, resulting in an "Or" find-request for FileMaker
47
132
  #
@@ -120,22 +205,40 @@ module Trophonius
120
205
  end
121
206
  end
122
207
  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
208
+ body = @current_sort.nil? ? { query: new_field_data, limit: '100000' } : { query: new_field_data, sort: @current_sort, limit: '100000' }
129
209
  else
130
210
  body =
131
211
  if @current_sort.nil?
132
- { query: new_field_data, limit: @limit.to_s, offset: @offset.to_s }.to_json
212
+ { query: new_field_data, limit: @limit.to_s, offset: @offset.to_s }
133
213
  else
134
- { query: new_field_data, sort: @current_sort, limit: @limit.to_s, offset: @offset.to_s }.to_json
214
+ { query: new_field_data, sort: @current_sort, limit: @limit.to_s, offset: @offset.to_s }
135
215
  end
136
216
  end
137
217
 
218
+ if @post_request_script.present?
219
+ body.merge!(script: @post_request_script)
220
+ body.merge!('script.param' => @post_request_script_param) if @post_request_scriptparam.present?
221
+ end
222
+
223
+ if @prerequest_script.present?
224
+ body.merge!(script: @prerequest_script)
225
+ body.merge!('script.param' => @prerequest_script_param) if @prerequest_scriptparam.present?
226
+ end
227
+
228
+ if @presort_script.present?
229
+ body.merge!(script: @presort_script)
230
+ body.merge!('script.param' => @presort_script_param) if @presort_scriptparam.present?
231
+ end
232
+
233
+ if @portal_limits
234
+ portal_hash = { portal: @portal_limits.map { |portal_name, limit| "#{portal_name}" } }
235
+ body.merge!(portal_hash)
236
+ @portal_limits.each { |portal_name, limit| body.merge!({ "limit.#{portal_name}" => limit.to_s }) }
237
+ end
238
+
239
+ body = body.to_json
138
240
  response = Request.make_request(url, "Bearer #{Request.get_token}", 'post', body)
241
+
139
242
  if response['messages'][0]['code'] != '0'
140
243
  if response['messages'][0]['code'] == '101' || response['messages'][0]['code'] == '401'
141
244
  resp = RecordSet.new(@trophonius_model.layout_name, @trophonius_model.non_modifiable_fields).send(method, *args, &block)
@@ -157,7 +260,26 @@ module Trophonius
157
260
  else
158
261
  r_results = response['response']['data']
159
262
  ret_val = RecordSet.new(@trophonius_model.layout_name, @trophonius_model.non_modifiable_fields)
263
+
160
264
  r_results.each do |r|
265
+ r['fieldData'].merge!('post_request_script_result' => response['response']['scriptResult']) if response['response']['scriptResult']
266
+
267
+ if response['response']['scriptResult.presort']
268
+ r['fieldData'].merge!('presort_script_result' => response['response']['scriptResult.presort'])
269
+ end
270
+
271
+ if response['response']['scriptResult.prerequest']
272
+ r['fieldData'].merge!('prerequest_script_result' => response['response']['scriptResult.prerequest'])
273
+ end
274
+
275
+ r['fieldData'].merge!('post_request_script_error' => response['response']['scriptError']) if response['response']['scriptError']
276
+
277
+ r['fieldData'].merge!('presort_script_error' => response['response']['scriptError.presort']) if response['response']['scriptError.presort']
278
+
279
+ if response['response']['scriptError.prerequest']
280
+ r['fieldData'].merge!('prerequest_script_error' => response['response']['scriptError.prerequest'])
281
+ end
282
+
161
283
  hash = @trophonius_model.build_result(r)
162
284
  ret_val << hash
163
285
  end
@@ -30,6 +30,7 @@ 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'
35
36
  close_connection(token)
@@ -47,6 +48,38 @@ module Trophonius
47
48
  return ret_val
48
49
  end
49
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
+
50
83
  def run_script(script:, scriptparameter:)
51
84
  url =
52
85
  URI(
@@ -62,8 +95,10 @@ module Trophonius
62
95
  ret_val = ''
63
96
 
64
97
  if result['messages'][0]['code'] != '0'
98
+ close_connection(token)
65
99
  Error.throw_error(result['messages'][0]['code'])
66
100
  elsif result['response']['scriptResult'] == '403'
101
+ close_connection(token)
67
102
  Error.throw_error(403)
68
103
  else
69
104
  ret_val = result['response']['scriptResult']
@@ -146,6 +181,7 @@ module Trophonius
146
181
  begin
147
182
  JSON.parse(temp.response_body)
148
183
  rescue Exception => e
184
+ close_connection(token)
149
185
  Error.throw_error('1631')
150
186
  end
151
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.3.0
4
+ version: 1.4.2.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: []