trophonius 1.2.3 → 1.2.4

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: b838d18be991c51c6c3190b0a09c552852778726a803ea0cb5a9186e542fb63a
4
- data.tar.gz: 36f06cb81b17c474e73684d9f42260a31ff3658c9607e6dbb3a1412ef2749079
3
+ metadata.gz: a314aa079b0dc7fca08f9796cfed19723f93006d2fef258b59517e9b20dd8c7a
4
+ data.tar.gz: f75dccd8b89ef66f69f15289f41e0389d946a9c25a96fdc7a19391eb296aa19f
5
5
  SHA512:
6
- metadata.gz: 043f1c4dc5584aa2627c0a0a6c438f5519b9797223025e5997fc7d0f6f4e1adf0889a9d5d4e41dcecab0049b48f468978f7edaa249ef4ebc7007e16426cb8543
7
- data.tar.gz: c7493bb44cf5a9d87ad78d4b82fa61d61272aa8dc6eed200d9e20d82bbf0079265f86c2000e4585ff09259253e47802476c14595cf878739933c9a220a7f7b49
6
+ metadata.gz: 88e13826eb573c46ad06bc4b6eb63a23769231a5a1134820b3b3a5c6e8ca208a5c7c95756eaf549d5a8c4e44e6be5f5a1fa2a3fdec86b3d80cdc60fab34c237b
7
+ data.tar.gz: cde2425883080994637eda7c571f3bfa4196c65118d798630e55bc1b7108d45a74a37dafe8f23dc7906becae35bcd39b36635ea4459fa125316655df8d0807b2
@@ -47,258 +47,258 @@ module Trophonius
47
47
  raise RecordNotFoundError.new, 'Empty result'
48
48
  when '9'
49
49
  raise UnauthenticatedError.new, 'User has insufficient privileges'
50
- # when '10'
51
- # when '11'
52
- # when '12'
53
- # when '13'
54
- # when '14'
55
- # when '15'
56
- # when '16'
57
- # when '17'
58
- # when '16'
59
- # when '18'
60
- # when '19'
61
- # when '09'
62
- # when '20'
63
- # when '21'
64
- # when '100'
50
+ # when "10"
51
+ # when "11"
52
+ # when "12"
53
+ # when "13"
54
+ # when "14"
55
+ # when "15"
56
+ # when "16"
57
+ # when "17"
58
+ # when "16"
59
+ # when "18"
60
+ # when "19"
61
+ # when "09"
62
+ # when "20"
63
+ # when "21"
64
+ # when "100"
65
65
  when '101'
66
- raise RecordNotFoundError.new, 'Record #{more_info} was not found'
66
+ raise RecordNotFoundError.new, "Record #{more_info} was not found"
67
67
  when '102'
68
68
  if more_info != 0
69
69
  raise FieldUnexistingError.new, "Following field(s) #{more_info} do not exist on layout #{layout_info}"
70
70
  else
71
71
  raise FieldUnexistingError.new, 'Field does not exist'
72
72
  end
73
- # when '103'
73
+ # when "103"
74
74
  when '104'
75
75
  raise ScriptUnexistingError.new, 'Script does not exist'
76
76
  when '105'
77
77
  raise LayoutUnexistingError.new, 'Layout does not exist'
78
- # when '106'
79
- # when '107'
80
- # when '108'
81
- # when '109'
82
- # when '110'
83
- # when '111'
84
- # when '112'
85
- # when '113'
86
- # when '114'
87
- # when '115'
88
- # when '116'
89
- # when '117'
90
- # when '118'
91
- # when '130'
92
- # when '131'
93
- # when '200'
78
+ # when "106"
79
+ # when "107"
80
+ # when "108"
81
+ # when "109"
82
+ # when "110"
83
+ # when "111"
84
+ # when "112"
85
+ # when "113"
86
+ # when "114"
87
+ # when "115"
88
+ # when "116"
89
+ # when "117"
90
+ # when "118"
91
+ # when "130"
92
+ # when "131"
93
+ # when "200"
94
94
  when '201'
95
95
  raise FieldNotModifiableError.new, 'Trying to write to a read-only field'
96
- # when '202'
97
- # when '203'
98
- # when '204'
99
- # when '205'
100
- # when '206'
101
- # when '207'
102
- # when '208'
103
- # when '209'
104
- # when '210'
105
- # when '211'
106
- # when '212'
107
- # when '213'
108
- # when '214'
109
- # when '215'
110
- # when '216'
111
- # when '217'
112
- # when '218'
113
- # when '300'
114
- # when '301'
115
- # when '302'
116
- # when '303'
117
- # when '304'
118
- # when '306'
119
- # when '307'
120
- # when '308'
96
+ # when "202"
97
+ # when "203"
98
+ # when "204"
99
+ # when "205"
100
+ # when "206"
101
+ # when "207"
102
+ # when "208"
103
+ # when "209"
104
+ # when "210"
105
+ # when "211"
106
+ # when "212"
107
+ # when "213"
108
+ # when "214"
109
+ # when "215"
110
+ # when "216"
111
+ # when "217"
112
+ # when "218"
113
+ # when "300"
114
+ # when "301"
115
+ # when "302"
116
+ # when "303"
117
+ # when "304"
118
+ # when "306"
119
+ # when "307"
120
+ # when "308"
121
121
  when '400'
