datasift 3.0.0.beta2 → 3.0.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b56e8834e9e227fc90f26c08fac16521d50fc2ab
4
- data.tar.gz: ab50e42f90b9aeaca168af3c7174160895cb558d
3
+ metadata.gz: f5a8e4b6cddffbd3b5608c4fe831bdf87213c772
4
+ data.tar.gz: e05742fa5831660e60c8395b812025d40bbdf0dd
5
5
  SHA512:
6
- metadata.gz: dbd1f4890b2b0693afa5255e75ec6e7a8f40f5b923d1c6c034f5a3e7540965c432c25e50e29a138f45d964cf5967a90a1ac50f5f28223d14cc429313ca53e9cc
7
- data.tar.gz: 3ee310b5822002750a6f517e2ef3ae218628753e4f4e55167f4cbc591542be962724db03fd06954ff56a5e51f3b6243ee7e1104e00014b3b9a9feecf201eff10
6
+ metadata.gz: 0a03568fe8b5bc5a650b8694f3763154ffd0c10fd13924221dc29cadfcc3befdd5a68b4ae325817c39fa84aea1b84946111230f3f73363d4682ae45f4e1445f9
7
+ data.tar.gz: f626e022353a188ba41d76d68680bacb60c92bd716921362c5c51400efbbe876ac6313b93caf7e7d9b1463bc53f4a4a339b11167ee781af34ca3cb7840b7c5a1
data/.gitignore CHANGED
@@ -1,7 +1,7 @@
1
1
  .DS_Store
2
2
  sftp-config.json
3
- Gemfile.lock
4
3
  *.iml
5
4
  .idea/
6
5
  rdoc/
