Class: ApiAuth::Client::Connection
- Inherits:
-
Object
- Object
- ApiAuth::Client::Connection
- Defined in:
- lib/api_auth/client/connection.rb
Instance Attribute Summary collapse
-
#app_id ⇒ Object
readonly
Returns the value of attribute app_id.
-
#secret_key ⇒ Object
readonly
Returns the value of attribute secret_key.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(url:, app_id: nil, secret_key: nil) ⇒ Connection
constructor
A new instance of Connection.
-
#query(mtd, path, payload = {}) ⇒ Object
rubocop:disable Metrics/AbcSize.
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_id ⇒ Object (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_key ⇒ Object (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 |
#url ⇒ Object (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. }, nil) rescue RestClient::ExceptionWithResponse => e response = Response.new(e.response) msg = response[:errors] || e. raise ApiEndpointError.new(msg, response, response.code) end |