122
122
  raise EmptyFindError.new, ' Find criteria are empty'
123
123
  when '401'
124
- raise RecordNotFoundError.new, 'Record #{more_info} was not found'
125
- # when '402'
124
+ raise RecordNotFoundError.new, "Record #{more_info} was not found"
125
+ # when "402"
126
126
  when '403'
127
127
  raise UnauthenticatedError.new, 'You are unauthenticated to perform this request'
128
- # when '404'
129
- # when '405'
130
- # when '406'
131
- # when '407'
132
- # when '408'
133
- # when '409'
134
- # when '410'
135
- # when '412'
136
- # when '413'
137
- # when '414'
138
- # when '415'
139
- # when '416'
140
- # when '417'
141
- # when '418'
128
+ # when "404"
129
+ # when "405"
130
+ # when "406"
131
+ # when "407"
132
+ # when "408"
133
+ # when "409"
134
+ # when "410"
135
+ # when "412"
136
+ # when "413"
137
+ # when "414"
138
+ # when "415"
139
+ # when "416"
140
+ # when "417"
141
+ # when "418"
142
142
  when '500'
143
143
  raise ValidationError.new, 'Data value does not meet validation entry options (hint make sure your date values are formatted as MM/DD/YYYY)'
144
- # when '501'
145
- # when '502'
146
- # when '503'
147
- # when '504'
148
- # when '505'
149
- # when '506'
150
- # when '507'
151
- # when '508'
152
- # when '509'
153
- # when '510'
154
- # when '511'
155
- # when '512'
156
- # when '513'
157
- # when '600'
158
- # when '601'
159
- # when '602'
160
- # when '603'
161
- # when '700'
162
- # when '706'
163
- # when '707'
164
- # when '708'
165
- # when '711'
166
- # when '714'
167
- # when '715'
168
- # when '716'
169
- # when '717'
170
- # when '718'
171
- # when '719'
172
- # when '720'
173
- # when '721'
174
- # when '722'
175
- # when '723'
176
- # when '724'
177
- # when '725'
178
- # when '726'
179
- # when '727'
180
- # when '729'
181
- # when '730'
182
- # when '731'
183
- # when '732'
184
- # when '733'
185
- # when '734'
186
- # when '735'
187
- # when '736'
188
- # when '738'
189
- # when '800'
190
- # when '801'
191
- # when '802'
192
- # when '803'
193
- # when '804'
194
- # when '805'
195
- # when '806'
196
- # when '807'
197
- # when '808'
198
- # when '809'
199
- # when '810'
200
- # when '811'
201
- # when '812'
202
- # when '813'
203
- # when '814'
204
- # when '815'
205
- # when '816'
206
- # when '817'
207
- # when '819'
208
- # when '820'
209
- # when '821'
210
- # when '822'
211
- # when '823'
212
- # when '824'
213
- # when '825'
214
- # when '826'
215
- # when '827'
216
- # when '850'
217
- # when '851'
218
- # when '852'
219
- # when '853'
220
- # when '900'
221
- # when '901'
222
- # when '902'
223
- # when '903'
224
- # when '905'
225
- # when '906'
226
- # when '920'
227
- # when '921'
228
- # when '922'
229
- # when '923'
230
- # when '951'
144
+ # when "501"
145
+ # when "502"
146
+ # when "503"
147
+ # when "504"
148
+ # when "505"
149
+ # when "506"
150
+ # when "507"
151
+ # when "508"
152
+ # when "509"
153
+ # when "510"
154
+ # when "511"
155
+ # when "512"
156
+ # when "513"
157
+ # when "600"
158
+ # when "601"
159
+ # when "602"
160
+ # when "603"
161
+ # when "700"
162
+ # when "706"
163
+ # when "707"
164
+ # when "708"
165
+ # when "711"
166
+ # when "714"
167
+ # when "715"
168
+ # when "716"
169
+ # when "717"
170
+ # when "718"
171
+ # when "719"
172
+ # when "720"
173
+ # when "721"
174
+ # when "722"
175
+ # when "723"
176
+ # when "724"
177
+ # when "725"
178
+ # when "726"
179
+ # when "727"
180
+ # when "729"
181
+ # when "730"
182
+ # when "731"
183
+ # when "732"
184
+ # when "733"
185
+ # when "734"
186
+ # when "735"
187
+ # when "736"
188
+ # when "738"
189
+ # when "800"
190
+ # when "801"
191
+ # when "802"
192
+ # when "803"
193
+ # when "804"
194
+ # when "805"
195
+ # when "806"
196
+ # when "807"
197
+ # when "808"
198
+ # when "809"
199
+ # when "810"
200
+ # when "811"
201
+ # when "812"
202
+ # when "813"
203
+ # when "814"
204
+ # when "815"
205
+ # when "816"
206
+ # when "817"
207
+ # when "819"
208
+ # when "820"
209
+ # when "821"
210
+ # when "822"
211
+ # when "823"
212
+ # when "824"
213
+ # when "825"
214
+ # when "826"
215
+ # when "827"
216
+ # when "850"
217
+ # when "851"
218
+ # when "852"
219
+ # when "853"
220
+ # when "900"
221
+ # when "901"
222
+ # when "902"
223
+ # when "903"
224
+ # when "905"
225
+ # when "906"
226
+ # when "920"
227
+ # when "921"
228
+ # when "922"
229
+ # when "923"
230
+ # when "951"
231
231
  when '952'
