Class: DataSift::Pylon

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

Overview

Class for accessing DataSift’s PYLON API

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 Method Summary collapse

Methods inherited from ApiResource

#initialize, #requires

Methods included from DataSift

#build_path, request

Constructor Details

This class inherits a constructor from DataSift::ApiResource

Instance Method Details

#analyze(hash = '', parameters = '', filter = '', start_time = nil, end_time = nil, id = '', service = 'facebook') ⇒ Object

Perform a PYLON analysis query by making an /pylon/analyze API call

Parameters:

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

    Hash of the recording you wish to perform an analysis against

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

    Parameters of the analysis you wish to perform. See the /pylon/analyze API Docs for full documentation

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

    Optional PYLON CSDL for a query filter

  • start_time (Integer) (defaults to: nil)

    Optional start timestamp for filtering by date

  • end_time (Integer) (defaults to: nil)

    Optional end timestamp for filtering by date

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

    ID of the recording you wish to analyze

  • service (String) (defaults to: 'facebook')

    The PYLON service to make this API call against

Returns:

  • (Object)

    API reponse object



159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/pylon.rb', line 159

def analyze(hash = '', parameters = '', filter = '', start_time = nil, end_time = nil, id = '', service = 'facebook')
  fail BadParametersError, 'hash or id is required' if hash.empty? && id.empty?
  fail BadParametersError, 'parameters is required' if parameters.empty?
  fail BadParametersError, 'service is required' if service.empty?

  params = { parameters: parameters }
  params.merge!(hash: hash) unless hash.empty?
  params.merge!(id: id) unless id.empty?
  params.merge!(filter: filter) unless filter.empty?
  params.merge!(start: start_time) unless start_time.nil?
  params.merge!(end: end_time) unless end_time.nil?

  DataSift.request(:POST, build_path(service, 'pylon/analyze', @config), @config, params)
end

#compile(csdl, service = 'facebook') ⇒ Object

Compile PYLON CSDL by making an /pylon/compile API call

Parameters:

  • csdl (String)

    CSDL you wish to compile

  • service (String) (defaults to: 'facebook')

    The PYLON service to make this API call against

Returns:

  • (Object)

    API reponse object



27
28
29
30
31
32
33
34
# File 'lib/pylon.rb', line 27

def compile(csdl, service = 'facebook')
  fail BadParametersError, 'csdl is required' if csdl.empty?
  fail BadParametersError, 'service is required' if service.empty?

  params = { csdl: csdl }

  DataSift.request(:POST, build_path(service, 'pylon/compile', @config), @config, params)
end

#get(hash = '', id = '', service = 'facebook') ⇒ Object

Perform /pylon/get API call to query status of your PYLON recordings

Parameters:

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

    Hash you with the get the status for

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

    The ID of the PYLON recording to get

  • service (String) (defaults to: 'facebook')

    The PYLON service to make this API call against

Returns:

  • (Object)

    API reponse object



42
43
44
45
46
47
48
49
50
51
# File 'lib/pylon.rb', line 42

def get(hash = '', id = '', service = 'facebook')
  fail BadParametersError, 'hash or id is required' if hash.empty? && id.empty?
  fail BadParametersError, 'service is required' if service.empty?

  params = {}
  params.merge!(hash: hash) unless hash.empty?
  params.merge!(id: id) unless id.empty?

  DataSift.request(:GET, build_path(service, 'pylon/get', @config), @config, params)
end

#list(page = nil, per_page = nil, order_by = '', order_dir = '', service = 'facebook') ⇒ Object

Perform /pylon/get API call to list all PYLON Recordings

Parameters:

  • page (Integer) (defaults to: nil)

    Which page of recordings to retreive

  • per_page (Integer) (defaults to: nil)

    How many recordings to return per page

  • order_by (String, Symbol) (defaults to: '')

    Which field to sort results by

  • order_dir (String, Symbol) (defaults to: '')

    Order results in ascending or descending order

  • service (String) (defaults to: 'facebook')

    The PYLON service to make this API call against

Returns:

  • (Object)

    API reponse object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/pylon.rb', line 62