7
- pkg/*
6
+ .bundle/
7
+ Gemfile.lock
@@ -1,16 +1,6 @@
1
1
  CHANGELOG
2
2
  ================================
3
3
 
4
- v.3.0.0.beta2 (2013-12-02)
5
- -------------------------
6
-
7
- Minor fixes to the 3.0.0 beta release
8
-
9
- * Requires websocket_td v.0.0.4+
10
- * Tests now run with Rake
11
- * Fixes a broken reference to the VERSION file
12
- * Renamed 'tests' directory to 'test'
13
-
14
4
  v.3.0.0.beta (2013-11-07)
15
5
  -------------------------
16
6
 
@@ -0,0 +1,262 @@
1
+ MIGRATING TO V.3.0.0
2
+ ================================
3
+
4
+ Breaking Changes
5
+ ----------------
6
+ Earlier versions of the DataSift library are incompatible with 3.x.x. 3.0.0 is a complete re-design. In order to continue delivering better features and performance some architectural changes have been made which make backwards compatibility very difficult and in some cases impractical.
7
+
8
+ Features
9
+ --------
10
+ * Live streaming now uses multi-threaded WebSockets, so you can subscribe and unsubscribe from stream hashes.
11
+ * This update ensures that the Ruby client library now supports all API features that were missing from prior versions of the client.
12
+ * This includes adding support for Historics Previews, and the [Pull Connector](http://dev.datasift.com/blog/pullingdata).
13
+ * Previous versions made API requests through a ```DataSift::User``` object. From v.3.0.0, we have moved to a more semantically correct ```DataSift::Client``` object.
14
+
15
+ Code
16
+ ====
17
+
18
+ ## Authentication
19
+ From v.3.0.0 of the Ruby client, we have dropped the concept of the ```DataSift::User``` object, and now use a ```DataSift::Client``` object for all API calls.
20
+
21
+ ### Authentication: < 3.0.0
22
+
23
+ ```ruby
24
+ config = YAML::load(File.open(File.join(File.dirname(__FILE__), '..', 'config.yml')))
25
+ user = DataSift::User.new(config['username'], config['api_key'])
26
+ ```
27
+
28
+ ### Authentication: 3.0.0+
29
+ From v.3.0.0+ you begin by providing a configuration object to the DataSift client. From here the client instance gives you access to the rest of the DataSift API. This is organized in a similar way to the DataSift [REST API documentation](http://dev.datasift.com/docs/rest-api) except where it didn't make sense to do so.
30
+
31
+ ```ruby
32
+ @config = {:username => 'DATASIFT_USERNAME', :api_key => 'DATASIFT_API_KEY', :enable_ssl => true}
33
+ @datasift = DataSift::Client.new(@config)
34
+ ```
35
+
36
+
37
+ ## Core
38
+ * @datasift.valid? csdl
39
+ * @datasift.compile csdl
40
+ * @datasift.usage [period]
41
+ * @datasift.dpu hash
42
+ * @datasift.balance
43
+
44
+ Below are examples of how to compile, then check the DPU cost of a CSDL statement, then check your API usage. These examples both assume you have correctly authenticated with the API.
45
+
46
+ ### Core: < 3.0.0
47
+ ```ruby
48
+ csdl = 'interaction.content contains "datasift"'
49
+ definition = user.createDefinition(csdl)
50
+ dpu = definition.getDPUBreakdown()
51
+ usage = user.getUsage()
52
+ ```
53
+
54
+ ### Core: 3.0.0+
55
+ ```ruby
56
+ csdl = interaction.content contains "datasift"'
57
+ stream = @datasift.compile csdl
58
+ dpu = @datasift.dpu stream[:data][:hash]
59
+ usage = @datasift.usage
60
+ ```
61
+
62
+
63
+ ## Live Streaming
64
+ The Live Streaming API is now accessed via WebSockets using the [websocket_td](https://github.com/zcourts/websocket-td) gem, rather than streaming over HTTP. This allows us to use the ```stream.subscribe(hash, on_message)``` and ```stream.unsubscribe hash``` methods to asynchronously subscribe and unsubscribe from streams, while still streaming data.
65
+ Please note, the examples below include only the mandatory callback methods, and do not include any additional error handling. The examples included in the client library itself do include some very basic error handling.
66
+
67
+ ### Core: < 3.0.0
68
+ ```ruby
69
+ consumer.consume(true) do |interaction|
70
+ if interaction
71
+ puts interaction.to_s
72
+ end
73
+ end
74
+ ```
75
+
76
+
77
+ ### Core: 3.0.0+
78
+ ```ruby
79
+ def stream(hash)
80
+ on_delete = lambda { |stream, m| puts m }
81
+ on_error = lambda { |stream, e| puts "An error has occurred: #{message}" }
82
+ on_message = lambda { |message, stream, hash| puts message }
83
+
84
+ on_datasift_message = lambda do |stream, message, hash|
85
+ puts "DataSift Message #{hash} ==> #{message}"
86
+ end
87
+
88
+ conn = DataSift::new_stream(@config, on_delete, on_error, on_open, on_close)
89
+ conn.on_datasift_message = on_datasift_message
90
+ conn.stream.read_thread.join
91
+ end
92
+ ```
93
+
94
+ #### on_delete event
95
+ on_delete is called when your stream receives a [delete notification](http://dev.datasift.com/docs/resources/twitter-deletes) from Twitter, notifying you that a Tweet you may have received has been deleted.
96
+
97
+ #### on_error event
98
+ on_error is called in cases where where an exception occurs during streaming.
99
+
100
+ #### on_message event
101
+ on_message is called when we receive [user status messages](http://dev.datasift.com/docs/resources/twitter-user-status-messages) from Twitter.
102
+
103
+
104
+ ## Push
105
+ * @datasift.push.valid? @params
106
+ * @datasift.create @params
107
+ * @datasift.push.pause subscription_id
108
+ * @datasift.push.resume subscription_id
109
+ * @datasift.push.update @params.merge({:id => subscription_id, :name => 'Updated name'})
110
+ * @datasift.push.stop subscription_id
111
+ * @datasift.push.delete subscription_id
112
+ * @datasift.push.logs
113
+ * @datasift.push.get_by_subscription subscription_id
114
+ * @datasift.push.get
115
+ * @datasift.pull
116
+
117
+ Below are some simple examples, showing you how to create, pause, resume, update, get, stop then delete a Push Subscription:
118
+
119
+ ### Push: < 3.0.0
120
+ ```ruby
121
+ definition = env.user.createDefinition(csdl)
122
+
123
+ pushdef = env.user.createPushDefinition()
124
+ pushdef.output_type = output_type
125
+
126
+ # Add your output parameters to your Push Definition
127
+ while env.args.size() > 0
128
+ k, v = env.args.shift.split('=', 2)
129
+ pushdef.output_params[k] = v
130
+ end
131
+
132
+ sub = pushdef.subscribeDefinition(definition, name)
133
+
134
+ sub.pause()
135
+ sub.resume()
136
+ sub.save()
137
+ sub.stop()
138
+ sub.delete()
139
+ ```
140
+
141
+
142
+ ### Push: 3.0.0+
143
+ ```ruby
144
+ subscription = create_push(hash)
145
+ subscription_id = subscription[:data][:id]
146
+
147
+ @datasift.push.pause subscription_id
148
+ @datasift.push.resume subscription_id
149
+ @datasift.push.update @params.merge({:id => subscription_id, :name => 'New name'})
150
+ @datasift.push.get_by_subscription subscription_id
151
+ @datasift.push.stop subscription_id
152
+ @datasift.push.delete subscription_id
153
+ ```
154
+
155
+
156
+ ## Historics
157
+ * @datasift.historics.prepare(hash, start, end, 'My ruby historics')
158
+ * @datasift.historics.start id
159
+ * @datasift.historics.stop id
160
+ * @datasift.historics.status(start, end_time)
161
+ * @datasift.historics.update(id, 'The new name of my historics')
162
+ * @datasift.historics.delete id
163
+ * @datasift.historics.get_by_id id
164
+ * @datasift.historics.get
165
+
166
+ Below are some simple examples demonstrating how to check the status of the Historics archive for a given timeframe, prepare an Historic, then start, get, stop and delete the Historic.
167
+
168
+ ### Historics: < 3.0.0
169
+ ```ruby
170
+ start_time = Time.now.to_i - 7200
171
+ end_time = start + 3600
172
+
173
+ # /historics/status not implemented in < 3.0.0
174
+ definition = env.user.createDefinition(csdl)
175
+ historic = definition.createHistoric(start_time, end_time, sources, sample, name)
176
+
177
+ historic.prepare()
178
+ historic.start()
179
+ user.getHistoric(historic.id)
180
+ historic.stop()
181
+ historic.delete()
182
+ ```
183
+
184
+ ### Historics: 3.0.0+
185
+ ```ruby
186
+ start_time = Time.now.to_i - 7200
187
+ end_time = start + 3600
188
+
189
+ @datasift.historics.status(start_time, end_time)
190
+
191
+ historics = @datasift.historics.prepare(hash, start_time, end_time, 'My Historic')
192
+ id = historics[:data][:id]
193
+
194
+ create_push(id, true)
195
+
196
+ @datasift.historics.start id
197
+ @datasift.historics.get_by_id id
198
+ @datasift.historics.stop id
199
+ @datasift.historics.delete id
200
+ ```
201
+
202
+ ## Historics Preview
203
+ * @datasift.historics_preview.create(hash, parameters, start, end)
204
+ * @datasift.historics_preview.get id
205
+
206
+ Historics preview was not available before v.3.0.0. The example below demonstrates how to create, then get the results of an Historics preview:
207
+
208
+ ### Hisotrics Preview: 3.0.0+
209
+ ```ruby
210
+ parameters = 'interaction.author.link,targetVol,hour;interaction.type,freqDist,10'
211
+ start = Time.now.to_i - (3600 * 48) # 48hrs ago
212
+ source = @datasift.historics_preview.create(hash, parameters, start)
213
+ @datasift.historics_preview.get source[:data][:id]
214
+ ```
215
+
216
+
217
+ ## Managed Sources
218
+ * @datasift.managed_source.create(source_type, name, parameters, resources, auth)
219
+ * @datasift.managed_source.update(id, source_type, name, parameters, resources, auth)
220
+ * @datasift.managed_source.delete id
221
+ * @datasift.managed_source.log id
222
+ * @datasift.managed_source.get id
223
+ * @datasift.managed_source.stop id
224
+ * @datasift.managed_source.start id
225
+
226
+ Below is a Managed Sources example, using each of the Managed Sources API endpoints:
227
+
228
+ ### Managed Sources < 3.0.0
229
+ ```ruby
230
+ parameters = {:likes => true, :comments => true}
231
+ resources = [{:parameters => {:type => 'tag', :value => 'coffee'}}]
232
+ auth = [{:parameters => {:value => '10942112.1fb234f.8713bcf4d5b44ece801022f6fa4b9e1b'}}]
233
+
234
+ user = DataSift::User.new(config['username'], config['api_key'], false)
235
+ source = user.createManagedSource(:source_type => 'instagram', :name => '#Coffee Pics', :parameters => parameters, :resources => resources, :auth => auth)
236
+
237
+ source.start
238
+ user.getManagedSource(source.managed_source_id)
239
+ user.getManagedSourcesLog(source.managed_source_id)
240
+ source.stop
241
+ source.delete
242
+ ```
243
+
244
+ ### Managed Sources 3.0.0+
245
+ ```ruby
246
+ parameters = {:likes => true, :comments => true}
247
+ resources = [{:parameters => {:type => 'tag', :value => 'coffee'}}]
248
+ auth = [{:parameters => {:value => '10942112.1fb234f.8713bcf4d5b44ece801022f6fa4b9e1b'}}]
249
+
250
+ source = @datasift.managed_source.create('instagram', '#Coffee Pics', parameters, resources, auth)
251
+ id = source[:data][:id]
252
+
253
+ @datasift.managed_source.start id
254
+ source = @datasift.managed_source.get id
255
+ # Note that in the line below, we pass the auth object returned from a /source/get call back into the /source/update statement. Passing the original auth object will fail
256
+ @datasift.managed_source.update(id, 'instagram', 'Updated source name', parameters, resources, source[:data][:auth])
257
+ @datasift.managed_source.log id
258
+ @datasift.managed_source.stop id
259
+ @datasift.managed_source.delete id
260
+ ```
261
+
262
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.0.beta2
1
+ 3.0.0.beta4
@@ -12,14 +12,15 @@ Gem::Specification.new do |s|
12
12
  s.rubygems_version = %q{1.3.6}
13
13
  s.required_rubygems_version = Gem::Requirement.new(">= 1.3.6") if s.respond_to? :required_rubygems_version=
14
14
 
15
- s.add_runtime_dependency('rest-client', '~> 1.6.3')
16
- s.add_development_dependency('multi_json', '~> 1.8.0')
15
+ s.add_runtime_dependency('rest-client', '~> 1.6.7')
16
+ s.add_runtime_dependency('multi_json', '~> 1.8.0')
17
17
  s.add_runtime_dependency('websocket-td', '~> 0.0.4')
18
18
  s.add_development_dependency('rdoc', '> 0')
19
+ s.add_development_dependency('webmock', '~> 1.17.1')
19
20
  s.add_development_dependency('shoulda', '~> 2.11.3')
20
21
  s.add_development_dependency('test-unit', '>= 2.5.5')
21
22
 
22
23
  s.files = `git ls-files`.split("\n")
23
24
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
25
  s.require_paths = ["lib"]
25
- end
26
+ end
@@ -1,10 +1,14 @@
1
1
  class DataSiftExample
2
- require File.dirname(__FILE__) + '/../lib/datasift'
2
+ require '../lib/datasift'
3
3
 
4
4
  def initialize
5
- @username = 'DATASIFT_USERNAME'
6
- @api_key = 'DATASIFT_API_KEY'
7
- @config ={:username => @username, :api_key => @api_key, :enable_ssl => false}
5
+ #only SSLv3 and TLSv1 currently supported, TLSv1 preferred
6
+ # this is fixed in REST client and is scheduled for the 1.7.0 release
7
+ # see https://github.com/rest-client/rest-client/pull/123
8
+ OpenSSL::SSL::SSLContext::DEFAULT_PARAMS[:ssl_version] = 'TLSv1'
9
+ @username = 'zcourts'
10
+ @api_key ='9dc2e16075de005b1a23444fbc6dd269'
11
+ @config ={:username => @username, :api_key => @api_key, :enable_ssl => true}
8
12
  @params = {
9
13
  :output_type => 's3',
10
14
  'output_params.bucket' => 'apitests',
@@ -41,4 +45,4 @@ class DataSiftExample
41
45
  puts 'Create push => ' + subscription.to_s
42
46
  subscription
43
47
  end
44
- end
48
+ end
@@ -0,0 +1,155 @@
1
+ #!/bin/bash
2
+ command -v jq >/dev/null 2>&1 || { echo >&2 "jq command must be available. See http://stedolan.github.io/jq/. Aborting."; exit 1; }
3
+
4
+ set -e
5
+
6
+ DEFAULT_API='api.datasift.com'
7
+
8
+ CC=${1:$CC}
9
+ DU=${2:-$DU}
10
+ DK=${3:-$DK}
11
+ API=${4:-$DEFAULT_API}
12
+
13
+ function ds(){
14
+ ${CC} -a ${DU} ${DK} --u ${API} "$@" #| jq .
15
+ }
16
+
17
+ # core API - validate our hash, compile it, check our usage, dpu and balance
18
+ echo 'Validating CSDL'
19
+ csdl='interaction.content contains "music"'
20
+ valid=$(ds -e core -c validate -p csdl "$csdl" | jq .status)
21
+
22
+ if [ ${valid} != 200 ]; then
23
+ echo "Validating CSDL failed"
24
+ echo ${valid}
25
+ exit -1
26
+ fi
27
+
28
+ echo 'Compiling'
29
+ hash=$(ds -e core -c compile -p csdl "$csdl" | jq -r .body.hash)
30
+ echo "Compiled and got $hash"
31
+
32
+ echo 'Usage :'
33
+ ds -e core -c usage | jq .
34
+
35
+ echo 'DPU :'
36
+ ds -e core -c dpu -p hash $hash | jq .
37
+
38
+ echo 'Balance :'
39
+ ds -e core -c usage | jq .
40
+
41
+ echo 'Preparing Historic query'
42
+ end=`expr $(date +%s) - 7200`
43
+ start=`expr $end - 3600`
44
+
45
+ historic=$(ds -e historics -c prepare -p start ${start} -p end ${end} -p name "Historics CLI @ $start" -p hash ${hash})
46
+ echo ${historic} | jq .
47
+ historic_id=$(echo ${historic} | jq -r .body.id)
48
+ echo "Historic created with ID $historic_id"
49
+
50
+ echo 'Validating Push subscription'
51
+ push_v=$(ds -e push -c validate -p playback_id ${historic_id} -p name "Playback CLI @ $start" -p output_type http \
52
+ -p output_params.method post -p output_params.url 'http://ec2-50-19-63-138.compute-1.amazonaws.com:80' \
53
+ -p output_params.delivery_frequency 0 -p output_params.max_size 102400 -p output_params.auth.type none \
54
+ -p output_params.verify_ssl false -p output_params.use_gzip true)
55
+ push_status=$(echo ${push_v} | jq .status)
56
+ echo ${push_v} | jq .
57
+
58
+ if [ ${push_status} != 200 ]; then
59
+ echo "Validating Push subscription failed"
60
+ exit -1
61
+ fi
62
+
63
+ echo 'Creating Push from Historic'
64
+ push=$(ds -e push -c create -p playback_id ${historic_id} -p name "Playback CLI @ $start" -p output_type http \
65
+ -p output_params.method post -p output_params.url 'http://ec2-50-19-63-138.compute-1.amazonaws.com:80' \
66
+ -p output_params.delivery_frequency 0 -p output_params.max_size 102400 -p output_params.auth.type none \
67
+ -p output_params.verify_ssl false -p output_params.use_gzip true)
68
+
69
+ echo "Created push subscription for historic"
70
+ echo ${push} | jq .
71
+ push_id=$(echo ${push} | jq -r .body.id)
72
+
73
+ echo 'Starting Historic query'
74
+ ds -e historics -c start -p id ${historic_id} | jq .
75
+
76
+ echo 'Getting Historic status'
77
+ ds -e historics -c status -p start ${start} -p end ${end} | jq .
78
+
79
+ echo 'Getting Historics'
80
+ ds -e historics -c get -p id ${historic_id} | jq .
81
+
82
+ echo 'Updating historic'
83
+ ds -e historics -c update -p id ${historic_id} -p name "Some name @ $start - CLI" | jq .
84
+
85
+ echo 'Getting push'
86
+ ds -e push -c get -p id ${push_id} | jq .
87
+
88
+ echo 'Getting push logs'
89
+ ds -e push -c log -p id ${push_id} | jq .
90
+
91
+ echo 'Pausing push'
92
+ ds -e push -c pause -p id ${push_id} | jq .
93
+
94
+ echo 'Resuming push'
95
+ ds -e push -c resume -p id ${push_id} | jq .
96
+
97
+ echo 'Stopping Historic'
98
+ ds -e historics -c stop -p id ${historic_id} | jq .
99
+
100
+ echo 'Deleting Historic'
101
+ ds -e historics -c delete -p id ${historic_id} | jq .
102
+
103
+ echo 'Stopping push'
104
+ ds -e push -c stop -p id ${push_id} | jq .
105
+
106
+ echo 'Deleting push'
107
+ ds -e push -c delete -p id ${push_id} | jq .
108
+ #todo update push, pull
109
+
110
+ echo "Attempting to create a Historics preview"
111
+ preview=$(ds -e preview -c create -p start ${start} -p end ${end} -p hash ${hash} -p sources twitter \
112
+ -p parameters 'interaction.author.link,targetVol,hour;interaction.type,freqDist,10')
113
+
114
+ echo ${preview} | jq .
115
+ preview_id=$(echo ${preview} | jq -r .body.id)
116
+
117
+
118
+ echo "Getting the preview we created"
119
+ ds -e preview -c get -p id ${preview_id} | jq .
120
+
121
+ echo "Creating a managed source"
122
+ source=$(ds -e managed_sources -c create -p source_type instagram -p name api \
123
+ -p auth "[{\"parameters\":{\"value\":\"$start$end\"}}]" \
124
+ -p resources '[{"parameters":{"value":"cats","type":"tag"}}]' \
125
+ -p parameters '{"comments":true,"likes":false}')
126
+ echo ${source}
127
+ source_id=$(echo ${source}| jq -r .body.id)
128
+ echo ${source_id}
129
+
130
+ echo "Starting managed source"
131
+ ds -e managed_sources -c start -p source_id ${source_id} | jq .
132
+
133
+ echo "Getting managed sources"
134
+ ds -e managed_sources -c get | jq .
135
+
136
+ echo "Getting Instagram sources"
137
+ ds -e managed_sources -c get -p source_type instagram | jq .
138
+
139
+ echo "Getting Facebook page sources"
140
+ ds -e managed_sources -c get -p source_type facebook_page | jq .
141
+
142
+ echo "Getting page 2 of instagram sources"
143
+ ds -e managed_sources -c get -p source_type instagram -p page 2 | jq .
144
+
145
+ echo "Getting source for $source_id"
146
+ ds -e managed_sources -c get -p source_id ${source_id} | jq .
147
+
148
+ echo "Getting logs for source $source_id"
149
+ ds -e managed_sources -c log -p source_id ${source_id} -p page 2 -p per_page 1 | jq .
150
+
151
+ echo "Stopping managed source"
152
+ ds -e managed_sources -c stop -p source_id ${source_id} | jq .
153
+
154
+ echo "Deleting managed source $source_id"
155
+ ds -e managed_sources -c delete -p source_id ${source_id} | jq .