232
232
  raise InvalidTokenError.new, 'Could not retrieve a valid token from FileMaker, check your FileMaker server'
233
- # when '954'
234
- # when '955'
235
- # when '956'
236
- # when '957'
237
- # when '958'
238
- # when '959'
239
- # when '960'
240
- # when '1200'
241
- # when '1201'
242
- # when '1202'
243
- # when '1203'
244
- # when '1204'
245
- # when '1205'
246
- # when '1206'
247
- # when '1207'
248
- # when '1208'
249
- # when '1209'
250
- # when '1210'
251
- # when '1211'
252
- # when '1212'
253
- # when '1213'
254
- # when '1214'
255
- # when '1215'
256
- # when '1216'
257
- # when '1217'
258
- # when '1218'
259
- # when '1219'
260
- # when '1220'
261
- # when '1221'
262
- # when '1222'
263
- # when '1223'
264
- # when '1224'
265
- # when '1225'
266
- # when '1300'
267
- # when '1301'
268
- # when '1400'
269
- # when '1401'
270
- # when '1402'
271
- # when '1403'
272
- # when '1404'
273
- # when '1405'
274
- # when '1406'
275
- # when '1407'
276
- # when '1408'
277
- # when '1409'
278
- # when '1413'
279
- # when '1414'
280
- # when '1450'
281
- # when '1451'
282
- # when '1501'
283
- # when '1502'
284
- # when '1503'
285
- # when '1504'
286
- # when '1505'
287
- # when '1506'
288
- # when '1507'
289
- # when '1550'
290
- # when '1551'
291
- # when '1626'
292
- # when '1627'
293
- # when '1628'
294
- # when '1629'
295
- # when '1630'
233
+ # when "954"
234
+ # when "955"
235
+ # when "956"
236
+ # when "957"
237
+ # when "958"
238
+ # when "959"
239
+ # when "960"
240
+ # when "1200"
241
+ # when "1201"
242
+ # when "1202"
243
+ # when "1203"
244
+ # when "1204"
245
+ # when "1205"
246
+ # when "1206"
247
+ # when "1207"
248
+ # when "1208"
249
+ # when "1209"
250
+ # when "1210"
251
+ # when "1211"
252
+ # when "1212"
253
+ # when "1213"
254
+ # when "1214"
255
+ # when "1215"
256
+ # when "1216"
257
+ # when "1217"
258
+ # when "1218"
259
+ # when "1219"
260
+ # when "1220"
261
+ # when "1221"
262
+ # when "1222"
263
+ # when "1223"
264
+ # when "1224"
265
+ # when "1225"
266
+ # when "1300"
267
+ # when "1301"
268
+ # when "1400"
269
+ # when "1401"
270
+ # when "1402"
271
+ # when "1403"
272
+ # when "1404"
273
+ # when "1405"
274
+ # when "1406"
275
+ # when "1407"
276
+ # when "1408"
277
+ # when "1409"
278
+ # when "1413"
279
+ # when "1414"
280
+ # when "1450"
281
+ # when "1451"
282
+ # when "1501"
283
+ # when "1502"
284
+ # when "1503"
285
+ # when "1504"
286
+ # when "1505"
287
+ # when "1506"
288
+ # when "1507"
289
+ # when "1550"
290
+ # when "1551"
291
+ # when "1626"
292
+ # when "1627"
293
+ # when "1628"
294
+ # when "1629"
295
+ # when "1630"
296
296
  when '1631'
297
297
  raise ConnectionError.new, 'An error occurred while attempting to connect to the FileMaker server'
298
- # when '1632'
299
- # when '1633'
298
+ # when "1632"
299
+ # when "1633"
300
300
  else
301
- raise ResponseNotYetImplementedError.new, 'An unknown error has been encountered: err_no was #{error_id}'
301
+ raise ResponseNotYetImplementedError.new, "An unknown error has been encountered: err_no was #{error_id}"
302
302
  end
303
303
  end
304
304
  end
@@ -1,9 +1,9 @@
1
- require "json"
2
- require "trophonius_config"
3
- require "trophonius_record"
4
- require "trophonius_recordset"
5
- require "trophonius_query"
6
- require "trophonius_error"
1
+ require 'json'
2
+ require 'trophonius_config'
3
+ require 'trophonius_record'
4
+ require 'trophonius_recordset'
5
+ require 'trophonius_query'
6
+ require 'trophonius_error'
7
7
 
8
8
  module Trophonius
9
9
  # This class will retrieve the records from the FileMaker database and build a RecordSet filled with Record objects. One Record object represents a record in FileMaker.
@@ -13,10 +13,10 @@ module Trophonius
13
13
 
14
14
  def initialize(config:)
15
15
  @configuration = config
16
- @offset = ""
17
- @limit = ""
16
+ @offset = ''
17
+ @limit = ''
18
18
  end
19
-
19
+
20
20
  ##
21
21
  # Sets up the configuration for the model.
22
22
  #
@@ -28,8 +28,8 @@ module Trophonius
28
28
  @configuration.non_modifiable_fields = configuration[:non_modifiable_fields]
29
29
  @configuration.all_fields = {}
30
30
  @configuration.translations = {}
