Class: Trophonius::Connection
- Inherits:
-
Object
- Object
- Trophonius::Connection
- Includes:
- DebugPrinter
- Defined in:
- lib/connectors/connection.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
-
#disconnect ⇒ Object
Disconnects from the FileMaker server.
-
#initialize ⇒ Connection
constructor
A new instance of Connection.
-
#token ⇒ String
Returns the last received token.
Methods included from DebugPrinter
Constructor Details
#initialize ⇒ Connection
Returns a new instance of Connection.
12 13 14 15 16 |
# File 'lib/connectors/connection.rb', line 12 def initialize @id = SecureRandom.uuid @token = '' connect end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/connectors/connection.rb', line 10 def id @id end |
Instance Method Details
#disconnect ⇒ Object
Disconnects from the FileMaker server
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/connectors/connection.rb', line 32 def disconnect return unless test_connection uri = URI::RFC2396_Parser.new url = URI( uri.escape( "http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{ Trophonius.config.database }/sessions/#{Trophonius.config.redis_connection ? Trophonius::RedisManager.get_key(key: 'token') : @token}" ) ) ssl_verifyhost = Trophonius.config.local_network ? 0 : 2 ssl_verifypeer = !Trophonius.config.local_network request = Typhoeus::Request.new( url, method: :delete, params: {}, ssl_verifyhost: ssl_verifyhost, ssl_verifypeer: ssl_verifypeer, headers: { 'Content-Type' => 'application/json' } ) temp = request.run begin parsed = JSON.parse(temp.response_body) DebugPrinter.print_debug('RECEIVED DISCONNECT', parsed) rescue StandardError => e puts e puts e.backtrace Error.throw_error('1631') end Error.throw_error(parsed['messages'][0]['code']) if parsed['messages'][0]['code'] != '0' Trophonius::RedisManager.disconnect! if Trophonius.config.redis_connection @token = nil @last_connection = nil true end |
#token ⇒ String
Returns the last received token
21 22 23 24 25 26 27 |
# File 'lib/connectors/connection.rb', line 21 def token if valid_connection? Trophonius.config.redis_connection ? Trophonius::RedisManager.get_key(key: 'token') : @token else connect end end |