class DataSift::Client
All API requests must be made by a Client
object
Attributes
Public Class Methods
@param config [Hash] A hash containing configuration options for the
client for e.g. { username: 'some_user', api_key: 'ds_api_key', enable_ssl: true, open_timeout: 30, timeout: 30 }
# File lib/datasift.rb, line 67 def initialize(config) raise InvalidConfigError.new('Config cannot be nil') if config.nil? if !config.key?(:username) || !config.key?(:api_key) raise InvalidConfigError.new('A valid username and API key are required. ' + 'You can check your API credentials at https://app.datasift.com/settings') end @config = config @historics = DataSift::Historics.new(config) @push = DataSift::Push.new(config) @managed_source = DataSift::ManagedSource.new(config) @managed_source_resource = DataSift::ManagedSourceResource.new(config) @managed_source_auth = DataSift::ManagedSourceAuth.new(config) @historics_preview = DataSift::HistoricsPreview.new(config) @pylon = DataSift::Pylon.new(config) @task = DataSift::Task.new(config) @account = DataSift::Account.new(config) @account_identity = DataSift::AccountIdentity.new(config) @account_identity_token = DataSift::AccountIdentityToken.new(config) @account_identity_limit = DataSift::AccountIdentityLimit.new(config) @odp = DataSift::Odp.new(config) end
Public Instance Methods
Determine your credit balance or DPU balance.
@return [Object] API reponse object
# File lib/datasift.rb, line 143 def balance DataSift.request(:POST, 'balance', @config) end
Compile CSDL code.
@param csdl [String] The CSDL you wish to compile @return [Object] API reponse object
# File lib/datasift.rb, line 108 def compile(csdl) requires({ :csdl => csdl }) DataSift.request(:POST, 'compile', @config, :csdl => csdl ) end
Calculate the DPU cost of running a filter, or Historics
query
@param hash [String] CSDL hash for which you wish to find the DPU cost @param historics_id [String] ID of Historics
query for which you wish to
find the DPU cost
@return [Object] API reponse object
# File lib/datasift.rb, line 127 def dpu(hash = '', historics_id = '') fail ArgumentError, 'Must pass a filter hash or Historics ID' if hash.empty? && historics_id.empty? fail ArgumentError, 'Must only pass hash or Historics ID; not both' unless hash.empty? || historics_id.empty? params = {} params.merge!(hash: hash) unless hash.empty? params.merge!(historics_id: historics_id) unless historics_id.empty? DataSift.request(:POST, 'dpu', @config, params) end
Collect a batch of interactions from a push queue
@param id [String] ID of the Push
subscription you wish to pull data from @param size [Integer] Max size (bytes) of the data you can receive from a
/pull API call
@param cursor [String] A pointer into the Push
queue associated with your
last delivery
@return [Object] API reponse object
# File lib/datasift.rb, line 155 def pull(id, size = 20_971_520, cursor='') DataSift.request(:POST, 'pull', @config, { :id => id, :size => size, :cursor => cursor }) end
Check the number of objects processed for a given time period
@param period [String] Can be “day”, “hour”, or “current” @return [Object] API reponse object
# File lib/datasift.rb, line 117 def usage(period = :hour) DataSift.request(:POST, 'usage', @config, :period => period ) end
Checks if the syntax of the given CSDL is valid
@param boolResponse [Boolean] If true a boolean is returned indicating whether the CSDL is valid, otherwise the full response object is returned
# File lib/datasift.rb, line 98 def valid?(csdl, boolResponse = true) requires({ :csdl => csdl }) res = DataSift.request(:POST, 'validate', @config, :csdl => csdl ) boolResponse ? res[:http][:status] == 200 : res end