Class: DataSift::Push

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

Overview

Push is a simple and robust mechanism for periodically delivering your data

directly to a given destination. Several widely adopted storage locations
are available including Amazon S3, (S)FTP, HTTP, DynamoDB, CouchDB,
MongoDB, Splunk, ElasticSearch and more! See
http://dev.datasift.com/docs/push/connectors

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

#create(params) ⇒ Object

Create a new subscription to a live stream or historics query. Possible

params are hash, historics_id, name, output_type, initial_status, start,
end and output_params.* where output_params.* depends on the output_type
for specific options see the documentation at
http://dev.datasift.com/docs/rest-api/pushcreate For a list of available
connectors see http://dev.datasift.com/docs/push/connectors

Parameters:

  • params (Hash)

    Hash of Push subscription parameters



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

def create(params)
  DataSift.request(:POST, 'push/create', @config, params)
end

#delete(id) ⇒ Object

Deletes an existing push subscription

Parameters:

  • id (String)

    ID of the Push subscription to delete



70
71
72
73
74
# File 'lib/push.rb', line 70

def delete(id)
  params = {:id => id}
  requires params
  DataSift.request(:DELETE, 'push/delete', @config, params)
end

#get(page = 1, per_page = 20, order_by = :created_at, order_dir = :desc, include_finished = 0, all = false) ⇒ Object

Get details of all subscriptions within the given page constraints

Parameters:

  • page (Integer) (defaults to: 1)

    Which page of logs to retreive

  • per_page (Integer) (defaults to: 20)

    How many logs to return per page

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

    Which field to sort results by

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

    Order results in ascending or descending

  • include_finished (Integer) (defaults to: 0)

    Include Push subscriptions in a ‘finished’ state in your results

  • all (Boolean) (defaults to: false)

    Also include Push subscriptions created via the web UI in your results



183
184
185
186
187
188
189
190
191
192
193
# File 'lib/push.rb', line 183

def get(page = 1, per_page = 20, order_by = :created_at, order_dir = :desc, include_finished = 0, all = false)
  params = {
    :page => page,
    :per_page => per_page,
    :order_by => order_by,
    :order_dir => order_dir,
    :include_finished => include_finished,
    :all => all
  }
  DataSift.request(:GET, 'push/get', @config, params)
end

#get_by_hash(hash, page = 1, per_page = 20, order_by = :created_at, order_dir = :desc, include_finished = 0, all = false) ⇒ Object

Get details of the subscription with the given filter hash

Parameters:

  • hash (String)

    CSDL filter hash

  • page (Integer) (defaults to: 1)

    Which page of logs to retreive

  • per_page (Integer) (defaults to: 20)

    How many logs to return per page

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

    Which field to sort results by

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

    Order results in ascending or descending

  • include_finished (Integer) (defaults to: 0)

    Include Push subscriptions in a ‘finished’ state in your results

  • all (Boolean) (defaults to: false)

    Also include Push subscriptions created via the web UI in your results



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/push.rb', line 132

def get_by_hash(hash, page = 1, per_page = 20, order_by = :created_at, order_dir = :desc, include_finished = 0, all = false)
  params = {
    :hash => hash
  }
  requires params
  params.merge!(
    :page => page,
    :per_page => per_page,
    :order_by => order_by,
    :order_dir => order_dir,
    :include_finished => include_finished,
    :all => all
  )
  DataSift.request(:GET, 'push/get', @config, params)
end

#get_by_historics_id(historics_id, page = 1, per_page = 20, order_by = :created_at, order_dir = :desc, include_finished = 0, all = false) ⇒ Object

Get details of the subscription with the given Historics ID

Parameters:

  • historics_id (String)

    ID of the Historics query for which you are searching for the related Push subscription

  • page (Integer) (defaults to: 1)

    Which page of logs to retreive

  • per_page (Integer) (defaults to: 20)

    How many logs to return per page

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

    Which field to sort results by

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

    Order results in ascending or descending

  • include_finished (Integer) (defaults to: 0)

    Include Push subscriptions in a ‘finished’ state in your results

  • all (Boolean) (defaults to: false)

    Also include Push subscriptions created via the web UI in your results



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

def get_by_historics_id(historics_id, page = 1, per_page = 20, order_by = :created_at, order_dir = :desc, include_finished = 0, all = false)
  params = {
    :historics_id => historics_id,
    :page => page,
    :per_page => per_page,
    :order_by => order_by,
    :order_dir => order_dir,
    :include_finished => include_finished,
    :all => all
  }
  DataSift.request(:GET, 'push/get', @config, params)