def list(page = nil, per_page = nil, order_by = '', order_dir = '', service = 'facebook')
  fail BadParametersError, 'service is required' if service.empty?

  params = {}
  params.merge!(page: page) unless page.nil?
  params.merge!(per_page: per_page) unless per_page.nil?
  params.merge!(order_by: order_by) unless order_by.empty?
  params.merge!(order_dir: order_dir) unless order_dir.empty?

  DataSift.request(:GET, build_path(service, 'pylon/get', @config), @config, params)
end

#reference(service:, slug: '', **opts) ⇒ Object

Hit the PYLON Reference endpoint to expose reference data sets

**opts

Parameters:

  • service (String)

    The PYLON service to make this API call against

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

    Optional slug of the reference data set you would like to explore

  • per_page (Integer)

    (Optional) How many data sets should be returned per page of results

  • page (Integer)

    (Optional) Which page of results to return



228
229
230
231
232
233
234
# File 'lib/pylon.rb', line 228

def reference(service:, slug: '', **opts)
  params = {}
  params[:per_page] = opts[:per_page] if opts.key?(:per_page)
  params[:page] = opts[:page] if opts.key?(:page)

  DataSift.request(:GET, "pylon/#{service}/reference/#{slug}", @config, params)
end

#restart(id, name = '', service = 'facebook') ⇒ Object

Restart an existing PYLON recording by making an /pylon/start API call with a recording ID

Parameters:

  • id (String)

    CSDL you wish to begin (or resume) recording

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

    Give your recording a name. Required when starting a new recording

  • service (String) (defaults to: 'facebook')

    The PYLON service to make this API call against

Returns:

  • (Object)

    API reponse object



118
119
120
121
122
123
124
125
126
# File 'lib/pylon.rb', line 118

def restart(id, name = '', service = 'facebook')
  fail BadParametersError, 'id is required' if id.empty?
  fail BadParametersError, 'service is required' if service.empty?

  params = { id: id }
  params.merge!(name: name) unless name.empty?

  DataSift.request(:PUT, build_path(service, 'pylon/start', @config), @config, params)
end

#sample(hash = '', count = nil, start_time = nil, end_time = nil, filter = '', id = '', service = 'facebook') ⇒ Object

Hit the PYLON Sample endpoint to pull public sample data from a PYLON recording

Parameters:

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

    The CSDL hash that identifies the recording you want to sample

  • count (Integer) (defaults to: nil)

    Optional number of public interactions you wish to receive

  • start_time (Integer) (defaults to: nil)

    Optional start timestamp for filtering by date

  • end_time (Integer) (defaults to: nil)

    Optional end timestamp for filtering by date

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

    Optional PYLON CSDL for a query filter

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

    ID of the recording you wish to sample

  • service (String) (defaults to: 'facebook')

    The PYLON service to make this API call against

Returns:

  • (Object)

    API reponse object



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/pylon.rb', line 202

def sample(hash = '', count = nil, start_time = nil, end_time = nil, filter = '', id = '', service = 'facebook')
  fail BadParametersError, 'hash or id is required' if hash.empty? && id.empty?
  fail BadParametersError, 'service is required' if service.empty?

  params = {}
  params.merge!(hash: hash) unless hash.empty?
  params.merge!(id: id) unless id.empty?
  params.merge!(count: count) unless count.nil?
  params.merge!(start_time: start_time) unless start_time.nil?
  params.merge!(end_time: end_time) unless end_time.nil?

  if filter.empty?
    DataSift.request(:GET, build_path(service, 'pylon/sample', @config), @config, params)
  else
    params.merge!(filter: filter)
    DataSift.request(:POST, build_path(service, 'pylon/sample', @config), @config, params)
  end
end

#start(hash = '', name = '', id = '', service = 'facebook') ⇒ Object

Start recording a PYLON filter by making an /pylon/start API call

Parameters:

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

    CSDL you wish to begin (or resume) recording

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

    Give your recording a name. Required when starting a

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

    ID of the recording you wish to start new recording

  • service (String) (defaults to: 'facebook')

    The PYLON service to make this API call against

