Class: Bugscriber::Client

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

Constant Summary collapse

BASE_URL =
'https://bugscriber-api.herokuapp.com'
AUTHORIZATION_HEADER_KEY =
'X-API-KEY'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter: Faraday.default_adapter, stubs: nil) ⇒ Client

Returns a new instance of Client.



10
11
12
13
# File 'lib/bugscriber/client.rb', line 10

def initialize(adapter: Faraday.default_adapter, stubs: nil)
  @adapter = adapter
  @stubs = stubs
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



8
9
10
# File 'lib/bugscriber/client.rb', line 8

def adapter
  @adapter
end

#stubsObject (readonly)

Returns the value of attribute stubs.



8
9
10
# File 'lib/bugscriber/client.rb', line 8

def stubs
  @stubs
end

Instance Method Details

#connectionObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bugscriber/client.rb', line 15

def connection
  @connection ||= Faraday.new(BASE_URL) do |conn|
    conn.request :json
    conn.response :json, content_type: 'application/json'
    unless Bugscriber.config.logger.blank?
      conn.response :logger, Bugscriber.config.logger, body: true,
                                                       bodies: { request: true, response: true }
    end
    conn.headers[AUTHORIZATION_HEADER_KEY] = Bugscriber.config.api_key
    conn.adapter adapter, stubs
  end
end

#tracksObject



28
29
30
# File 'lib/bugscriber/client.rb', line 28

def tracks
  Bugscriber::Resources::Tracks.new(self)
end