Class: LogSnag::Client

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

Constant Summary collapse

BASE_URL =
"https://api.logsnag.com/v1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Client.



7
8
9
10
11
12
13
# File 'lib/log_snag/client.rb', line 7

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

  # Test stubs for requests
  @stubs = stubs
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



5
6
7
# File 'lib/log_snag/client.rb', line 5

def adapter
  @adapter
end

#tokenObject (readonly)

Returns the value of attribute token.



5
6
7
# File 'lib/log_snag/client.rb', line 5

def token
  @token
end

Instance Method Details

#connectionObject



25
26
27
28
29
30
31
32
# File 'lib/log_snag/client.rb', line 25

def connection
  @connection ||= Faraday.new(BASE_URL) do |conn|
    conn.request :authorization, :Bearer, token
    conn.request :json
    conn.response :json
    conn.adapter adapter, @stubs
  end
end

#insight(project:, title:, value:, **params) ⇒ Object



20
21
22
23
# File 'lib/log_snag/client.rb', line 20

def insight(project:, title:, value:, **params)
  attributes = {project: project, title: title, value: value}
  Insight.new post_request("insight", body: attributes.merge(params)).body
end

#log(project:, channel:, event:, **params) ⇒ Object



15
16
17
18
# File 'lib/log_snag/client.rb', line 15

def log(project:, channel:, event:, **params)
  attributes = {project: project, channel: channel, event: event}
  Log.new post_request("log", body: attributes.merge(params)).body
end