trophonius 1.3.1 → 1.4.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 193ec5a1a1a35715519760565271544fe7d14e56670ff533b30449db17a9739f
4
- data.tar.gz: 7b241ecfc24897f44d288fbb912c22fb950b1e645eddb1ed4b2cccaeb6022198
3
+ metadata.gz: bbc6e79b6244e3db4d69057e9502565a77b4aed5c053872332d4015bd6a28d95
4
+ data.tar.gz: 128ec494f7a33e45dd6300c3b9c5386f297cf0384a16c43c170b59cd9d8b5e10
5
5
  SHA512:
6
- metadata.gz: 3c4e65f40f0f8e484ebf35418c9ec26b998f0c9cbd4610e449ec5f0c0abf2c49daec033b8c0929b8f15979f785a461218607b4f075a4d877b3dab6637f50c57e
7
- data.tar.gz: 7b64990a532ca0944514746d78b56adc39ea5b175c3d683ff284a09a101ad4f15fb94c391e8fee67223baf50bb4d5ad2dc6cb34c593f9cf8abf0a5b0fe3e5395
6
+ metadata.gz: 17cc7cf2bb12e56a07683b5bd26c4d33f872945b88ef707b5b61621eed79aa5e1b79d2e879b9a86ca564e19f49df7daab9632fc9874b70d307ac11b848092ed4
7
+ data.tar.gz: 260b16ca4aede6110a88e415ad4b676ea9475bb321c6d68ece2464004595272da4eedafdf41f8e122b9ddaea2369a36abdb598f5166715ff9b420390343cb896
@@ -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
  ##
@@ -60,6 +67,66 @@ module Trophonius
60
67
  args[1]
61
68
  end
62
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
+
63
130
  ##
64
131
  # Adds a find request to the original query, resulting in an "Or" find-request for FileMaker
65
132
  #
@@ -125,7 +192,6 @@ module Trophonius
125
192
  }/layouts/#{@trophonius_model.layout_name}/_find"
126
193
  )
127
194
  )
128
-
129
195
  new_field_data = @current_query.map { |_q| {} }
130
196
 
131
197
  @trophonius_model.create_translations if @trophonius_model.translations.keys.empty?
@@ -149,6 +215,21 @@ module Trophonius
149
215
  end
150
216
  end
151
217
 
218
+ if @post_request_script.present?
219
+ body.merge!(script: @post_request_script)
220
+ body.merge!('script.param' => @post_request_scriptparam) if @post_request_scriptparam.present?
221
+ end
222
+
223
+ if @prerequest_script.present?
224
+ body.merge!(script: @prerequest_script)
225
+ body.merge!('script.prerequest.param' => @prerequest_scriptparam) if @prerequest_scriptparam.present?
226
+ end
227
+
228
+ if @presort_script.present?
229
+ body.merge!(script: @presort_script)
230
+ body.merge!('script.presort.param' => @presort_scriptparam) if @presort_scriptparam.present?
231
+ end
232
+
152
233
  if @portal_limits
153
234
  portal_hash = { portal: @portal_limits.map { |portal_name, limit| "#{portal_name}" } }
154
235
  body.merge!(portal_hash)
@@ -157,6 +238,7 @@ module Trophonius
157
238
 
158
239
  body = body.to_json
159
240
  response = Request.make_request(url, "Bearer #{Request.get_token}", 'post', body)
241
+
160
242
  if response['messages'][0]['code'] != '0'
161
243
  if response['messages'][0]['code'] == '101' || response['messages'][0]['code'] == '401'
162
244
  resp = RecordSet.new(@trophonius_model.layout_name, @trophonius_model.non_modifiable_fields).send(method, *args, &block)
@@ -178,7 +260,26 @@ module Trophonius
178
260
  else
179
261
  r_results = response['response']['data']
180
262
  ret_val = RecordSet.new(@trophonius_model.layout_name, @trophonius_model.non_modifiable_fields)
263
+
181
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
+
182
283
  hash = @trophonius_model.build_result(r)
183
284
  ret_val << hash
184
285
  end
@@ -48,6 +48,38 @@ module Trophonius
48
48
  return ret_val
49
49
  end
50
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
+
51
83
  def run_script(script:, scriptparameter:)
52
84
  url =
53
85
  URI(
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.1
4
+ version: 1.4.2.2
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: []