Class: RJMetricsClient

Inherits:
Object
  • Object
show all
Defined in:
lib/rjmetrics_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client_id, api_key, timeout_in_seconds = 10) ⇒ RJMetricsClient

Constructs a RJMetricsClient instance if it receives valid arguments or will raise an ArgumentError.

Parameters:

  • client_id (Integer)

    your RJMetrics Client ID

  • api_key (String)

    your RJMetrics API Key

  • timeout_in_seconds (Integer) (defaults to: 10)

    seconds to wait for API responses



10
11
12
13
14
15
16
# File 'lib/rjmetrics_client.rb', line 10

def initialize(client_id, api_key, timeout_in_seconds = 10)
  @client = RJMetrics::Client.new(client_id, api_key, timeout_in_seconds)

  if not authenticated?
    raise RJMetrics::Client::UnableToConnectException, "Connection failed. Please double check your credentials."
  end
end

Instance Method Details

#authenticated?Boolean

Validates credentials by making a request to the RJMetrics API Sandbox.

Returns:

  • (Boolean)


19
20
21
# File 'lib/rjmetrics_client.rb', line 19

def authenticated?
  return @client.authenticated?
end

#pushData(table_name, data, url = RJMetrics::Client::API_BASE) ⇒ Array

Sends data to RJMetrics Data Import API.

Parameters:

  • table_name (String)

    the table name you wish to store the data

  • data (Hashamp)

    or Array of Hashmaps of data points that will get sent

  • url (String) (defaults to: RJMetrics::Client::API_BASE)

    Import API url

Returns:

  • (Array)

    results of each request to RJMetrics Data Import API



29
30
31
# File 'lib/rjmetrics_client.rb', line 29

def pushData(table_name, data, url = RJMetrics::Client::API_BASE)
  @client.pushData(table_name, data, url)
end