Class: DataSift::Client

Inherits:
ApiResource show all
Defined in:
lib/datasift.rb

Overview

All API requests must be made by a Client object

Constant Summary

Constants inherited from ApiResource

ApiResource::TLSv1, ApiResource::TLSv1_2

Constants included from DataSift

APPLICATION_JSON, DELETE, DETECT_DEAD_SOCKETS, GET, HEAD, IS_WINDOWS, KNOWN_SOCKETS, SOCKET_DETECTOR_TIMEOUT, VERSION, X_ANALYSIS_TASKS_QUEUED, X_ANALYSIS_TASKS_QUEUE_LIMIT, X_INSIGHT_TASKS_QUEUED, X_INSIGHT_TASKS_QUEUE_LIMIT, X_RATELIMIT_COST, X_RATELIMIT_LIMIT, X_RATELIMIT_REMAINING, X_TASKS_QUEUED, X_TASKS_QUEUE_LIMIT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ApiResource

#requires

Methods included from DataSift

#build_path, request

Constructor Details

#initialize(config) ⇒ Client

Returns a new instance of Client.

Parameters:

  • 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 }

Raises:



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# 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::.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

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account.



90
91
92
# File 'lib/datasift.rb', line 90

def 
  @account
end

#account_identityObject (readonly)

Returns the value of attribute account_identity.



90
91
92
# File 'lib/datasift.rb', line 90

def 
  @account_identity
end

#account_identity_limitObject (readonly)

Returns the value of attribute account_identity_limit.



90
91
92
# File 'lib/datasift.rb', line 90

def 
  @account_identity_limit
end

#account_identity_tokenObject (readonly)

Returns the value of attribute account_identity_token.



90
91
92
# File 'lib/datasift.rb', line 90

def 
  @account_identity_token
end

#configObject (readonly)

Returns the value of attribute config.



90
91
92
# File 'lib/datasift.rb', line 90

def config
  @config
end

#historicsObject (readonly)

Returns the value of attribute historics.



90
91
92
# File 'lib/datasift.rb', line 90

def historics
  @historics
end

#historics_previewObject (readonly)

Returns the value of attribute historics_preview.



90
91
92
# File 'lib/datasift.rb', line 90

def historics_preview
  @historics_preview
end

#managed_sourceObject (readonly)

Returns the value of attribute managed_source.



90
91
92
# File 'lib/datasift.rb', line 90

def managed_source
  @managed_source
end

#managed_source_authObject (readonly)

Returns the value of attribute managed_source_auth.



90
91
92
# File 'lib/datasift.rb', line 90

def managed_source_auth
  @managed_source_auth
end

#managed_source_resourceObject (readonly)

Returns the value of attribute managed_source_resource.



90
91
92
# File 'lib/datasift.rb', line 90

def managed_source_resource
  @managed_source_resource
end

#odpObject (readonly)

Returns the value of attribute odp.



90
91
92
# File 'lib/datasift.rb', line 90

def odp
  @odp
end

#pushObject (readonly)

Returns the value of attribute push.



90
91
92
# File 'lib/datasift.rb', line 90

def push
  @push
end

#pylonObject (readonly)

Returns the value of attribute pylon.



90
91
92
# File 'lib/datasift.rb', line 90

def pylon
  @pylon
end

#taskObject (readonly)

Returns the value of attribute task.



90
91
92
# File 'lib/datasift.rb', line 90

def task
  @task
end

Instance Method Details

#balanceObject

Determine your credit balance or DPU balance.

Returns:

  • (Object)

    API reponse object



143
144
145
# File 'lib/datasift.rb', line 143

def balance
  DataSift.request(:POST, 'balance', @config)
end

#compile(csdl) ⇒ Object

Compile CSDL code.

Parameters:

  • csdl (String)

    The CSDL you wish to compile

Returns:

  • (Object)

    API reponse object



108
109
110
111
# File 'lib/datasift.rb', line 108

def compile(csdl)
  requires({ :csdl => csdl })
  DataSift.request(:POST, 'compile', @config, :csdl => csdl )
end

#dpu(hash = '', historics_id = '') ⇒ Object

Calculate the DPU cost of running a filter, or Historics query

Parameters:

  • hash (String) (defaults to: '')

    CSDL hash for which you wish to find the DPU cost

  • historics_id (String) (defaults to: '')

    ID of Historics query for which you wish to find the DPU cost

Returns:

  • (Object)

    API reponse object



127
128
129
130
131
132
133
134
135
136
137
138
# 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

#pull(id, size = 20_971_520, cursor = '') ⇒ Object

Collect a batch of interactions from a push queue

Parameters:

  • id (String)

    ID of the Push subscription you wish to pull data from

  • size (Integer) (defaults to: 20_971_520)

    Max size (bytes) of the data you can receive from a /pull API call

  • cursor (String) (defaults to: '')

    A pointer into the Push queue associated with your last delivery

Returns:

  • (Object)

    API reponse object



155
156
157
158
# 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

#usage(period = :hour) ⇒ Object

Check the number of objects processed for a given time period

Parameters:

  • period (String) (defaults to: :hour)

    Can be “day”, “hour”, or “current”

Returns:

  • (Object)

    API reponse object



117
118
119
# File 'lib/datasift.rb', line 117

def usage(period = :hour)
  DataSift.request(:POST, 'usage', @config, :period => period )
end

#valid?(csdl, boolResponse = true) ⇒ Boolean

Checks if the syntax of the given CSDL is valid

whether the CSDL is valid, otherwise the full response object is returned

Parameters:

  • boolResponse (Boolean) (defaults to: true)

    If true a boolean is returned indicating

Returns:

  • (Boolean)


98
99
100
101
102
# 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