Returns:

  • (Object)

    API reponse object



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/pylon.rb', line 99

def start(hash = '', name = '', id = '', service = 'facebook')
  fail BadParametersError, 'hash or id is required' if hash.empty? && id.empty?
  fail BadParametersError, 'service is required' if service.empty?

  params = {}
  params.merge!(hash: hash) unless hash.empty?
  params.merge!(name: name) unless name.empty?
  params.merge!(id: id) unless id.empty?

  DataSift.request(:PUT, build_path(service, 'pylon/start', @config), @config, params)
end

#stop(hash = '', id = '', service = 'facebook') ⇒ Object

Stop an active PYLON recording by making an /pylon/stop API call

Parameters:

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

    CSDL you wish to stop recording

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

    ID of the recording you wish to stop

  • service (String) (defaults to: 'facebook')

    The PYLON service to make this API call against

Returns:

  • (Object)

    API reponse object



134
135
136
137
138
139
140
141
142
143
# File 'lib/pylon.rb', line 134

def stop(hash = '', id = '', service = 'facebook')
  fail BadParametersError, 'hash or id is required' if hash.empty? && id.empty?
  fail BadParametersError, 'service is required' if service.empty?

  params = {}
  params.merge!(hash: hash) unless hash.empty?
  params.merge!(id: id) unless id.empty?

  DataSift.request(:PUT, build_path(service, 'pylon/stop', @config), @config, params)
end

#tags(hash = '', id = '', service = 'facebook') ⇒ Object

Query the tag hierarchy on interactions populated by a particular

recording

Parameters:

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

    Hash of the recording you wish to query

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

    ID of the recording you wish to query

  • service (String) (defaults to: 'facebook')

    The PYLON service to make this API call against

Returns:

  • (Object)

    API reponse object



181
182
183
184
185
186
187
188
189
190
# File 'lib/pylon.rb', line 181

def tags(hash = '', id = '', service = 'facebook')
  fail BadParametersError, 'hash or id is required' if hash.empty? && id.empty?
  fail BadParametersError, 'service is required' if service.empty?

  params = {}
  params.merge!(hash: hash) unless hash.empty?
  params.merge!(id: id) unless id.empty?

  DataSift.request(:GET, build_path(service, 'pylon/tags', @config), @config, params)
end

#update(id, hash = '', name = '', service = 'facebook') ⇒ Object

Perform /pylon/update API call to update a given PYLON Recording

Parameters:

  • id (String)

    The ID of the PYLON recording to update

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

    The CSDL filter hash this recording should be subscribed to

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

    Update the name of your recording

  • service (String) (defaults to: 'facebook')

    The PYLON service to make this API call against

Returns:

  • (Object)

    API reponse object



81
82
83
84
85
86
87
88
89
# File 'lib/pylon.rb', line 81

def update(id, hash = '', name = '', service = 'facebook')
  fail BadParametersError, 'service is required' if service.empty?

  params = { id: id }
  params.merge!(hash: hash) unless hash.empty?
  params.merge!(name: name) unless name.empty?

  DataSift.request(:PUT, build_path(service, 'pylon/update', @config), @config, params)
end

#valid?(csdl = '', boolResponse = true, service = 'facebook') ⇒ Boolean, Object

Check PYLON CSDL is valid by making an /pylon/validate API call

Parameters:

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

    CSDL you wish to validate

  • boolResponse (Boolean) (defaults to: true)

    True if you want a boolean response.

  • service (String) (defaults to: 'facebook')

    The PYLON service to make this API call against False if you want the full response object

Returns:

  • (Boolean, Object)

    Dependent on value of boolResponse



12
13
14
15
16
17
18
19
20
# File 'lib/pylon.rb', line 12

def valid?(csdl = '', boolResponse = true, service = 'facebook')
  fail BadParametersError, 'csdl is required' if csdl.empty?
  fail BadParametersError, 'service is required' if service.empty?

  params = { csdl: csdl }

  res = DataSift.request(:POST, build_path(service, 'pylon/validate', @config), @config, params)
  boolResponse ? res[:http][:status] == 200 : res
end