datasift 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +1 -1
- data/README.md +6 -0
- data/VERSION +1 -1
- data/examples/consume-stream.rb +1 -1
- data/examples/deletes.rb +1 -1
- data/examples/dpu.rb +1 -1
- data/examples/football-buffered.rb +1 -1
- data/examples/football.rb +1 -1
- data/examples/twitter-track.rb +1 -1
- data/lib/DataSift/apiclient.rb +5 -6
- data/lib/DataSift/historic.rb +0 -6
- data/lib/DataSift/stream_consumer.rb +2 -1
- data/lib/DataSift/stream_consumer_http.rb +9 -2
- data/lib/DataSift/user.rb +1 -1
- data/test/helper.rb +6 -9
- data/test/test_definition.rb +1 -1
- data/test/test_historics.rb +1 -1
- data/test/test_pushdefinition.rb +1 -1
- data/test/test_pushsubscription.rb +1 -1
- data/test/test_user.rb +1 -1
- metadata +7 -20
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source
|
1
|
+
source "https://rubygems.org"
|
2
2
|
gemspec
|
data/README.md
CHANGED
@@ -56,6 +56,12 @@ more details.
|
|
56
56
|
Changelog
|
57
57
|
---------
|
58
58
|
|
59
|
+
* v.2.0.3 Stability improvement and bug fix (2013-03-04)
|
60
|
+
|
61
|
+
Removed references to deprecated Historic output field 'volume_info'.
|
62
|
+
Added 65s timeout on live streaming to handle 'silent' server disconnects.
|
63
|
+
Minor changes to ensure Ruby 2.0 compatibility.
|
64
|
+
|
59
65
|
* v.2.0.2 Added missing Historic sample size into historic/prepare requests (2012-12-03)
|
60
66
|
|
61
67
|
* v.2.0.1 Fixed a bug that was preventing streaming connections from being established (2012-09-03)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.
|
1
|
+
2.0.3
|
data/examples/consume-stream.rb
CHANGED
@@ -16,7 +16,7 @@ if ARGV.size == 0
|
|
16
16
|
end
|
17
17
|
|
18
18
|
# Include the DataSift library
|
19
|
-
require File.dirname(__FILE__) + '/../lib/datasift'
|
19
|
+
require './' + File.dirname(__FILE__) + '/../lib/datasift'
|
20
20
|
|
21
21
|
# Include the configuration - put your username and API key in this file
|
22
22
|
require 'yaml'
|
data/examples/deletes.rb
CHANGED
data/examples/dpu.rb
CHANGED
data/examples/football.rb
CHANGED
data/examples/twitter-track.rb
CHANGED
@@ -18,7 +18,7 @@ if ARGV.size == 0
|
|
18
18
|
end
|
19
19
|
|
20
20
|
# Include the DataSift library
|
21
|
-
require File.dirname(__FILE__) + '/../lib/datasift'
|
21
|
+
require './' + File.dirname(__FILE__) + '/../lib/datasift'
|
22
22
|
|
23
23
|
# Include the configuration - put your username and API key in this file
|
24
24
|
require 'yaml'
|
data/lib/DataSift/apiclient.rb
CHANGED
@@ -7,19 +7,18 @@ module DataSift
|
|
7
7
|
class ApiClient
|
8
8
|
#Make a call to a DataSift API endpoint.
|
9
9
|
#=== Parameters
|
10
|
+
#* +user+ - The DataSift User object.
|
10
11
|
#* +endpoint+ - The endpoint of the API call.
|
11
12
|
#* +params+ - The parameters to be passed along with the request.
|
12
|
-
#* +username+ - The username for the Auth header
|
13
|
-
#* +api_key+ - The API key for the Auth header
|
14
13
|
#=== Returns
|
15
14
|
#A Hash contatining...
|
16
15
|
#* +response_code+ - The HTTP response code.
|
17
16
|
#* +data+ - A Hash containing the response data.
|
18
17
|
#* +rate_limit+ - The total API credits you get per hour.
|
19
18
|
#* +rate_limit_remaining+ - The number of API credits you have remaining for this hour.
|
20
|
-
def call(
|
19
|
+
def call(user, endpoint, params = {}, user_agent = User::USER_AGENT)
|
21
20
|
# Build the full endpoint URL
|
22
|
-
url = 'http://' + User::API_BASE_URL + endpoint
|
21
|
+
url = 'http' + (user.use_ssl ? 's' : '') + '://' + User::API_BASE_URL + endpoint
|
23
22
|
|
24
23
|
retval = {
|
25
24
|
'response_code' => 500,
|
@@ -30,10 +29,10 @@ module DataSift
|
|
30
29
|
|
31
30
|
begin
|
32
31
|
# Make the call
|
33
|
-
res = RestClient.post(url, params, { 'Auth' => username + ':' + api_key, 'User-Agent' => user_agent })
|
32
|
+
res = RestClient.post(url, params, { 'Auth' => user.username + ':' + user.api_key, 'User-Agent' => user_agent })
|
34
33
|
|
35
34
|
# Success
|
36
|
-
retval['response_code'] =
|
35
|
+
retval['response_code'] = res.code
|
37
36
|
|
38
37
|
# Parse the JSON response
|
39
38
|
retval['data'] = Yajl::Parser.parse(res)
|
data/lib/DataSift/historic.rb
CHANGED
@@ -58,8 +58,6 @@ module DataSift
|
|
58
58
|
attr_reader :sample
|
59
59
|
#The DPU cost of running this Historics query.
|
60
60
|
attr_reader :dpus
|
61
|
-
#The data availability for this Historics query.
|
62
|
-
attr_reader :volume_info
|
63
61
|
#True if this Historics query has been deleted.
|
64
62
|
attr_reader :is_deleted
|
65
63
|
|
@@ -109,7 +107,6 @@ module DataSift
|
|
109
107
|
@progress = 0
|
110
108
|
@dpus = false
|
111
109
|
@availability = {}
|
112
|
-
@volume_info = {}
|
113
110
|
@is_deleted = false
|
114
111
|
end
|
115
112
|
end
|
@@ -169,9 +166,6 @@ module DataSift
|
|
169
166
|
raise APIError, 'No sample in the response' unless data.has_key?('sample')
|
170
167
|
@sample = data['sample']
|
171
168
|
|
172
|
-
raise APIError, 'No volume info in the response' unless data.has_key?('volume_info')
|
173
|
-
@volume_info = data['volume_info']
|
174
|
-
|
175
169
|
@is_deleted = (@status == 'deleted')
|
176
170
|
|
177
171
|
return true
|
@@ -53,6 +53,7 @@ module DataSift
|
|
53
53
|
@auto_reconnect = true
|
54
54
|
@stop_reason = 'Unknown reason'
|
55
55
|
@state = STATE_STOPPED
|
56
|
+
@stream_timeout = 65
|
56
57
|
|
57
58
|
# Get the hash which will compile the CSDL if necessary
|
58
59
|
@definition.hash
|
@@ -124,7 +125,7 @@ module DataSift
|
|
124
125
|
elsif interaction['status'] == 'warning'
|
125
126
|
onWarning.call(interaction['message'])
|
126
127
|
else
|
127
|
-
#
|
128
|
+
# Tick
|
128
129
|
end
|
129
130
|
else
|
130
131
|
if interaction.has_key?('deleted') and interaction['deleted']
|
@@ -22,7 +22,6 @@ module DataSift
|
|
22
22
|
def onStart(&block)
|
23
23
|
begin
|
24
24
|
reconnect() unless !@socket.nil? and !@socket.closed?
|
25
|
-
|
26
25
|
parser = Yajl::Parser.new
|
27
26
|
parser.on_parse_complete = block if block_given?
|
28
27
|
if @response_head[:headers]["Transfer-Encoding"] == 'chunked'
|
@@ -30,6 +29,15 @@ module DataSift
|
|
30
29
|
chunkLeft = 0
|
31
30
|
while !@socket.eof? && (line = @socket.gets) && @state == StreamConsumer::STATE_RUNNING
|
32
31
|
break if line.match /^0.*?\r\n/
|
32
|
+
|
33
|
+
begin
|
34
|
+
ready = IO.select([@socket], nil, [@socket], @stream_timeout)
|
35
|
+
unless ready
|
36
|
+
reconnect()
|
37
|
+
next
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
33
41
|
next if line == "\r\n"
|
34
42
|
size = line.hex
|
35
43
|
json = @socket.read(size)
|
@@ -82,7 +90,6 @@ module DataSift
|
|
82
90
|
end
|
83
91
|
|
84
92
|
private
|
85
|
-
|
86
93
|
#Reconnect the stream socket.
|
87
94
|
def reconnect()
|
88
95
|
uri = URI.parse('http' + (@user.use_ssl ? 's' : '') + '://' + User::STREAM_BASE_URL + @definition.hash)
|
data/lib/DataSift/user.rb
CHANGED
@@ -234,7 +234,7 @@ module DataSift
|
|
234
234
|
@api_client = ApiClient.new()
|
235
235
|
end
|
236
236
|
|
237
|
-
res = @api_client.call(
|
237
|
+
res = @api_client.call(self, endpoint, params, getUserAgent())
|
238
238
|
|
239
239
|
# Set up the return value
|
240
240
|
retval = res['data']
|
data/test/helper.rb
CHANGED
@@ -14,12 +14,12 @@ class Test::Unit::TestCase
|
|
14
14
|
@testdata = YAML::load(File.open(File.join(File.dirname(__FILE__), 'testdata.yml')))
|
15
15
|
|
16
16
|
# Initialise the test data (parse the dates, etc).
|
17
|
-
@testdata['historic_start'] = DateTime.parse(@testdata['historic_start'])
|
18
|
-
@testdata['historic_end'] = DateTime.parse(@testdata['historic_end'])
|
19
|
-
@testdata['historic_created_at'] = DateTime.parse(@testdata['historic_created_at'])
|
20
|
-
@testdata['push_created_at'] = DateTime.parse(@testdata['push_created_at'])
|
21
|
-
@testdata['push_last_request'] = DateTime.parse(@testdata['push_last_request'])
|
22
|
-
@testdata['push_last_success'] = DateTime.parse(@testdata['push_last_success'])
|
17
|
+
@testdata['historic_start'] = DateTime.parse(@testdata['historic_start'].to_s)
|
18
|
+
@testdata['historic_end'] = DateTime.parse(@testdata['historic_end'].to_s)
|
19
|
+
@testdata['historic_created_at'] = DateTime.parse(@testdata['historic_created_at'].to_s)
|
20
|
+
@testdata['push_created_at'] = DateTime.parse(@testdata['push_created_at'].to_s)
|
21
|
+
@testdata['push_last_request'] = DateTime.parse(@testdata['push_last_request'].to_s)
|
22
|
+
@testdata['push_last_success'] = DateTime.parse(@testdata['push_last_success'].to_s)
|
23
23
|
@testdata['historic_sources'] = @testdata['historic_sources'].split(',')
|
24
24
|
|
25
25
|
@user = DataSift::User.new(@config['username'], @config['api_key'])
|
@@ -43,9 +43,6 @@ class Test::Unit::TestCase
|
|
43
43
|
'progress' => 0,
|
44
44
|
'sources' => @testdata['historic_sources'],
|
45
45
|
'sample' => @testdata['historic_sample'],
|
46
|
-
'volume_info' => {
|
47
|
-
'digg' => 9
|
48
|
-
},
|
49
46
|
}
|
50
47
|
@user.api_client.setResponse(200, data.merge(changes), 200, 150)
|
51
48
|
end
|
data/test/test_definition.rb
CHANGED
data/test/test_historics.rb
CHANGED
data/test/test_pushdefinition.rb
CHANGED
data/test/test_user.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datasift
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
4
|
+
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 2
|
8
7
|
- 0
|
9
|
-
-
|
10
|
-
version: 2.0.
|
8
|
+
- 3
|
9
|
+
version: 2.0.3
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- DataSift
|
@@ -15,17 +14,16 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date:
|
17
|
+
date: 2013-03-04 00:00:00 +00:00
|
18
|
+
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rest-client
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
-
none: false
|
25
24
|
requirements:
|
26
25
|
- - ~>
|
27
26
|
- !ruby/object:Gem::Version
|
28
|
-
hash: 9
|
29
27
|
segments:
|
30
28
|
- 1
|
31
29
|
- 6
|
@@ -37,11 +35,9 @@ dependencies:
|
|
37
35
|
name: yajl-ruby
|
38
36
|
prerelease: false
|
39
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
-
none: false
|
41
38
|
requirements:
|
42
39
|
- - ~>
|
43
40
|
- !ruby/object:Gem::Version
|
44
|
-
hash: 19
|
45
41
|
segments:
|
46
42
|
- 1
|
47
43
|
- 1
|
@@ -53,11 +49,9 @@ dependencies:
|
|
53
49
|
name: rdoc
|
54
50
|
prerelease: false
|
55
51
|
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
-
none: false
|
57
52
|
requirements:
|
58
53
|
- - ">"
|
59
54
|
- !ruby/object:Gem::Version
|
60
|
-
hash: 3
|
61
55
|
segments:
|
62
56
|
- 0
|
63
57
|
version: "0"
|
@@ -67,11 +61,9 @@ dependencies:
|
|
67
61
|
name: shoulda
|
68
62
|
prerelease: false
|
69
63
|
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
-
none: false
|
71
64
|
requirements:
|
72
65
|
- - ~>
|
73
66
|
- !ruby/object:Gem::Version
|
74
|
-
hash: 37
|
75
67
|
segments:
|
76
68
|
- 2
|
77
69
|
- 11
|
@@ -83,11 +75,9 @@ dependencies:
|
|
83
75
|
name: rspec
|
84
76
|
prerelease: false
|
85
77
|
requirement: &id005 !ruby/object:Gem::Requirement
|
86
|
-
none: false
|
87
78
|
requirements:
|
88
79
|
- - ~>
|
89
80
|
- !ruby/object:Gem::Version
|
90
|
-
hash: 23
|
91
81
|
segments:
|
92
82
|
- 2
|
93
83
|
- 6
|
@@ -158,6 +148,7 @@ files:
|
|
158
148
|
- test/test_pushsubscription.rb
|
159
149
|
- test/test_user.rb
|
160
150
|
- test/testdata.yml
|
151
|
+
has_rdoc: true
|
161
152
|
homepage: http://github.com/datasift/datasift-ruby
|
162
153
|
licenses: []
|
163
154
|
|
@@ -167,20 +158,16 @@ rdoc_options: []
|
|
167
158
|
require_paths:
|
168
159
|
- lib
|
169
160
|
required_ruby_version: !ruby/object:Gem::Requirement
|
170
|
-
none: false
|
171
161
|
requirements:
|
172
162
|
- - ">="
|
173
163
|
- !ruby/object:Gem::Version
|
174
|
-
hash: 3
|
175
164
|
segments:
|
176
165
|
- 0
|
177
166
|
version: "0"
|
178
167
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
|
-
none: false
|
180
168
|
requirements:
|
181
169
|
- - ">="
|
182
170
|
- !ruby/object:Gem::Version
|
183
|
-
hash: 23
|
184
171
|
segments:
|
185
172
|
- 1
|
186
173
|
- 3
|
@@ -189,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
189
176
|
requirements: []
|
190
177
|
|
191
178
|
rubyforge_project:
|
192
|
-
rubygems_version: 1.
|
179
|
+
rubygems_version: 1.3.6
|
193
180
|
signing_key:
|
194
181
|
specification_version: 3
|
195
182
|
summary: DataSift is a simple wrapper for the DataSift API.
|