31
- @offset = ""
32
- @limit = ""
31
+ @offset = ''
32
+ @limit = ''
33
33
  end
34
34
 
35
35
  ##
@@ -80,11 +80,9 @@ module Trophonius
80
80
 
81
81
  def self.method_missing(method, *args, &block)
82
82
  new_instance = Trophonius::Model.new(config: @configuration)
83
- new_instance.current_query = Trophonius::Query.new(trophonius_model: self, limit: @limit, offset: @offset )
83
+ new_instance.current_query = Trophonius::Query.new(trophonius_model: self, limit: @limit, offset: @offset)
84
84
  args << new_instance
85
- if new_instance.current_query.respond_to?(method)
86
- new_instance.current_query.send(method, args)
87
- end
85
+ new_instance.current_query.send(method, args) if new_instance.current_query.respond_to?(method)
88
86
  end
89
87
 
90
88
  def method_missing(method, *args, &block)
@@ -106,7 +104,7 @@ module Trophonius
106
104
  # @return [Trophonius::Model] new instance of the model
107
105
  def self.where(fieldData)
108
106
  new_instance = Trophonius::Model.new(config: @configuration)
109
- new_instance.current_query = Trophonius::Query.new(trophonius_model: self, limit: @limit, offset: @offset )
107
+ new_instance.current_query = Trophonius::Query.new(trophonius_model: self, limit: @limit, offset: @offset)
110
108
  new_instance.current_query.build_query[0].merge!(fieldData)
111
109
  new_instance
112
110
  end
@@ -131,38 +129,44 @@ module Trophonius
131
129
  # @return [Record] the created record
132
130
  # Model.create(fieldOne: "Data")
133
131
  def self.create(fieldData)
134
- url = URI("http#{Trophonius.config.ssl == true ? "s" : ""}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/layouts/#{layout_name}/records")
132
+ url =
133
+ URI(
134
+ "http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/layouts/#{
135
+ layout_name
136
+ }/records"
137
+ )
135
138
  new_field_data = {}
136
- if @configuration.translations.keys.empty?
137
- create_translations
138
- end
139
+ create_translations if @configuration.translations.keys.empty?
139
140
  fieldData.keys.each do |k|
140
141
  if @configuration.translations.keys.include?(k.to_s)
141
- new_field_data.merge!({"#{@configuration.translations[k.to_s]}" => fieldData[k]})
142
+ new_field_data.merge!({ "#{@configuration.translations[k.to_s]}" => fieldData[k] })
142
143
  else
143
- new_field_data.merge!({"#{k}" => fieldData[k]})
144
+ new_field_data.merge!({ "#{k}" => fieldData[k] })
144
145
  end
145
146
  end
146
147
  body = "{\"fieldData\": #{new_field_data.to_json}}"
147
- response = Request.make_request(url, "Bearer #{Request.get_token}", "post", body)
148
- if response["messages"][0]["code"] != "0"
149
- if response["messages"][0]["code"] == "102"
148
+ response = Request.make_request(url, "Bearer #{Request.get_token}", 'post', body)
149
+ if response['messages'][0]['code'] != '0'
150
+ if response['messages'][0]['code'] == '102'
150
151
  results = Request.retrieve_first(layout_name)
151
- if results["messages"][0]["code"] != "0"
152
- Error.throw_error("102")
152
+ if results['messages'][0]['code'] != '0'
153
+ Error.throw_error('102')
153
154
  else
154
- r_results = results["response"]["data"]
155
- ret_val = r_results.empty? ? Error.throw_error("102") : r_results[0]['fieldData']
156
- Error.throw_error("102", (new_field_data.keys.map(&:downcase) - ret_val.keys.map(&:downcase)).flatten.join(', '), layout_name)
155
+ r_results = results['response']['data']
156
+ ret_val = r_results.empty? ? Error.throw_error('102') : r_results[0]['fieldData']
157
+ Error.throw_error('102', (new_field_data.keys.map(&:downcase) - ret_val.keys.map(&:downcase)).flatten.join(', '), layout_name)
157
158
  end
158
159
  end
159
- Error.throw_error(response["messages"][0]["code"])
160
+ Error.throw_error(response['messages'][0]['code'])
160
161
  else
161
- url = URI("http#{Trophonius.config.ssl == true ? "s" : ""}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/layouts/#{layout_name}/records/#{response["response"]["recordId"]}")
162
- ret_val = build_result(Request.make_request(url, "Bearer #{Request.get_token}", "get", "{}")["response"]["data"][0])
163
- ret_val.send(:define_singleton_method, "result_count") do
164
- 1
165
- end
162
+ url =
163
+ URI(
164
+ "http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
165
+ Trophonius.config.database
166
+ }/layouts/#{layout_name}/records/#{response['response']['recordId']}"
167
+ )
168
+ ret_val = build_result(Request.make_request(url, "Bearer #{Request.get_token}", 'get', '{}')['response']['data'][0])
169
+ ret_val.send(:define_singleton_method, 'result_count') { 1 }
166
170
  return ret_val
167
171
  end
168
172
  end
@@ -175,25 +179,31 @@ module Trophonius
175
179
  # @return [Record] a Record object that correspond to FileMaker record fitting the find request
176
180
  # Model.find_by(fieldOne: "Data")
177
181
  def self.find_by(fieldData)
