Module: Botan

Defined in:
lib/botan.rb,
lib/botan/version.rb,
lib/botan/exceptions.rb,
lib/botan/configuration.rb

Defined Under Namespace

Classes: Configuration, Error, ResponseError

Constant Summary collapse

API_URL =
'https://api.botan.io'.freeze
VERSION =
"0.1.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject



31
32
33
# File 'lib/botan.rb', line 31

def self.configuration
  @configuration ||= Configuration.new
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Yields:



35
36
37
# File 'lib/botan.rb', line 35

def self.configure
  yield(configuration)
end

.track(uid, message, name, token = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/botan.rb', line 15

def self.track(uid, message, name, token = nil)
  token = token || Botan.configuration.token

  begin
    response = Faraday.new(url: API_URL).post do |req|
      req.url "/track?token=#{token}&uid=#{uid}&name=#{name}"
      req.headers['Content-Type'] = 'application/json'
      req.body = JSON.dump({text: message})
    end

    JSON.parse(response.body)
  rescue => e
    raise Botan::ResponseError.new(e.message)
  end
end