trophonius 1.1.1 → 1.1.2
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_model.rb +33 -8
- data/lib/trophonius_query.rb +35 -27
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f55a33c411a7d8e30e6b71817c8f4becba9579bedbd1971d1d3edb184ad9974
|
4
|
+
data.tar.gz: '09e8776664aaf9cf5c8b87e1373f0f8455692c793d84ac93876d98c949aa783d'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f53e29093fcbd1d2917ccb35b2a313a7aaa533d47ea82251de514a4e642bec843d3b74e65db5dcb6657e7c5151ca9d02c68ad67b0c3db073ced60ab449c725b7
|
7
|
+
data.tar.gz: 19e3cd597557bb9016726b3518e169769dd24a297f65774555b7633e86b2a2c7ea17e34ad37f44bbd68bcc489b56fcc1050346338efa985c47d1022abe09af17
|
data/lib/trophonius_model.rb
CHANGED
@@ -13,8 +13,10 @@ module Trophonius
|
|
13
13
|
|
14
14
|
def initialize(config:)
|
15
15
|
@configuration = config
|
16
|
+
@offset = ""
|
17
|
+
@limit = ""
|
16
18
|
end
|
17
|
-
|
19
|
+
|
18
20
|
##
|
19
21
|
# Sets up the configuration for the model.
|
20
22
|
#
|
@@ -26,6 +28,21 @@ module Trophonius
|
|
26
28
|
@configuration.non_modifiable_fields = configuration[:non_modifiable_fields]
|
27
29
|
@configuration.all_fields = {}
|
28
30
|
@configuration.translations = {}
|
31
|
+
@offset = ""
|
32
|
+
@limit = ""
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Limits the found record set.
|
37
|
+
#
|
38
|
+
# @param [Integer] page: number of current page
|
39
|
+
# @param [Integer] limit: number of records retreived
|
40
|
+
#
|
41
|
+
# @return [Trophonius::Model] Self
|
42
|
+
def self.paginate(page, limit)
|
43
|
+
@offset = ((page * limit - limit) + 1).to_s
|
44
|
+
@limit = limit.to_s
|
45
|
+
self
|
29
46
|
end
|
30
47
|
|
31
48
|
##
|
@@ -60,13 +77,12 @@ module Trophonius
|
|
60
77
|
self.first
|
61
78
|
@configuration.translations
|
62
79
|
end
|
63
|
-
|
80
|
+
|
64
81
|
def self.method_missing(method, *args, &block)
|
65
82
|
new_instance = Trophonius::Model.new(config: @configuration)
|
66
|
-
new_instance.current_query = Trophonius::Query.new(trophonius_model: self)
|
67
|
-
# new_instance.current_query.build_query[0].merge!(fieldData)
|
83
|
+
new_instance.current_query = Trophonius::Query.new(trophonius_model: self, limit: @limit, offset: @offset )
|
68
84
|
args << new_instance
|
69
|
-
if new_instance.current_query.respond_to?(method)
|
85
|
+
if new_instance.current_query.respond_to?(method)
|
70
86
|
new_instance.current_query.send(method, args)
|
71
87
|
end
|
72
88
|
end
|
@@ -76,7 +92,10 @@ module Trophonius
|
|
76
92
|
args << self
|
77
93
|
@current_query.send(method, args)
|
78
94
|
elsif @current_query.response.respond_to?(method)
|
79
|
-
@current_query.run_query(method, *args, &block)
|
95
|
+
ret_val = @current_query.run_query(method, *args, &block)
|
96
|
+
@limit = ''
|
97
|
+
@offset = ''
|
98
|
+
return ret_val
|
80
99
|
end
|
81
100
|
end
|
82
101
|
|
@@ -87,7 +106,7 @@ module Trophonius
|
|
87
106
|
# @return [Trophonius::Model] new instance of the model
|
88
107
|
def self.where(fieldData)
|
89
108
|
new_instance = Trophonius::Model.new(config: @configuration)
|
90
|
-
new_instance.current_query = Trophonius::Query.new(trophonius_model: self)
|
109
|
+
new_instance.current_query = Trophonius::Query.new(trophonius_model: self, limit: @limit, offset: @offset )
|
91
110
|
new_instance.current_query.build_query[0].merge!(fieldData)
|
92
111
|
new_instance
|
93
112
|
end
|
@@ -337,7 +356,13 @@ module Trophonius
|
|
337
356
|
def self.all(sort: {})
|
338
357
|
results = Request.retrieve_all(layout_name, sort)
|
339
358
|
count = results["response"]["scriptResult"].to_i
|
340
|
-
|
359
|
+
unless @limit.empty? || @offset.empty?
|
360
|
+
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}")
|
361
|
+
else
|
362
|
+
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}")
|
363
|
+
end
|
364
|
+
@limit = ''
|
365
|
+
@offset = ''
|
341
366
|
results = Request.make_request(url, "Bearer #{Request.get_token}", "get", "{}")
|
342
367
|
if results["messages"][0]["code"] != "0"
|
343
368
|
Error.throw_error(results["messages"][0]["code"])
|
data/lib/trophonius_query.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require 'json'
|
2
|
+
require 'trophonius_config'
|
3
|
+
require 'trophonius_record'
|
4
|
+
require 'trophonius_recordset'
|
5
|
+
require 'trophonius_error'
|
6
6
|
|
7
7
|
module Trophonius
|
8
8
|
class Trophonius::Query
|
@@ -10,12 +10,16 @@ module Trophonius
|
|
10
10
|
|
11
11
|
##
|
12
12
|
# Creates a new instance of the Trophonius::Query class
|
13
|
-
#
|
14
|
-
# @param [Trophonius::Model] base model for the new query
|
13
|
+
#
|
14
|
+
# @param [Trophonius::Model] trophonius_model: base model for the new query
|
15
|
+
# @param [String] limit: Used for every query to set the limit
|
16
|
+
# @param [String] offset: Used for every query to set the offset
|
15
17
|
# @return [Trophonius::Query] new instance of Trophonius::Query
|
16
|
-
def initialize(trophonius_model:)
|
18
|
+
def initialize(trophonius_model:, limit:, offset:)
|
17
19
|
@response = RecordSet.new(trophonius_model.layout_name, trophonius_model.non_modifiable_fields)
|
18
20
|
@trophonius_model = trophonius_model
|
21
|
+
@limit = limit
|
22
|
+
@offset = offset
|
19
23
|
end
|
20
24
|
|
21
25
|
##
|
@@ -29,7 +33,7 @@ module Trophonius
|
|
29
33
|
def inspect
|
30
34
|
@current_query
|
31
35
|
end
|
32
|
-
|
36
|
+
|
33
37
|
##
|
34
38
|
# Adds a find request to the original query, resulting in an "Or" find-request for FileMaker
|
35
39
|
#
|
@@ -39,17 +43,17 @@ module Trophonius
|
|
39
43
|
args[1].current_query.build_query << args[0]
|
40
44
|
args[1]
|
41
45
|
end
|
42
|
-
|
46
|
+
|
43
47
|
##
|
44
48
|
# Adds an omit request to the original query, resulting in an "omit" find for FileMaker
|
45
49
|
#
|
46
50
|
# @param [args] arguments containing a Hash containing the FileMaker omit request, and the base model object for the query
|
47
51
|
# @return [Trophonius::Model] updated base model
|
48
52
|
def not(args)
|
49
|
-
args[1].current_query.build_query << args[0].merge!(
|
53
|
+
args[1].current_query.build_query << args[0].merge!(omit: true)
|
50
54
|
args[1]
|
51
55
|
end
|
52
|
-
|
56
|
+
|
53
57
|
##
|
54
58
|
# Performs the query in FileMaker
|
55
59
|
#
|
@@ -57,33 +61,37 @@ module Trophonius
|
|
57
61
|
# @param [*args] original arguments, will be passed to the method call
|
58
62
|
# @param [&block] original block, will be passed to the method call
|
59
63
|
#
|
60
|
-
# @return Response of the called method
|
64
|
+
# @return Response of the called method
|
61
65
|
def run_query(method, *args, &block)
|
62
|
-
url = URI("http#{Trophonius.config.ssl == true ?
|
63
|
-
new_field_data = @current_query.map { |
|
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")
|
67
|
+
new_field_data = @current_query.map { |_q| {} }
|
64
68
|
if @trophonius_model.translations.keys.empty?
|
65
69
|
@trophonius_model.create_translations
|
66
70
|
end
|
67
71
|
@current_query.each_with_index do |query, index|
|
68
72
|
query.keys.each do |k|
|
69
|
-
if @trophonius_model.translations.
|
70
|
-
new_field_data[index].merge!(
|
73
|
+
if @trophonius_model.translations.key?(k.to_s)
|
74
|
+
new_field_data[index].merge!(@trophonius_model.translations[k.to_s].to_s => query[k].to_s)
|
71
75
|
else
|
72
|
-
new_field_data[index].merge!(
|
76
|
+
new_field_data[index].merge!(k.to_s => query[k].to_s)
|
73
77
|
end
|
74
78
|
end
|
75
79
|
end
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
+
if @offset.empty? || @limit.empty?
|
81
|
+
body = { query: new_field_data, limit: '100000' }.to_json
|
82
|
+
else
|
83
|
+
body = { query: new_field_data, limit: @limit.to_s, offset: @offset.to_s }.to_json
|
84
|
+
end
|
85
|
+
response = Request.make_request(url, "Bearer #{Request.get_token}", 'post', body)
|
86
|
+
if response['messages'][0]['code'] != '0'
|
87
|
+
if response['messages'][0]['code'] == '101' || response['messages'][0]['code'] == '401'
|
80
88
|
RecordSet.new(@trophonius_model.layout_name, @trophonius_model.non_modifiable_fields).send(method, *args, &block)
|
81
89
|
return
|
82
90
|
else
|
83
|
-
Error.throw_error(response[
|
91
|
+
Error.throw_error(response['messages'][0]['code'])
|
84
92
|
end
|
85
93
|
else
|
86
|
-
r_results = response[
|
94
|
+
r_results = response['response']['data']
|
87
95
|
ret_val = RecordSet.new(@trophonius_model.layout_name, @trophonius_model.non_modifiable_fields)
|
88
96
|
r_results.each do |r|
|
89
97
|
hash = @trophonius_model.build_result(r)
|
@@ -93,7 +101,7 @@ module Trophonius
|
|
93
101
|
return @response.send(method, *args, &block)
|
94
102
|
end
|
95
103
|
end
|
96
|
-
|
97
|
-
|
104
|
+
|
105
|
+
alias to_s inspect
|
98
106
|
end
|
99
|
-
end
|
107
|
+
end
|