Module: Trophonius::Request
- Defined in:
- lib/trophonius_request.rb
Class Method Summary collapse
-
.get_token ⇒ String
Gets the current FileMaker token.
-
.make_request(url_param, auth, method, body, params = '') ⇒ JSON
Crafts and runs a HTTP request of any type.
-
.retrieve_all(layout_name, sort) ⇒ JSON
Retrieves the 10000000 records from FileMaker.
-
.retrieve_first(layout_name) ⇒ JSON
Retrieves the first record from FileMaker.
-
.run_script(script, scriptparameter, layout_name) ⇒ JSON
Runs a FileMaker script.
Class Method Details
.get_token ⇒ String
Gets the current FileMaker token
44 45 46 47 48 49 50 |
# File 'lib/trophonius_request.rb', line 44 def self.get_token if Connection.valid_connection? Connection.token else Connection.connect end end |
.make_request(url_param, auth, method, body, params = '') ⇒ JSON
Crafts and runs a HTTP request of any type
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/trophonius_request.rb', line 20 def self.make_request(url_param, auth, method, body, params = '') ssl_verifyhost = Trophonius.config.local_network ? 0 : 2 ssl_verifypeer = !Trophonius.config.local_network request = Typhoeus::Request.new( url_param, method: method.to_sym, body: body, params: params, ssl_verifyhost: ssl_verifyhost, ssl_verifypeer: ssl_verifypeer, headers: { 'Content-Type' => 'application/json', Authorization: auth.to_s } ) temp = request.run begin JSON.parse(temp.response_body) rescue Exception Error.throw_error('1631') end end |
.retrieve_all(layout_name, sort) ⇒ JSON
Retrieves the 10000000 records from FileMaker
74 75 76 77 78 79 80 81 82 |
# File 'lib/trophonius_request.rb', line 74 def self.retrieve_all(layout_name, sort) if !sort.empty? sort_order = sort.to_json.to_s url = URI("http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/layouts/#{layout_name}/records?_limit=10000000_sort=#{sort_order}#{Trophonius.config.count_result_script == '' ? '' : "&script=#{Trophonius.config.count_result_script}"}") else url = URI("http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/layouts/#{layout_name}/records?_limit=10000000#{Trophonius.config.count_result_script == '' ? '' : "&script=#{Trophonius.config.count_result_script}"}") end make_request(url, "Bearer #{get_token}", 'get', '{}') end |
.retrieve_first(layout_name) ⇒ JSON
Retrieves the first record from FileMaker
56 57 58 59 |
# File 'lib/trophonius_request.rb', line 56 def self.retrieve_first(layout_name) url = URI("http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/layouts/#{layout_name}/records?_limit=1") make_request(url, "Bearer #{get_token}", 'get', '{}') end |
.run_script(script, scriptparameter, layout_name) ⇒ JSON
Runs a FileMaker script
65 66 67 68 |
# File 'lib/trophonius_request.rb', line 65 def self.run_script(script, scriptparameter, layout_name) url = URI("http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/layouts/#{layout_name}/records?_limit=1&script=#{script}&script.param=#{scriptparameter}") make_request(url, "Bearer #{get_token}", 'get', '{}') end |