178
- url = URI("http#{Trophonius.config.ssl == true ? "s" : ""}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/layouts/#{self.layout_name}/_find?_limit=1")
182
+ url =
183
+ URI(
184
+ "http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/layouts/#{
185
+ self.layout_name
186
+ }/_find?_limit=1"
187
+ )
179
188
  new_field_data = {}
180
- if @configuration.translations.keys.empty?
181
- create_translations
182
- end
189
+ create_translations if @configuration.translations.keys.empty?
183
190
  fieldData.keys.each do |k|
184
191
  if @configuration.translations.keys.include?(k.to_s)
185
- new_field_data.merge!({"#{@configuration.translations[k.to_s]}" => fieldData[k]})
192
+ new_field_data.merge!({ "#{@configuration.translations[k.to_s]}" => fieldData[k] })
186
193
  else
187
- new_field_data.merge!({"#{k}" => fieldData[k]})
194
+ new_field_data.merge!({ "#{k}" => fieldData[k] })
188
195
  end
189
196
  end
190
- body = {query: [new_field_data], limit:"100000"}.to_json
191
- response = Request.make_request(url, "Bearer #{Request.get_token}", "post", body)
192
- if response["messages"][0]["code"] != "0"
193
- return RecordSet.new(self.layout_name, self.non_modifiable_fields) if response["messages"][0]["code"] == "101" || response["messages"][0]["code"] == "401"
194
- Error.throw_error(response["messages"][0]["code"])
197
+ body = { query: [new_field_data], limit: '100000' }.to_json
198
+ response = Request.make_request(url, "Bearer #{Request.get_token}", 'post', body)
199
+
200
+ if response['messages'][0]['code'] != '0'
201
+ if response['messages'][0]['code'] == '101' || response['messages'][0]['code'] == '401'
202
+ return RecordSet.new(self.layout_name, self.non_modifiable_fields)
203
+ end
204
+ Error.throw_error(response['messages'][0]['code'])
195
205
  else
196
- r_results = response["response"]["data"]
206
+ r_results = response['response']['data']
197
207
  ret_val = RecordSet.new(self.layout_name, self.non_modifiable_fields)
198
208
  r_results.each do |r|
199
209
  hash = build_result(r)
@@ -210,15 +220,18 @@ module Trophonius
210
220
  #
211
221
  # @return [Record] the record
212
222
  def self.find(record_id)
213
- url = URI("http#{Trophonius.config.ssl == true ? "s" : ""}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/layouts/#{layout_name}/records/#{record_id}")
214
- response = Request.make_request(url, "Bearer #{Request.get_token}", "get", "{}")
215
- if response["messages"][0]["code"] != "0"
216
- Error.throw_error(response["messages"][0]["code"], record_id)
223
+ url =
224
+ URI(
225
+ "http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/layouts/#{
226
+ layout_name
227
+ }/records/#{record_id}"
228
+ )
229
+ response = Request.make_request(url, "Bearer #{Request.get_token}", 'get', '{}')
230
+ if response['messages'][0]['code'] != '0'
231
+ Error.throw_error(response['messages'][0]['code'], record_id)
217
232
  else
218
- ret_val = build_result(response["response"]["data"][0])
219
- ret_val.send(:define_singleton_method, "result_count") do
220
- 1
221
- end
233
+ ret_val = build_result(response['response']['data'][0])
234
+ ret_val.send(:define_singleton_method, 'result_count') { 1 }
222
235
  return ret_val
223
236
  end
224
237
  end
@@ -230,10 +243,15 @@ module Trophonius
230
243
  #
231
244
  # @return [Boolean] True if the delete was successful
232
245
  def self.delete(record_id)
233
- url = URI("http#{Trophonius.config.ssl == true ? "s" : ""}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/layouts/#{layout_name}/records/#{record_id}")
234
- response = Request.make_request(url, "Bearer #{Request.get_token}", "delete", "{}")
235
- if response["messages"][0]["code"] != "0"
236
- Error.throw_error(response["messages"][0]["code"])
246
+ url =
247
+ URI(
248
+ "http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/layouts/#{
249
+ layout_name
250
+ }/records/#{record_id}"
251
+ )
252
+ response = Request.make_request(url, "Bearer #{Request.get_token}", 'delete', '{}')
253
+ if response['messages'][0]['code'] != '0'
254
+ Error.throw_error(response['messages'][0]['code'])
237
255
  else
238
256
  return true
239
257
  end
@@ -248,25 +266,24 @@ module Trophonius
248
266
  #
249
267
  # @return [Boolean] True if the delete was successful
250
268
  def self.edit(record_id, fieldData)
251
- url = URI("http#{Trophonius.config.ssl == true ? "s" : ""}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/layouts/#{layout_name}/records/#{record_id}")
269
+ url =
270
+ URI(
271
+ "http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/layouts/#{
272
+ layout_name
273
+ }/records/#{record_id}"
274
+ )
252
275
  new_field_data = {}
253
- if @configuration.translations.keys.empty?
254
- create_translations
255
- end
276
+ create_translations if @configuration.translations.keys.empty?
256
277
  fieldData.keys.each do |k|
257
278
  if @configuration.translations.keys.include?(k.to_s)
