Class: ThisData::Client
- Inherits:
-
Object
- Object
- ThisData::Client
- Includes:
- HTTParty
- Defined in:
- lib/this_data/client.rb
Overview
For the ThisData REST APIv1 help.thisdata.com/docs/apiv1events
Constant Summary collapse
- USER_AGENT =
"ThisData Ruby v#{ThisData::VERSION}"- NO_API_KEY_MESSAGE =
"Oops: you've got no ThisData API Key configured, so we can't talk to the API. Specify your ThisData API key using ThisData#setup (find yours at https://thisdata.com)"
Instance Method Summary collapse
-
#delete(path, query: {}) ⇒ Object
Perform a DELETE request against the ThisData API, with the API key prepopulated.
-
#get(path, query: {}) ⇒ Object
Perform a GET request against the ThisData API, with the API key prepopulated.
-
#initialize ⇒ Client
constructor
A new instance of Client.
-
#post(path, query: {}, body: {}) ⇒ Object
Perform a POST request against the ThisData API, with the API key prepopulated.
- #require_api_key ⇒ Object
-
#track(event, options = {}) ⇒ Object
A convenience method for tracking Events.
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/this_data/client.rb', line 11 def initialize self.class.base_uri ThisData.configuration.base_uri @api_key = require_api_key @headers = { "User-Agent" => USER_AGENT } @default_query = { api_key: ThisData.configuration.api_key } end |
Instance Method Details
#delete(path, query: {}) ⇒ Object
Perform a DELETE request against the ThisData API, with the API key prepopulated
52 53 54 55 |
# File 'lib/this_data/client.rb', line 52 def delete(path, query: {}) query = @default_query.merge(query) self.class.delete(path, query: query, headers: @headers) end |
#get(path, query: {}) ⇒ Object
Perform a GET request against the ThisData API, with the API key prepopulated
38 39 40 41 |
# File 'lib/this_data/client.rb', line 38 def get(path, query: {}) query = @default_query.merge(query) self.class.get(path, query: query, headers: @headers) end |
#post(path, query: {}, body: {}) ⇒ Object
Perform a POST request against the ThisData API, with the API key prepopulated
45 46 47 48 |
# File 'lib/this_data/client.rb', line 45 def post(path, query: {}, body: {}) query = @default_query.merge(query) self.class.post(path, query: query, headers: @headers, body: body) end |
#require_api_key ⇒ Object
22 23 24 |
# File 'lib/this_data/client.rb', line 22 def require_api_key ThisData.configuration.api_key || print_api_key_warning end |
#track(event, options = {}) ⇒ Object
A convenience method for tracking Events.
Parameters:
-
event (Required: Hash) a Hash containing details about the event.
See http://help.thisdata.com/v1.0/docs/apiv1events for a full & current list of available options.
32 33 34 |
# File 'lib/this_data/client.rb', line 32 def track(event, = {}) post(ThisData::EVENTS_ENDPOINT, query: , body: JSON.generate(event)) end |