Class: ApiAuth::Client::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/api_auth/client/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, app_id: nil, secret_key: nil) ⇒ Connection



11
12
13
14
15
# File 'lib/api_auth/client/connection.rb', line 11

def initialize(url:, app_id: nil, secret_key: nil)
  @url = url
  @app_id = app_id
  @secret_key = secret_key
end

Instance Attribute Details

#app_idObject (readonly)

Returns the value of attribute app_id.



9
10
11
# File 'lib/api_auth/client/connection.rb', line 9

def app_id
  @app_id
end

#secret_keyObject (readonly)

Returns the value of attribute secret_key.



9
10
11
# File 'lib/api_auth/client/connection.rb', line 9

def secret_key
  @secret_key
end

#urlObject (readonly)

Returns the value of attribute url.



9
10
11
# File 'lib/api_auth/client/connection.rb', line 9

def url
  @url
end

Instance Method Details

#query(mtd, path, payload = {}) ⇒ Object

rubocop:disable Metrics/AbcSize



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/api_auth/client/connection.rb', line 36

def query(mtd, path, payload = {}) # rubocop:disable Metrics/AbcSize
  req = build_request(mtd, path, payload)
  Response.new(execute(req))
rescue RestClient::RequestTimeout, RestClient::Exceptions::OpenTimeout
  raise ConnectionError.new('Error', { errors: ['Connection timeout'] }, nil)
rescue Errno::ECONNREFUSED, SocketError => e
  raise ConnectionError.new('Connection Error', { message: e.message }, nil)
rescue RestClient::ExceptionWithResponse => e
  response = Response.new(e.response)
  msg = response[:errors] || e.message
  raise ApiEndpointError.new(msg, response, response.code)
end