258
- new_field_data.merge!({"#{@configuration.translations[k.to_s]}" => fieldData[k]})
279
+ new_field_data.merge!({ "#{@configuration.translations[k.to_s]}" => fieldData[k] })
259
280
  else
260
- new_field_data.merge!({"#{k}" => fieldData[k]})
281
+ new_field_data.merge!({ "#{k}" => fieldData[k] })
261
282
  end
262
283
  end
263
284
  body = "{\"fieldData\": #{new_field_data.to_json}}"
264
- response = Request.make_request(url, "Bearer #{Request.get_token}", "patch", body)
265
- if response["messages"][0]["code"] != "0"
266
- Error.throw_error(response["messages"][0]["code"])
267
- else
268
- true
269
- end
285
+ response = Request.make_request(url, "Bearer #{Request.get_token}", 'patch', body)
286
+ response['messages'][0]['code'] != '0' ? Error.throw_error(response['messages'][0]['code']) : true
270
287
  end
271
288
 
272
289
  ##
@@ -276,45 +293,52 @@ module Trophonius
276
293
  #
277
294
  # @return [Record] A Record with singleton_methods for the fields where possible
278
295
  def self.build_result(result)
279
- hash = Trophonius::Record.new()
280
- hash.record_id = result["recordId"]
296
+ hash = Trophonius::Record.new
297
+ hash.record_id = result['recordId']
281
298
  hash.layout_name = layout_name
282
- result["fieldData"].keys.each do |key|
299
+ result['fieldData'].keys.each do |key|
283
300
  # unless key[/\s/] || key[/\W/]
284
- @configuration.translations.merge!({ "#{ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_').downcase}" => "#{key}" })
301
+ @configuration.translations.merge!(
302
+ { "#{ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_').downcase}" => "#{key}" }
303
+ )
285
304
  hash.send(:define_singleton_method, ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_')) do
286
305
  hash[key]
287
306
  end
288
307
  unless non_modifiable_fields&.include?(key)
289
- @configuration.all_fields.merge!(ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_').downcase => ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_'))
290
- hash.send(:define_singleton_method, "#{ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_')}=") do |new_val|
308
+ @configuration.all_fields.merge!(
309
+ ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_').downcase =>
310
+ ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_')
311
+ )
312
+ hash.send(
313
+ :define_singleton_method,
314
+ "#{ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_')}="
315
+ ) do |new_val|
291
316
  hash[key] = new_val
292
317
  hash.modifiable_fields[key] = new_val
293
318
  hash.modified_fields[key] = new_val
294
319
  end
295
320
  end
296
321
  # end
297
- hash.merge!({key => result["fieldData"][key]})
298
- unless non_modifiable_fields&.include?(key)
299
- hash.modifiable_fields.merge!({key => result["fieldData"][key]})
300
- end
322
+ hash.merge!({ key => result['fieldData'][key] })
323
+ hash.modifiable_fields.merge!({ key => result['fieldData'][key] }) unless non_modifiable_fields&.include?(key)
301
324
  end
302
- result["portalData"].keys.each do |key|
325
+ result['portalData'].keys.each do |key|
303
326
  unless key[/\s/] || key[/\W/]
304
327
  hash.send(:define_singleton_method, ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_')) do
305
328
  hash[key]
306
329
  end
307
330
  end
308
- result["portalData"][key].each_with_index do |inner_hash|
331
+ result['portalData'][key].each_with_index do |inner_hash|
309
332
  inner_hash.keys.each do |inner_key|
310
- inner_method = ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(inner_key.gsub(/\w+::/, "").to_s), separator: '_')
333
+ inner_method =
334
+ ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(inner_key.gsub(/\w+::/, '').to_s), separator: '_')
311
335
  unless inner_method[/\s/] || inner_method[/\W/]
312
336
  inner_hash.send(:define_singleton_method, inner_method.to_s) { inner_hash[inner_key] }
313
- inner_hash.send(:define_singleton_method, "record_id") { inner_hash["recordId"] }
337
+ inner_hash.send(:define_singleton_method, 'record_id') { inner_hash['recordId'] }
314
338
  end
315
339
  end
316
340
  end
317
- hash.merge!({key => result["portalData"][key]})
341
+ hash.merge!({ key => result['portalData'][key] })
318
342
  end
319
343
  return hash
320
344
  end
@@ -325,14 +349,12 @@ module Trophonius
325
349
  # @return [Record]: a Record corresponding to the FileMaker record.
326
350
  def self.first
327
351
  results = Request.retrieve_first(layout_name)
328
- if results["messages"][0]["code"] != "0"
329
- Error.throw_error(results["messages"][0]["code"])
352
+ if results['messages'][0]['code'] != '0'
353
+ Error.throw_error(results['messages'][0]['code'])
330
354
  else
331
- r_results = results["response"]["data"]
332
- ret_val = r_results.empty? ? Trophonius::Record.new() : build_result(r_results[0])
333
- ret_val.send(:define_singleton_method, "result_count") do
334
- r_results.empty? ? 0 : 1
335
- end
355
+ r_results = results['response']['data']
356
+ ret_val = r_results.empty? ? Trophonius::Record.new : build_result(r_results[0])
357
+ ret_val.send(:define_singleton_method, 'result_count') { r_results.empty? ? 0 : 1 }
336
358
  return ret_val
337
359
  end
338
360
  end
@@ -345,14 +367,14 @@ module Trophonius
345
367
  # @param [String] scriptparameter: the parameter required by the FileMaker script
