class ThisData::Client

For the ThisData REST APIv1 help.thisdata.com/docs/apiv1events

Constants

NO_API_KEY_MESSAGE
USER_AGENT

Public Class Methods

new() click to toggle source
# 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

Public Instance Methods

delete(path, query: {}) click to toggle source

Perform a DELETE request against the ThisData API, with the API key prepopulated

# 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: {}) click to toggle source

Perform a GET request against the ThisData API, with the API key prepopulated

# 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: {}) click to toggle source

Perform a POST request against the ThisData API, with the API key prepopulated

# 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() click to toggle source
# File lib/this_data/client.rb, line 22
def require_api_key
  ThisData.configuration.api_key || print_api_key_warning
end
track(event, options = {}) click to toggle source

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.
# File lib/this_data/client.rb, line 32
def track(event, options = {})
  post(ThisData::EVENTS_ENDPOINT, query: options, body: JSON.generate(event))
end

Private Instance Methods

print_api_key_warning() click to toggle source
version() click to toggle source
# File lib/this_data/client.rb, line 59
def version
  ThisData.configuration.version
end