end

#get_by_subscription(id) ⇒ Object

Get details of the subscription with the given ID

Parameters:

  • id (String)

    ID of the subscription to retrieve



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

def get_by_subscription(id)
  params = { :id => id }
  DataSift.request(:GET, 'push/get', @config, params)
end

#log(page = 1, per_page = 20, order_by = :request_time, order_dir = :desc) ⇒ Object

Retrieve log messages for all subscriptions

Parameters:

  • page (Integer) (defaults to: 1)

    Which page of logs to retreive

  • per_page (Integer) (defaults to: 20)

    How many logs to return per page

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

    Which field to sort results by

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

    Order results in ascending or descending



103
104
105
106
107
108
109
110
111
# File 'lib/push.rb', line 103

def log(page = 1, per_page = 20, order_by = :request_time, order_dir = :desc)
  params = {
    :page => page,
    :per_page => per_page,
    :order_by => order_by,
    :order_dir => order_dir
  }
  DataSift.request(:GET, 'push/log', @config, params)
end

#log_for(id, page = 1, per_page = 20, order_by = :request_time, order_dir = :desc) ⇒ Object

Retrieve log messages for a specific subscription

Parameters:

  • id (String)

    ID of the Push subscription to retrieve logs for

  • page (Integer) (defaults to: 1)

    Which page of logs to retreive

  • per_page (Integer) (defaults to: 20)

    How many logs to return per page

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

    Which field to sort results by

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

    Order results in ascending or descending



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/push.rb', line 83

def log_for(id, page = 1, per_page = 20, order_by = :request_time, order_dir = :desc)
  params = {
    :id => id
  }
  requires params
  params.merge!(
    :page => page,
    :per_page => per_page,
    :order_by => order_by,
    :order_dir => order_dir
  )
  DataSift.request(:GET, 'push/log', @config, params)
end

#pause(id) ⇒ Object

Pause a subscription and buffer the data for up to an hour

Parameters:

  • id (String)

    ID of the Push subscription to pause



43
44
45
46
47
# File 'lib/push.rb', line 43

def pause(id)
  params = { :id => id }
  requires params
  DataSift.request(:PUT, 'push/pause', @config, params)
end

#pull(id, size = 52_428_800, cursor = '', callback = nil) ⇒ Object

Pull data from a ‘pull’ type Push Subscription

Parameters:

  • id (String)

    ID of the Push subscription to pull data from

  • size (Integer) (defaults to: 52_428_800)

    Max size (bytes) of the data that should be returned

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

    Point to a specific point in your Push buffer using a cursor

  • callback (Method) (defaults to: nil)

    Pass a callback to process each interaction returned from a successful pull request



203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/push.rb', line 203

def pull(id, size = 52_428_800, cursor = '', callback = nil)
  params = {
    :id => id
  }
  requires params
  params.merge!(
    :size => size,
    :cursor => cursor
  )
  params.merge!({:on_interaction => callback}) unless callback.nil?
  DataSift.request(:GET, 'pull', @config, params, {}, 30, 30, true)
end

#resume(id) ⇒ Object

Resume a Push subscription that was previously paused

Parameters:

  • id (String)

    ID of the Push subscription to resume



52
53
54
55
56
# File 'lib/push.rb', line 52

def resume(id)
  params = { :id => id }
  requires params
  DataSift.request(:PUT, 'push/resume', @config, params)
end

#stop(id) ⇒ Object

Stop a Push subscription; you will not be able to resume this

Parameters:

  • id (String)

    ID of the Push subscription to stop



61
62
63
64
65
# File 'lib/push.rb', line 61

def stop(id)
  params = { :id => id }
  requires params
  DataSift.request(:PUT, 'push/stop', @config, params)
end

#update(params) ⇒ Object

Update the name or output parameters for an existing subscription

Parameters:

  • params (Hash)

    Hash of Push subscription parameters



36
37
38
# File 'lib/push.rb', line 36

def update(params)
  DataSift.request(:POST, 'push/update', @config, params)
end

#valid?(params, bool_response = true) ⇒ Boolean

Check that a Push subscription definition is valid

Parameters:

  • params (Hash)

    Hash of Push subscription parameters

  • bool_response (Boolean) (defaults to: true)

    True if you want a boolean response. False if you want the full response object

Returns:

  • (Boolean)


15
16
17
18
19
# File 'lib/push.rb', line 15

def valid?(params, bool_response = true)
  requires params
  res = DataSift.request(:POST, 'push/validate', @config, params)
  bool_response ? res[:http][:status] == 200 : res
end