Class: Framed::Client
- Inherits:
-
Object
- Object
- Framed::Client
- Defined in:
- lib/framed/client.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(config) ⇒ Client
constructor
A new instance of Client.
- #track(data) ⇒ Object
Constructor Details
#initialize(config) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 |
# File 'lib/framed/client.rb', line 11 def initialize(config) raise Error.new('No API endpoint specified') unless config[:endpoint] raise Error.new('No api_key specified') unless config[:api_key] @config = config end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
9 10 11 |
# File 'lib/framed/client.rb', line 9 def config @config end |
Instance Method Details
#track(data) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/framed/client.rb', line 18 def track(data) creds = Base64.strict_encode64(@config[:api_key] + ':') payload = JSON.generate(data) response = Excon.post(@config[:endpoint], :headers => { 'Authorization' => "Basic #{creds}", 'Content-Type' => 'application/json' }, :body => payload ) if response.status != 200 raise Framed::RequestError.new("Failed Client.track #{response.status} with data #{payload}") end end |