Class: CardConnect::Connection
- Inherits:
-
Object
- Object
- CardConnect::Connection
- Defined in:
- lib/cardconnect/connection.rb
Instance Method Summary collapse
- #connection ⇒ Object
- #faraday_options ⇒ Object
-
#initialize(config = CardConnect.configuration) ⇒ Connection
constructor
A new instance of Connection.
- #ping_server ⇒ Object
Constructor Details
#initialize(config = CardConnect.configuration) ⇒ Connection
Returns a new instance of Connection.
6 7 8 |
# File 'lib/cardconnect/connection.rb', line 6 def initialize(config = CardConnect.configuration) @config = config end |
Instance Method Details
#connection ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/cardconnect/connection.rb', line 10 def connection @connection ||= Faraday.new() do |f| f.request :basic_auth, @config.api_username, @config.api_password f.request :json f.response :json, content_type: /\bjson$/ f.response :raise_error f.adapter Faraday.default_adapter end end |
#faraday_options ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/cardconnect/connection.rb', line 30 def { url: @config.endpoint, headers: { user_agent: "CardConnectRubyGem/#{CardConnect::VERSION}" }, }.merge(@config.) end |
#ping_server ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/cardconnect/connection.rb', line 22 def ping_server connection.get('/cardconnect/rest/') rescue Faraday::ResourceNotFound => e return e rescue Faraday::ClientError => e return e end |