346
368
  #
347
369
  # @return [String]: string representing the script result returned by FileMaker
348
- def self.run_script(script: "", scriptparameter: "")
370
+ def self.run_script(script: '', scriptparameter: '')
349
371
  result = Request.run_script(script, scriptparameter, layout_name)
350
- if result["messages"][0]["code"] != "0"
351
- Error.throw_error(result["messages"][0]["code"])
352
- elsif result["response"]["scriptResult"] == "403"
372
+ if result['messages'][0]['code'] != '0'
373
+ Error.throw_error(result['messages'][0]['code'])
374
+ elsif result['response']['scriptResult'] == '403'
353
375
  Error.throw_error(403)
354
376
  else
355
- ret_val = result["response"]["scriptResult"]
377
+ ret_val = result['response']['scriptResult']
356
378
  return ret_val
357
379
  end
358
380
  end
@@ -365,19 +387,29 @@ module Trophonius
365
387
  # @return [RecordSet]: a RecordSet containing all the Record objects that correspond to the FileMaker records.
366
388
  def self.all(sort: {})
367
389
  results = Request.retrieve_all(layout_name, sort)
368
- count = results["response"]["scriptResult"].to_i
390
+ count = results['response']['scriptResult'].to_i
369
391
  unless @limit.empty? || @offset.empty?
370
- url = URI("http#{Trophonius.config.ssl == true ? "s" : ""}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/layouts/#{layout_name}/records?_offset=#{@offset}&_limit=#{@limit}")
392
+ url =
393
+ URI(
394
+ "http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
395
+ Trophonius.config.database
396
+ }/layouts/#{layout_name}/records?_offset=#{@offset}&_limit=#{@limit}"
397
+ )
371
398
  else
372
- url = URI("http#{Trophonius.config.ssl == true ? "s" : ""}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/layouts/#{layout_name}/records?_limit=#{count == 0 ? 1000000 : count}")
399
+ url =
400
+ URI(
401
+ "http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{
402
+ Trophonius.config.database
403
+ }/layouts/#{layout_name}/records?_limit=#{count == 0 ? 1_000_000 : count}"
404
+ )
373
405
  end
374
406
  @limit = ''
375
407
  @offset = ''
376
- results = Request.make_request(url, "Bearer #{Request.get_token}", "get", "{}")
377
- if results["messages"][0]["code"] != "0"
378
- Error.throw_error(results["messages"][0]["code"])
408
+ results = Request.make_request(url, "Bearer #{Request.get_token}", 'get', '{}')
409
+ if results['messages'][0]['code'] != '0'
410
+ Error.throw_error(results['messages'][0]['code'])
379
411
  else
380
- r_results = results["response"]["data"]
412
+ r_results = results['response']['data']
381
413
  ret_val = RecordSet.new(self.layout_name, self.non_modifiable_fields)
382
414
  r_results.each do |r|
383
415
  hash = build_result(r)
@@ -30,6 +30,14 @@ module Trophonius
30
30
  @current_query ||= [{}]
31
31
  end
32
32
 
33
+ ##
34
+ # Returns the current sort order, creates an empty sort order if no current sort order exists
35
+ #
36
+ # @return [Array[Hash]] array representing the FileMaker sort request
37
+ def build_sort
38
+ @current_sort ||= []
39
+ end
40
+
33
41
  def inspect
34
42
  @current_query
35
43
  end
@@ -54,6 +62,34 @@ module Trophonius
54
62
  args[1]
55
63
  end
56
64
 
65
+ ##
66
+ # Sets or updates the limit and offset for a query
67
+ #
68
+ # @param [args] arguments containing the limit and offset
69
+ # @return [Trophonius::Model] updated base model
70
+ def paginate(args)
71
+ @offset = args[0]
72
+ @limit = args[1]
73
+ args[2]
74
+ end
75
+
76
+ ##
77
+ # Adds a sort request to the original query, resulting in an "sorted" query
78
+ #
79
+ # @param [args] arguments containing a Hash containing the FileMaker sort request, and the base model object for the query
80
+ # @return [Trophonius::Model] updated base model
81
+ def sort(args)
82
+ @trophonius_model.create_translations if @trophonius_model.translations.keys.empty?
83
+ args[0].each do |key, value|
84
+ if @trophonius_model.translations.key?(key.to_s)
85
+ args[1].current_query.build_sort << { fieldName: "#{@trophonius_model.translations[key.to_s]}", sortOrder: "#{value}" }
86
+ else
87
+ args[1].current_query.build_sort << { fieldName: "#{key}", sortOrder: "#{value}" }
88
+ end
89
+ end
90
+ args[1]
91
+ end
92
+
57
93
  ##
58
94
  # Performs the query in FileMaker
59
95
  #
@@ -63,11 +99,15 @@ module Trophonius
63
99
  #
64
100
  # @return Response of the called method
65
101
  def run_query(method, *args, &block)
66
- url = URI("http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/layouts/#{@trophonius_model.layout_name}/_find")
102
+ url =
103
+ URI(
104
+ "http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/layouts/#{
105
+ @trophonius_model.layout_name
106
+ }/_find"
107
+ )
67
108
  new_field_data = @current_query.map { |_q| {} }
