datasift 2.1.1 → 3.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +100 -0
- data/Gemfile.lock +32 -0
- data/README.md +38 -79
- data/VERSION +1 -1
- data/datasift.gemspec +21 -24
- data/examples/auth.rb +44 -0
- data/examples/core_api_eg.rb +46 -0
- data/examples/historics_eg.rb +50 -0
- data/examples/historics_preview_eg.rb +30 -0
- data/examples/live_stream_eg.rb +89 -0
- data/examples/managed_source_eg.rb +56 -0
- data/examples/pull.rb +44 -0
- data/examples/push_eg.rb +56 -0
- data/lib/api/api_resource.rb +23 -0
- data/lib/datasift.rb +287 -14
- data/lib/errors.rb +59 -0
- data/lib/historics.rb +76 -0
- data/lib/historics_preview.rb +20 -0
- data/lib/live_stream.rb +53 -0
- data/lib/managed_source.rb +57 -0
- data/lib/push.rb +156 -0
- data/tests/core_api_test.rb +42 -0
- metadata +51 -73
- data/Rakefile +0 -34
- data/config.yml +0 -2
- data/examples/consume-stream.rb +0 -63
- data/examples/deletes.rb +0 -52
- data/examples/dpu.rb +0 -115
- data/examples/football-buffered.rb +0 -51
- data/examples/football.rb +0 -53
- data/examples/historics.sh +0 -2
- data/examples/historics/create-from-csdl.rb +0 -71
- data/examples/historics/create-from-hash.rb +0 -65
- data/examples/historics/delete.rb +0 -30
- data/examples/historics/env.rb +0 -37
- data/examples/historics/list.rb +0 -30
- data/examples/historics/start.rb +0 -30
- data/examples/historics/stop.rb +0 -30
- data/examples/historics/view.rb +0 -28
- data/examples/push.sh +0 -2
- data/examples/push/delete.rb +0 -33
- data/examples/push/env.rb +0 -53
- data/examples/push/list.rb +0 -30
- data/examples/push/pause.rb +0 -33
- data/examples/push/push-from-hash.rb +0 -72
- data/examples/push/push-historic-from-csdl.rb +0 -98
- data/examples/push/push-stream-from-csdl.rb +0 -70
- data/examples/push/resume.rb +0 -33
- data/examples/push/stop.rb +0 -33
- data/examples/push/view-log.rb +0 -45
- data/examples/push/view.rb +0 -31
- data/examples/twitter-track.rb +0 -61
- data/lib/DataSift/apiclient.rb +0 -73
- data/lib/DataSift/definition.rb +0 -202
- data/lib/DataSift/exceptions.rb +0 -33
- data/lib/DataSift/historic.rb +0 -316
- data/lib/DataSift/managed_source.rb +0 -263
- data/lib/DataSift/mockapiclient.rb +0 -44
- data/lib/DataSift/push_definition.rb +0 -115
- data/lib/DataSift/push_subscription.rb +0 -330
- data/lib/DataSift/stream_consumer.rb +0 -166
- data/lib/DataSift/stream_consumer_http.rb +0 -188
- data/lib/DataSift/user.rb +0 -311
- data/test/helper.rb +0 -95
- data/test/test_definition.rb +0 -273
- data/test/test_historics.rb +0 -233
- data/test/test_pushdefinition.rb +0 -92
- data/test/test_pushsubscription.rb +0 -17
- data/test/test_user.rb +0 -130
- data/test/testdata.yml +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2edfce8b73a255a0b9cce1bcf3d8834bf1e0b028
|
4
|
+
data.tar.gz: 4e34361963da7c4c5e06ebd2b7bf6d13c80b04fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9b2ef5c9c081a46ea7dc343dc33faad8e0cba822ef84f7abb7ba755221dc6e334f02ee08e915b6bf059eb678e73004184b17de39c939814285bb33b96febc41
|
7
|
+
data.tar.gz: 7cfe773014a1b0c719501f8b7b0160606dde21525bb2cb03d41d551837e4020f7f9aa64bca1d660ebbdbf0119d14c23462dc93b09b0913da3d0d2ce046167263
|
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
CHANGELOG
|
2
|
+
================================
|
3
|
+
|
4
|
+
v.3.0.0.beta (2013-11-07)
|
5
|
+
-------------------------
|
6
|
+
|
7
|
+
Total rewrite of the DataSift client library for Ruby.
|
8
|
+
|
9
|
+
This release does break backwards compatibility with previous versions. New features include:
|
10
|
+
* Support for DataSift Historics Preview
|
11
|
+
* Support for multi-streaming via WebSockets
|
12
|
+
|
13
|
+
v.2.1.0 (2013-09-13)
|
14
|
+
--------------------
|
15
|
+
|
16
|
+
Final fixes for v.2.1.0
|
17
|
+
|
18
|
+
* Adds /source/log call
|
19
|
+
* Updated /source/create call to comply with latest version of the API
|
20
|
+
* Removed JSON gem - now dependant on Yajl-Ruby for JSON parsing
|
21
|
+
* Added license info to gemspec
|
22
|
+
* Fixed edge case when passing refresh token to authentication with G+ API
|
23
|
+
* Fixed /source/get call
|
24
|
+
|
25
|
+
v.2.1.0.beta (2013-08-05)
|
26
|
+
-------------------------
|
27
|
+
|
28
|
+
Adding Managed Sources support.
|
29
|
+
Thanks to [giovannelli](https://github.com/giovannelli) for the contribution
|
30
|
+
|
31
|
+
v.2.0.4 (2013-03-18)
|
32
|
+
--------------------
|
33
|
+
|
34
|
+
Bug fix to handle HTTP 202 response codes
|
35
|
+
|
36
|
+
v.2.0.3 (2013-03-04)
|
37
|
+
--------------------
|
38
|
+
|
39
|
+
Stability improvement and bug fix
|
40
|
+
|
41
|
+
* Removed references to deprecated Historic output field 'volume_info'.
|
42
|
+
* Added 65s timeout on live streaming to handle 'silent' server disconnects.
|
43
|
+
* Minor changes to ensure Ruby 2.0 compatibility.
|
44
|
+
|
45
|
+
v.2.0.2 (2012-12-03)
|
46
|
+
--------------------
|
47
|
+
|
48
|
+
Added missing Historic sample size into historic/prepare requests
|
49
|
+
|
50
|
+
v.2.0.1 (2012-09-03)
|
51
|
+
--------------------
|
52
|
+
|
53
|
+
Fixed a bug that was preventing streaming connections from being established
|
54
|
+
|
55
|
+
v.2.0.0 (2012-08-31)
|
56
|
+
--------------------
|
57
|
+
|
58
|
+
Added support for Historics queries and Push delivery
|
59
|
+
|
60
|
+
v.1.5.0 (2012-05-24)
|
61
|
+
--------------------
|
62
|
+
|
63
|
+
Added getBalance to the User class [joncooper](https://github.com/joncooper)
|
64
|
+
|
65
|
+
v.1.4.1 (2012-05-15)
|
66
|
+
--------------------
|
67
|
+
|
68
|
+
Fixed a minor bug in the SSL support
|
69
|
+
|
70
|
+
v.1.4.0 (2012-05-15)
|
71
|
+
--------------------
|
72
|
+
|
73
|
+
Added SSL support
|
74
|
+
|
75
|
+
This is enabled by default and can be disabled by passing false as the third
|
76
|
+
parameter to the User constructor, or calling enableSSL(false) on the User
|
77
|
+
object.
|
78
|
+
|
79
|
+
v.1.3.1 (2012-04-20)
|
80
|
+
--------------------
|
81
|
+
|
82
|
+
Exposed compile failures when getting the stream hash
|
83
|
+
|
84
|
+
v.1.3.0 (2012-03-08)
|
85
|
+
--------------------
|
86
|
+
|
87
|
+
Improved error handling
|
88
|
+
|
89
|
+
* Added onError and onWarning events - see examples/consume-stream.rb for an example.
|
90
|
+
* Stopped the HTTP consumer from attempting to reconnect when it receives a 4xx response from the server.
|
91
|
+
|
92
|
+
v.1.2.0 (2012-02-28)
|
93
|
+
--------------------
|
94
|
+
|
95
|
+
Twitter Compliance
|
96
|
+
|
97
|
+
* The consumer now has an onDeleted method to which you can assign a block that will be called to handle DELETE requests from Twitter. See delete.rb in the examples folder for a sample implementation. (@see http://dev.datasift.com/docs/twitter-deletes)
|
98
|
+
|
99
|
+
NB: if you are storing tweets you must implement this method in your code
|
100
|
+
and take appropriate action to maintain compliance with the Twitter license.
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
datasift (3.0.0.beta)
|
5
|
+
rest-client (~> 1.6.3)
|
6
|
+
websocket-td (~> 0.0.3)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
json (1.8.0)
|
12
|
+
mime-types (1.25)
|
13
|
+
multi_json (1.8.0)
|
14
|
+
rdoc (4.0.1)
|
15
|
+
json (~> 1.4)
|
16
|
+
rest-client (1.6.7)
|
17
|
+
mime-types (>= 1.16)
|
18
|
+
shoulda (2.11.3)
|
19
|
+
test-unit (2.5.5)
|
20
|
+
websocket (1.1.1)
|
21
|
+
websocket-td (0.0.3)
|
22
|
+
websocket (~> 1.1.1)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
datasift!
|
29
|
+
multi_json (~> 1.8.0)
|
30
|
+
rdoc (> 0)
|
31
|
+
shoulda (~> 2.11.3)
|
32
|
+
test-unit (>= 2.5.5)
|
data/README.md
CHANGED
@@ -4,8 +4,6 @@ DataSift
|
|
4
4
|
The official Ruby library for accessing the DataSift API. See
|
5
5
|
http://datasift.com/ for full details and to sign up for an account.
|
6
6
|
|
7
|
-
The examples use the username and API key in config.yml unless otherwise noted.
|
8
|
-
|
9
7
|
Install Instructions
|
10
8
|
--------------------
|
11
9
|
|
@@ -16,34 +14,56 @@ Dependencies
|
|
16
14
|
|
17
15
|
If you're using the source you'll need to install the dependencies.
|
18
16
|
|
19
|
-
sudo gem install
|
17
|
+
sudo gem install rest-client multi_json websocket-td
|
20
18
|
|
21
19
|
The library will use SSL connections by default. While we recommend using SSL
|
22
|
-
you may disable it if required by passing false as the third
|
23
|
-
|
20
|
+
you may disable it if required by passing ':enable_ssl => false' as the third
|
21
|
+
parameter when creating your @config object.
|
24
22
|
|
25
23
|
Simple example
|
26
24
|
--------------
|
27
25
|
|
28
|
-
This example looks for anything that contains the word "
|
29
|
-
prints the content to the screen as they come in.
|
26
|
+
This example looks for anything that contains the word "football" in real-time,
|
27
|
+
and simply prints the content to the screen as they come in.
|
30
28
|
|
31
29
|
```ruby
|
32
|
-
require 'rubygems'
|
33
30
|
require 'datasift'
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
31
|
+
@config = {:username => 'DATASIFT_USERNAME', :api_key => 'DATASIFT_API_KEY', :enable_ssl => true}
|
32
|
+
@datasift = DataSift::Client.new(@config)
|
33
|
+
csdl = 'interaction.content contains "football"'
|
34
|
+
filter = @datasift.compile csdl
|
35
|
+
receivedCount = 0
|
36
|
+
|
37
|
+
on_delete = lambda { |stream, m| puts 'We must delete this to be compliant ==> ' + m }
|
38
|
+
on_error = lambda { |stream, e| puts "A serious error has occurred: #{e.message}" }
|
39
|
+
on_message = lambda do |message, stream, hash|
|
40
|
+
receivedCount += 1
|
41
|
+
puts "Received interaction: #{message}"
|
42
|
+
|
43
|
+
if receivedCount >= 5
|
44
|
+
puts "Unsubscribing from hash #{hash}"
|
45
|
+
stream.unsubscribe hash
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
on_connect = lambda do |stream|
|
50
|
+
stream.subscribe(filter[:data][:hash], on_message)
|
51
|
+
puts 'Subscribed to '+ filter[:data][:hash]
|
41
52
|
end
|
53
|
+
|
54
|
+
on_datasift_message = lambda do |stream, message, hash|
|
55
|
+
#not all messages have a hash
|
56
|
+
puts "is_success = #{message[:is_success]}, is_failure = #{message[:is_failure]}, is_warning = #{message[:is_warning]}, is_tick = #{message[:is_tick]}"
|
57
|
+
puts "DataSift Message #{hash} ==> #{message}"
|
58
|
+
end
|
59
|
+
|
60
|
+
conn = DataSift::new_stream(@config, on_delete, on_error, on_connect)
|
61
|
+
conn.on_datasift_message = on_datasift_message
|
62
|
+
conn.stream.read_thread.join
|
42
63
|
```
|
43
64
|
|
44
|
-
See the
|
45
|
-
|
46
|
-
http://dev.datasift.com/docs/targets/twitter/tweet-output-format
|
65
|
+
See the [Understanding the Output Data](http://dev.datasift.com/docs/getting-started/data) page on the DataSift Developer site for
|
66
|
+
full details of the data contained within each interaction.
|
47
67
|
|
48
68
|
License
|
49
69
|
-------
|
@@ -52,64 +72,3 @@ All code contained in this repository is Copyright 2011-2013 MediaSift Ltd.
|
|
52
72
|
|
53
73
|
This code is released under the BSD license. Please see the LICENSE file for
|
54
74
|
more details.
|
55
|
-
|
56
|
-
Changelog
|
57
|
-
---------
|
58
|
-
* v.2.1.1 (2014-05-16)
|
59
|
-
- Allow use of more recent versions of required gems
|
60
|
-
- Minor bug fixes
|
61
|
-
|
62
|
-
* v.2.1.0 Final fixes for v.2.1.0 (2013-09-13)
|
63
|
-
|
64
|
-
- Adds /source/log call
|
65
|
-
- Updated /source/create call to comply with latest version of the API
|
66
|
-
- Removed JSON gem - now dependant on Yajl-Ruby for JSON parsing
|
67
|
-
- Added license info to gemspec
|
68
|
-
- Fixed edge case when passing refresh token to authentication with G+ API
|
69
|
-
- Fixed /source/get call
|
70
|
-
|
71
|
-
* v.2.1.0.beta Adding Managed Sources support. Thanks to [giovannelli](https://github.com/giovannelli) for the contribution (2013-08-05)
|
72
|
-
|
73
|
-
* v.2.0.4 Bug fix to handle HTTP 202 response codes (2013-03-18)
|
74
|
-
|
75
|
-
* v.2.0.3 Stability improvement and bug fix (2013-03-04)
|
76
|
-
|
77
|
-
Removed references to deprecated Historic output field 'volume_info'.
|
78
|
-
Added 65s timeout on live streaming to handle 'silent' server disconnects.
|
79
|
-
Minor changes to ensure Ruby 2.0 compatibility.
|
80
|
-
|
81
|
-
* v.2.0.2 Added missing Historic sample size into historic/prepare requests (2012-12-03)
|
82
|
-
|
83
|
-
* v.2.0.1 Fixed a bug that was preventing streaming connections from being established (2012-09-03)
|
84
|
-
|
85
|
-
* v.2.0.0 Added support for Historics queries and Push delivery (2012-08-31)
|
86
|
-
|
87
|
-
* v.1.5.0 Added getBalance to the User class [joncooper](https://github.com/joncooper) (2012-05-24)
|
88
|
-
|
89
|
-
* v.1.4.1 Fixed a minor bug in the SSL support (2012-05-15)
|
90
|
-
|
91
|
-
* v.1.4.0 Added SSL support (2012-05-15)
|
92
|
-
|
93
|
-
- This is enabled by default and can be disabled by passing false as the third
|
94
|
-
parameter to the User constructor, or calling enableSSL(false) on the User
|
95
|
-
object.
|
96
|
-
|
97
|
-
* v.1.3.1 Exposed compile failures when getting the stream hash (2012-04-20)
|
98
|
-
|
99
|
-
* v.1.3.0 Improved error handling (2012-03-08)
|
100
|
-
|
101
|
-
- Added onError and onWarning events - see examples/consume-stream.rb for an
|
102
|
-
example.
|
103
|
-
|
104
|
-
- Stopped the HTTP consumer from attempting to reconnect when it receives a
|
105
|
-
4xx response from the server.
|
106
|
-
|
107
|
-
* v.1.2.0 Twitter Compliance (2012-02-28)
|
108
|
-
|
109
|
-
- The consumer now has an onDeleted method to which you can assign a block
|
110
|
-
that will be called to handle DELETE requests from Twitter. See delete.rb
|
111
|
-
in the examples folder for a sample implementation.
|
112
|
-
(@see http://dev.datasift.com/docs/twitter-deletes)
|
113
|
-
|
114
|
-
- NB: if you are storing tweets you must implement this method in your code
|
115
|
-
and take appropriate action to maintain compliance with the Twitter license.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.0.0.beta
|
data/datasift.gemspec
CHANGED
@@ -1,28 +1,25 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
|
4
1
|
Gem::Specification.new do |s|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
s.license = 'BSD'
|
2
|
+
s.name = 'datasift'
|
3
|
+
s.version = File.open('VERSION').first
|
4
|
+
s.authors = ['DataSift']
|
5
|
+
s.email = ['support@datasift.com']
|
6
|
+
s.description = %q{The official Ruby library for accessing the DataSift API. See http://datasift.com/ for full details and to sign up for an account.}
|
7
|
+
s.summary = %q{DataSift is a simple wrapper for the DataSift API.}
|
8
|
+
s.homepage = 'https://github.com/datasift/datasift-ruby'
|
9
|
+
s.license = 'BSD'
|
14
10
|
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
s.platform = Gem::Platform::RUBY
|
12
|
+
s.rubygems_version = %q{1.3.6}
|
13
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.3.6") if s.respond_to? :required_rubygems_version=
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
15
|
+
s.add_runtime_dependency('rest-client', '~> 1.6.3')
|
16
|
+
s.add_development_dependency('multi_json', '~> 1.8.0')
|
17
|
+
s.add_runtime_dependency('websocket-td', '~> 0.0.3')
|
18
|
+
s.add_development_dependency('rdoc', '> 0')
|
19
|
+
s.add_development_dependency('shoulda', '~> 2.11.3')
|
20
|
+
s.add_development_dependency('test-unit', '>= 2.5.5')
|
24
21
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
22
|
+
s.files = `git ls-files`.split("\n")
|
23
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
end
|
data/examples/auth.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
class DataSiftExample
|
2
|
+
require '../lib/datasift'
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@username = 'DATASIFT_USERNAME'
|
6
|
+
@api_key = 'DATASIFT_API_KEY'
|
7
|
+
@config ={:username => @username, :api_key => @api_key, :enable_ssl => false}
|
8
|
+
@params = {
|
9
|
+
:output_type => 's3',
|
10
|
+
'output_params.bucket' => 'apitests',
|
11
|
+
'output_params.directory' => 'ruby',
|
12
|
+
'output_params.acl' => 'private',
|
13
|
+
'output_params.auth.access_key' => 'AKIAIINK5C4FH75RSWNA',
|
14
|
+
'output_params.auth.secret_key' => 'F9mLnLoFFGuCNgbMUhdhHmm5YCcNAt/OG32SUhPy',
|
15
|
+
'output_params.delivery_frequency' => 0,
|
16
|
+
'output_params.max_size' => 10485760,
|
17
|
+
'output_params.file_prefix' => 'DataSift',
|
18
|
+
}
|
19
|
+
@datasift = DataSift::Client.new(@config)
|
20
|
+
end
|
21
|
+
|
22
|
+
attr_reader :datasift
|
23
|
+
|
24
|
+
def create_push(hash, is_historics_id = false)
|
25
|
+
create_params = @params.merge ({
|
26
|
+
#hash or playback_id can be used but not both
|
27
|
+
:name => 'My awesome push subscription',
|
28
|
+
:initial_status => 'active', # or 'paused' or 'waiting_for_start'
|
29
|
+
})
|
30
|
+
if is_historics_id
|
31
|
+
create_params.merge!({:playback_id => hash})
|
32
|
+
else
|
33
|
+
create_params.merge!({:hash => hash,
|
34
|
+
#start and end are not valid for historics
|
35
|
+
:start => Time.now.to_i,
|
36
|
+
:end => Time.now.to_i + 320
|
37
|
+
})
|
38
|
+
end
|
39
|
+
puts 'Creating subscription'
|
40
|
+
subscription = @datasift.push.create create_params
|
41
|
+
puts 'Create push => ' + subscription.to_s
|
42
|
+
subscription
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require './auth'
|
2
|
+
class CoreApiEg < DataSiftExample
|
3
|
+
def initialize
|
4
|
+
super
|
5
|
+
@datasift = DataSift::Client.new(@config)
|
6
|
+
run
|
7
|
+
end
|
8
|
+
|
9
|
+
def run
|
10
|
+
begin
|
11
|
+
csdl = 'interaction.content contains "test"'
|
12
|
+
# see docs at http://dev.datasift.com/docs/rest-api/validate
|
13
|
+
puts @datasift.valid? csdl
|
14
|
+
|
15
|
+
# http://dev.datasift.com/docs/rest-api/compile
|
16
|
+
stream = @datasift.compile csdl
|
17
|
+
puts stream[:data][:hash]
|
18
|
+
|
19
|
+
# http://dev.datasift.com/docs/rest-api/dpu
|
20
|
+
dpu = @datasift.dpu stream[:data][:hash]
|
21
|
+
puts dpu[:data][:dpu]
|
22
|
+
|
23
|
+
# http://dev.datasift.com/docs/rest-api/balance
|
24
|
+
balance = @datasift.balance
|
25
|
+
puts balance[:data]
|
26
|
+
|
27
|
+
#http://dev.datasift.com/docs/rest-api/usage
|
28
|
+
usage = @datasift.usage
|
29
|
+
puts usage[:data]
|
30
|
+
|
31
|
+
#rescue DataSiftError
|
32
|
+
rescue DataSiftError => dse
|
33
|
+
puts dse.message
|
34
|
+
# Then match specific one to take action - All errors thrown by the client extend DataSiftError
|
35
|
+
case dse
|
36
|
+
when ConnectionError
|
37
|
+
# some connection error
|
38
|
+
when AuthError
|
39
|
+
when BadRequestError
|
40
|
+
else
|
41
|
+
# do something else...
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
CoreApiEg.new
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require './auth'
|
2
|
+
class HistoricsApi < DataSiftExample
|
3
|
+
def initialize
|
4
|
+
super
|
5
|
+
run_historics
|
6
|
+
end
|
7
|
+
|
8
|
+
def run_historics
|
9
|
+
begin
|
10
|
+
stream = @datasift.compile 'interaction.content contains "datasift"'
|
11
|
+
hash = stream[:data][:hash]
|
12
|
+
start = Time.now.to_i - 7200
|
13
|
+
end_time = start + 3600
|
14
|
+
|
15
|
+
puts 'Check the data coverage for the last two hours'
|
16
|
+
puts @datasift.historics.status(start, end_time)
|
17
|
+
|
18
|
+
puts 'Preparing'
|
19
|
+
#prepare a historics to start from two hours ago and run for 1 hour using twitter as a data source and using only a 10% sample
|
20
|
+
historics = @datasift.historics.prepare(hash, start, end_time, 'My ruby historics')
|
21
|
+
puts historics
|
22
|
+
|
23
|
+
id = historics[:data][:id]
|
24
|
+
|
25
|
+
puts 'Creating push subscription for historics'
|
26
|
+
puts create_push(id, true)
|
27
|
+
|
28
|
+
puts "Starting historics #{id}"
|
29
|
+
puts @datasift.historics.start id
|
30
|
+
|
31
|
+
puts 'Updating historics'
|
32
|
+
puts @datasift.historics.update(id, 'The new name of my historics')
|
33
|
+
|
34
|
+
puts 'Get info for the historics'
|
35
|
+
puts @datasift.historics.get_by_id id
|
36
|
+
|
37
|
+
puts 'Getting info for all my historics'
|
38
|
+
puts @datasift.historics.get
|
39
|
+
|
40
|
+
puts 'Stopping historics'
|
41
|
+
puts @datasift.historics.stop id
|
42
|
+
|
43
|
+
puts 'Deleting historics'
|
44
|
+
puts @datasift.historics.delete id
|
45
|
+
rescue DataSiftError => dse
|
46
|
+
puts dse.message
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
HistoricsApi.new
|