Class: RJMetrics::Client
- Inherits:
-
Object
- Object
- RJMetrics::Client
- Defined in:
- lib/rjmetrics-client/client.rb
Defined Under Namespace
Classes: InvalidRequestException, InvalidResponseException, UnableToConnectException
Constant Summary collapse
- API_BASE =
default RJMetrics Data Import API url
"https://connect.rjmetrics.com/v2"
- SANDBOX_BASE =
RJMetrics Sandbox API url
"https://sandbox-connect.rjmetrics.com/v2"
- BATCH_SIZE =
Datapoints to push at a time
100
- DEFAULT_TIMEOUT_SECONDS =
Timout Seconds
10
Instance Method Summary collapse
-
#authenticated? ⇒ Boolean
Checks if the provided Client ID and API Key are valid.
-
#initialize(client_id, api_key, timeout_in_seconds = DEFAULT_TIMEOUT_SECONDS) ⇒ Client
constructor
Constructs a Client instance if it receives valid arguments or will raise an ArgumentError.
-
#pushData(table_name, data, url = API_BASE) ⇒ Array
Sends data to RJMetrics Data Import API in batches of 100.
Constructor Details
#initialize(client_id, api_key, timeout_in_seconds = DEFAULT_TIMEOUT_SECONDS) ⇒ Client
Constructs a Client instance if it receives valid arguments or will raise an ArgumentError.
26 27 28 29 30 31 |
# File 'lib/rjmetrics-client/client.rb', line 26 def initialize(client_id, api_key, timeout_in_seconds = DEFAULT_TIMEOUT_SECONDS) validateConstructorArgs(client_id, api_key, timeout_in_seconds) @client_id = client_id @api_key = api_key @timeout_in_seconds = timeout_in_seconds end |
Instance Method Details
#authenticated? ⇒ Boolean
Checks if the provided Client ID and API Key are valid.
34 35 36 37 38 39 40 41 |
# File 'lib/rjmetrics-client/client.rb', line 34 def authenticated? begin makeAuthAPICall() rescue InvalidRequestException return false end return true end |
#pushData(table_name, data, url = API_BASE) ⇒ Array
Sends data to RJMetrics Data Import API in batches of 100.
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rjmetrics-client/client.rb', line 49 def pushData(table_name, data, url = API_BASE) responses = Array.new validatePushDataArgs(table_name, data, url) if not data.is_a? Array data = Array.[](data) end data.each_slice(BATCH_SIZE) {|batch_data| responses << makePushDataAPICall(table_name, batch_data, url) } return responses end |