Class: LogSnag::Client
- Inherits:
-
Object
- Object
- LogSnag::Client
- Defined in:
- lib/log_snag/client.rb
Constant Summary collapse
- BASE_URL =
"https://api.logsnag.com/v1"
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize(token:, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client
constructor
A new instance of Client.
- #log(project:, channel:, event:, **params) ⇒ Object
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
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
5 6 7 |
# File 'lib/log_snag/client.rb', line 5 def adapter @adapter end |
#token ⇒ Object (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
#connection ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/log_snag/client.rb', line 20 def connection @connection ||= Faraday.new(BASE_URL) do |conn| conn.request :authorization, :basic, token conn.request :json conn.response :json conn.adapter adapter, @stubs end 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 |