68
- if @trophonius_model.translations.keys.empty?
69
- @trophonius_model.create_translations
70
- end
109
+
110
+ @trophonius_model.create_translations if @trophonius_model.translations.keys.empty?
71
111
  @current_query.each_with_index do |query, index|
72
112
  query.keys.each do |k|
73
113
  if @trophonius_model.translations.key?(k.to_s)
@@ -77,26 +117,37 @@ module Trophonius
77
117
  end
78
118
  end
79
119
  end
80
- if @offset.empty? || @limit.empty?
81
- body = { query: new_field_data, limit: '100000' }.to_json
120
+ if @offset.nil? || @limit.nil? || @offset == '' || @limit == '' || @offset == 0 || @limit == 0
121
+ body =
122
+ if @current_sort.nil?
123
+ { query: new_field_data, limit: '100000' }.to_json
124
+ else
125
+ { query: new_field_data, sort: @current_sort, limit: '100000' }.to_json
126
+ end
82
127
  else
83
- body = { query: new_field_data, limit: @limit.to_s, offset: @offset.to_s }.to_json
128
+ body =
129
+ if @current_sort.nil?
130
+ { query: new_field_data, limit: @limit.to_s, offset: @offset.to_s }.to_json
131
+ else
132
+ { query: new_field_data, sort: @current_sort, limit: @limit.to_s, offset: @offset.to_s }.to_json
133
+ end
84
134
  end
135
+
85
136
  response = Request.make_request(url, "Bearer #{Request.get_token}", 'post', body)
86
137
  if response['messages'][0]['code'] != '0'
87
138
  if response['messages'][0]['code'] == '101' || response['messages'][0]['code'] == '401'
88
139
  RecordSet.new(@trophonius_model.layout_name, @trophonius_model.non_modifiable_fields).send(method, *args, &block)
89
140
  return
90
141
  else
91
- if response["messages"][0]["code"] == "102"
142
+ if response['messages'][0]['code'] == '102'
92
143
  results = Request.retrieve_first(@trophonius_model.layout_name)
93
- if results["messages"][0]["code"] != "0"
94
- Error.throw_error("102")
144
+ if results['messages'][0]['code'] != '0'
145
+ Error.throw_error('102')
95
146
  else
96
- r_results = results["response"]["data"]
97
- ret_val = r_results.empty? ? Error.throw_error("102") : r_results[0]['fieldData']
147
+ r_results = results['response']['data']
148
+ ret_val = r_results.empty? ? Error.throw_error('102') : r_results[0]['fieldData']
98
149
  query_keys = new_field_data.map { |q| q.keys.map(&:downcase) }.uniq
99
- Error.throw_error("102", (query_keys - ret_val.keys.map(&:downcase)).flatten.join(', '), @trophonius_model.layout_name)
150
+ Error.throw_error('102', (query_keys - ret_val.keys.map(&:downcase)).flatten.join(', '), @trophonius_model.layout_name)
100
151
  end
101
152
  end
102
153
  Error.throw_error(response['messages'][0]['code'])
@@ -1,4 +1,5 @@
1
1
  module Trophonius
2
+ # the RedisManager module is used to create a (single) connection to a redis store.
2
3
  module Trophonius::RedisManager
3
4
  def self.connect
4
5
  if ENV['REDIS_URL'] && ENV['REDIS_URL'] != ''
@@ -6,27 +7,52 @@ module Trophonius
6
7
  else
7
8
  @redis ||= Redis.new
8
9
  end
10
+ return nil
9
11
  end
10
12
 
13
+ ##
14
+ # Checks whether the given key exists
15
+ #
16
+ # @param [String] key: the key to check
17
+ # @return [Boolean] true or false depending on whether the key exists in the redis store or not
11
18
  def self.key_exists?(key:)
12
19
  connect unless connected?
13
20
  !(@redis.get(key).nil? || @redis.get(key).empty?)
14
21
  end
15
22
 
23
+ ##
24
+ # Get the value corresponding with the key
25
+ #
26
+ # @param [String] key: the key to find
27
+ # @return [String] the value corresponding with the key
16
28
  def self.get_key(key:)
17
29
  connect unless connected?
18
30
  @redis.get(key)
19
31
  end
20
32
 
33
+ ##
34
+ # Set the value corresponding with a key
35
+ #
36
+ # @param [String] key: the key to store in redis
37
+ # @param [any] value: the value for the key
38
+ # @return [String] the value corresponding with the key
21
39
  def self.set_key(key:, value:)
22
40
  connect unless connected?
23
41
  @redis.set(key, value)
24
42
  end
25
43
 
44
+ ##
45
+ # Checks whether we are connected to redis
46
+ #
47
+ # @return [Boolean] true or false depending on whether a connection to redis has been established
26
48
  def self.connected?
27
49
  @redis.nil? == false && @redis.connected?
28
50
  end
29
51
 
52
+ ##
53
+ # Disconnects from redis as quickly and as silently as possible
54
+ #
55
+ # @return [NilClass] nil
30
56
  def self.disconnect
31
57
  @redis.disconnect!
32
58
  end
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.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kempen Automatisering
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  requirements: []
91
- rubygems_version: 3.1.2
91
+ rubygems_version: 3.0.0
92
92
  signing_key:
93
93
  specification_version: 4
94
94
  summary: Link between Ruby (on Rails) and FileMaker.