datasift 0.2.0 → 1.0.0
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/README.md +1 -1
- data/Rakefile +1 -3
- data/VERSION +1 -1
- data/examples/consume-stream.rb +52 -0
- data/examples/{cost.rb → dpu.rb} +17 -31
- data/lib/DataSift/definition.rb +26 -16
- data/lib/DataSift/stream_consumer.rb +2 -2
- data/lib/DataSift/stream_consumer_http.rb +3 -1
- data/lib/DataSift/user.rb +29 -3
- data/test/test_definition.rb +21 -21
- data/test/test_live_api.rb +9 -9
- data/test/test_user.rb +50 -1
- metadata +16 -15
data/README.md
CHANGED
@@ -28,7 +28,7 @@ consumer.consume(true) do |interaction|
|
|
28
28
|
end
|
29
29
|
```
|
30
30
|
|
31
|
-
See the DataSift documentation for full details of the data contained within each interaction: http://
|
31
|
+
See the DataSift documentation for full details of the data contained within each interaction. See this page on our developer site for an example tweet: http://dev.datasift.com/docs/targets/twitter/twitter-output-format
|
32
32
|
|
33
33
|
License
|
34
34
|
-------
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
1.0.0
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# This simple example demonstrates consuming a stream from just the stream
|
2
|
+
# hash.
|
3
|
+
#
|
4
|
+
# NB: Most of the error handling (exception catching) has been removed for
|
5
|
+
# the sake of simplicity. Nearly everything in this library may throw
|
6
|
+
# exceptions, and production code should catch them. See the documentation
|
7
|
+
# for full details.
|
8
|
+
#
|
9
|
+
|
10
|
+
# Make sure we have some arguments
|
11
|
+
if ARGV.size == 0
|
12
|
+
puts 'ERR: Please specify the hash to consume!'
|
13
|
+
puts
|
14
|
+
puts
|
15
|
+
exit!
|
16
|
+
end
|
17
|
+
|
18
|
+
# Include the DataSift library
|
19
|
+
require File.dirname(__FILE__) + '/../lib/datasift'
|
20
|
+
|
21
|
+
# Include the configuration - put your username and API key in this file
|
22
|
+
config = YAML::load(File.open(File.join(File.dirname(__FILE__), '..', 'config.yml')))
|
23
|
+
|
24
|
+
# Authenticate
|
25
|
+
puts 'Creating user...'
|
26
|
+
user = DataSift::User.new(config['username'], config['api_key'])
|
27
|
+
|
28
|
+
# Create the consumer
|
29
|
+
puts 'Getting the consumer...'
|
30
|
+
consumer = user.getConsumer(DataSift::StreamConsumer::TYPE_HTTP, ARGV[0])
|
31
|
+
|
32
|
+
# Setting up the onStopped handler
|
33
|
+
consumer.onStopped do |reason|
|
34
|
+
puts
|
35
|
+
puts 'Stopped: ' + reason
|
36
|
+
puts
|
37
|
+
end
|
38
|
+
|
39
|
+
# And start consuming
|
40
|
+
puts 'Consuming...'
|
41
|
+
puts '--'
|
42
|
+
consumer.consume(true) do |interaction|
|
43
|
+
if interaction
|
44
|
+
puts 'Type: ' + interaction['interaction']['type']
|
45
|
+
puts 'Content: ' + interaction['interaction']['content']
|
46
|
+
puts '--'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
puts
|
51
|
+
puts 'Finished consuming'
|
52
|
+
puts
|
data/examples/{cost.rb → dpu.rb}
RENAMED
@@ -1,10 +1,10 @@
|
|
1
|
-
# This example gets the
|
1
|
+
# This example gets the DPU associated with the stream given on the command
|
2
2
|
# line or piped/typed into STDIN. It presents it in a nice ASCII table.]
|
3
3
|
# Note that the CSDL must be enclosed in quotes if given on the command line.
|
4
4
|
#
|
5
|
-
# ruby
|
5
|
+
# ruby dpu.rb 'interaction.content contains "football"'
|
6
6
|
# or
|
7
|
-
# cat football.csdl | ruby
|
7
|
+
# cat football.csdl | ruby dpu.rb
|
8
8
|
#
|
9
9
|
# NB: Most of the error handling (exception catching) has been removed for
|
10
10
|
# the sake of simplicity. Nearly everything in this library may throw
|
@@ -38,43 +38,43 @@ user = DataSift::User.new(config['username'], config['api_key'])
|
|
38
38
|
puts 'Creating definition...'
|
39
39
|
definition = user.createDefinition(csdl)
|
40
40
|
|
41
|
-
# Getting
|
42
|
-
puts 'Getting
|
41
|
+
# Getting DPU
|
42
|
+
puts 'Getting DPU...'
|
43
43
|
begin
|
44
|
-
|
44
|
+
dpu = definition.getDPUBreakdown()
|
45
45
|
rescue DataSift::CompileFailedError => e
|
46
46
|
puts 'CSDL compilation failed: ' + e
|
47
47
|
puts
|
48
48
|
exit!
|
49
49
|
end
|
50
50
|
|
51
|
-
|
51
|
+
dputable = []
|
52
52
|
maxlength = {'target' => 'Target'.length, 'times used' => 'Times used'.length, 'complexity' => 'Complexity'.length};
|
53
|
-
|
53
|
+
dpu['detail'].each do |tgt,c|
|
54
54
|
maxlength['target'] = [maxlength['target'], tgt.length].max()
|
55
55
|
maxlength['times used'] = [maxlength['times used'], number_with_delimiter(c['count']).length].max()
|
56
|
-
maxlength['complexity'] = [maxlength['complexity'], number_with_delimiter(c['
|
56
|
+
maxlength['complexity'] = [maxlength['complexity'], number_with_delimiter(c['dpu']).length].max()
|
57
57
|
|
58
|
-
|
58
|
+
dputable.push({
|
59
59
|
'target' => tgt,
|
60
60
|
'times used' => number_with_delimiter(c['count']),
|
61
|
-
'complexity' => number_with_delimiter(c['
|
61
|
+
'complexity' => number_with_delimiter(c['dpu']),
|
62
62
|
})
|
63
63
|
|
64
64
|
c['targets'].each do |tgt2,d|
|
65
65
|
maxlength['target'] = [maxlength['target'], 2 + tgt2.length].max()
|
66
66
|
maxlength['times used'] = [maxlength['times used'], number_with_delimiter(d['count']).length].max()
|
67
|
-
maxlength['complexity'] = [maxlength['complexity'], number_with_delimiter(d['
|
67
|
+
maxlength['complexity'] = [maxlength['complexity'], number_with_delimiter(d['dpu']).length].max()
|
68
68
|
|
69
|
-
|
69
|
+
dputable.push({
|
70
70
|
'target' => ' ' + tgt2,
|
71
71
|
'times used' => number_with_delimiter(d['count']),
|
72
|
-
'complexity' => number_with_delimiter(d['
|
72
|
+
'complexity' => number_with_delimiter(d['dpu']),
|
73
73
|
})
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
maxlength['complexity'] = [maxlength['complexity'], number_with_delimiter(
|
77
|
+
maxlength['complexity'] = [maxlength['complexity'], number_with_delimiter(dpu['dpu']).length].max()
|
78
78
|
|
79
79
|
puts
|
80
80
|
print '/-' + ('-' * maxlength['target']) + '---'
|
@@ -89,7 +89,7 @@ print '|-' + ('-' * maxlength['target']) + '-+-'
|
|
89
89
|
print ('-' * maxlength['times used']) + '-+-'
|
90
90
|
puts ('-' * maxlength['complexity']) + '-|'
|
91
91
|
|
92
|
-
|
92
|
+
dputable.each do |row|
|
93
93
|
print '| ' + row['target'].ljust(maxlength['target']) + ' | '
|
94
94
|
print row['times used'].rjust(maxlength['times used']) + ' | '
|
95
95
|
puts row['complexity'].rjust(maxlength['complexity']) + ' |'
|
@@ -100,24 +100,10 @@ print ('-' * maxlength['times used']) + '-+-'
|
|
100
100
|
puts ('-' * maxlength['complexity']) + '-|'
|
101
101
|
|
102
102
|
print '| ' + 'Total'.rjust(maxlength['target'] + 3 + maxlength['times used']) + ' = '
|
103
|
-
puts
|
103
|
+
puts dpu['dpu'].to_s.rjust(maxlength['complexity']) + ' |'
|
104
104
|
|
105
105
|
print '\\-' + ('-' * maxlength['target']) + '---'
|
106
106
|
print ('-' * maxlength['times used']) + '---'
|
107
107
|
puts ('-' * maxlength['complexity']) + '-/'
|
108
108
|
|
109
109
|
puts
|
110
|
-
|
111
|
-
if cost['total'] > 1000
|
112
|
-
tiernum = 3;
|
113
|
-
tierdesc = 'high complexity';
|
114
|
-
elsif cost['total'] > 100
|
115
|
-
tiernum = 2;
|
116
|
-
tierdesc = 'medium complexity';
|
117
|
-
else
|
118
|
-
tiernum = 1;
|
119
|
-
tierdesc = 'simple complexity';
|
120
|
-
end
|
121
|
-
|
122
|
-
puts 'A total cost of ' + number_with_delimiter(cost['total']) + ' puts this stream in tier ' + tiernum.to_s + ', ' + tierdesc
|
123
|
-
puts
|
data/lib/DataSift/definition.rb
CHANGED
@@ -18,7 +18,7 @@ module DataSift
|
|
18
18
|
# The Definition class represents a stream definition.
|
19
19
|
#
|
20
20
|
class Definition
|
21
|
-
attr_reader :csdl, :
|
21
|
+
attr_reader :csdl, :total_dpu, :created_at
|
22
22
|
|
23
23
|
# Constructor. A User object is required, and you can optionally supply a
|
24
24
|
# default CSDL string.
|
@@ -36,12 +36,22 @@ module DataSift
|
|
36
36
|
self.csdl = csdl
|
37
37
|
end
|
38
38
|
|
39
|
+
# CSDL getter
|
40
|
+
def csdl
|
41
|
+
raise InvalidDataError, 'The CSDL is not available' unless !@csdl.nil?
|
42
|
+
@csdl
|
43
|
+
end
|
44
|
+
|
39
45
|
# CSDL setter. Strips the incoming string and resets the hash if it's changed.
|
40
46
|
def csdl=(csdl)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
47
|
+
if csdl.nil?
|
48
|
+
@csdl = nil
|
49
|
+
else
|
50
|
+
raise InvalidDataError, 'The CSDL must be a string.' unless csdl.is_a? String
|
51
|
+
csdl.strip!
|
52
|
+
clearHash() unless csdl == @csdl
|
53
|
+
@csdl = csdl
|
54
|
+
end
|
45
55
|
end
|
46
56
|
|
47
57
|
# Hash getter. If the hash has not yet been obtained the CSDL will be
|
@@ -61,8 +71,9 @@ module DataSift
|
|
61
71
|
# Reset the hash to false. The effect of this is to mark the definition as
|
62
72
|
# requiring compilation.
|
63
73
|
def clearHash()
|
74
|
+
@csdl = '' unless !@csdl.nil?
|
64
75
|
@hash = false
|
65
|
-
@
|
76
|
+
@total_dpu = false
|
66
77
|
@created_at = false
|
67
78
|
end
|
68
79
|
|
@@ -80,10 +91,10 @@ module DataSift
|
|
80
91
|
raise CompileFailedError, 'Compiled successfully but no hash in the response'
|
81
92
|
end
|
82
93
|
|
83
|
-
if res.has_key?('
|
84
|
-
@
|
94
|
+
if res.has_key?('dpu')
|
95
|
+
@total_dpu = Float(res['dpu'])
|
85
96
|
else
|
86
|
-
raise CompileFailedError, 'Compiled successfully but no
|
97
|
+
raise CompileFailedError, 'Compiled successfully but no DPU in the response'
|
87
98
|
end
|
88
99
|
|
89
100
|
if res.has_key?('created_at')
|
@@ -103,16 +114,15 @@ module DataSift
|
|
103
114
|
end
|
104
115
|
end
|
105
116
|
|
106
|
-
# Call the DataSift API to get the
|
117
|
+
# Call the DataSift API to get the DPU for this definition. Returns an
|
107
118
|
# array containing...
|
108
|
-
#
|
109
|
-
#
|
110
|
-
# total => The total cost of the rule
|
119
|
+
# detail => The breakdown of running the rule
|
120
|
+
# dpu => The total DPU of the rule
|
111
121
|
#
|
112
|
-
def
|
113
|
-
raise InvalidDataError, "Cannot get the
|
122
|
+
def getDPUBreakdown()
|
123
|
+
raise InvalidDataError, "Cannot get the DPU for an empty definition." unless @csdl.length > 0
|
114
124
|
|
115
|
-
@user.callAPI('
|
125
|
+
@user.callAPI('dpu', { 'hash' => self.hash })
|
116
126
|
end
|
117
127
|
|
118
128
|
# Call the DataSift API to get buffered interactions.
|
@@ -57,8 +57,8 @@ module DataSift
|
|
57
57
|
@stop_reason = 'Unknown reason'
|
58
58
|
@state = STATE_STOPPED
|
59
59
|
|
60
|
-
#
|
61
|
-
@definition.
|
60
|
+
# Get the hash which will compile the CSDL if necessary
|
61
|
+
@definition.hash
|
62
62
|
end
|
63
63
|
|
64
64
|
# This is called when the consumer is stopped.
|
data/lib/DataSift/user.rb
CHANGED
@@ -22,9 +22,9 @@ module DataSift
|
|
22
22
|
# provides factory methods for all of the functionality in the API.
|
23
23
|
#
|
24
24
|
class User
|
25
|
-
USER_AGENT = 'DataSiftRuby/0.
|
26
|
-
API_BASE_URL = 'api.datasift.
|
27
|
-
STREAM_BASE_URL = 'stream.datasift.
|
25
|
+
USER_AGENT = 'DataSiftRuby/0.3.0';
|
26
|
+
API_BASE_URL = 'api.datasift.com/';
|
27
|
+
STREAM_BASE_URL = 'stream.datasift.com/';
|
28
28
|
|
29
29
|
attr_reader :username, :api_key, :rate_limit, :rate_limit_remaining, :api_client
|
30
30
|
|
@@ -54,6 +54,32 @@ module DataSift
|
|
54
54
|
DataSift::Definition.new(self, csdl, false)
|
55
55
|
end
|
56
56
|
|
57
|
+
# Returns a StreamConsumer-derived object for the given hash, for the
|
58
|
+
# given type.
|
59
|
+
# === Parameters
|
60
|
+
#
|
61
|
+
# * +type+ - The consumer type for which to construct a consumer.
|
62
|
+
# * +hash+ - The hash to be consumed.
|
63
|
+
#
|
64
|
+
def getConsumer(type = nil, hash = nil, on_interaction = nil, on_stopped = nil)
|
65
|
+
StreamConsumer.factory(self, type, Definition.new(self, nil, hash))
|
66
|
+
end
|
67
|
+
|
68
|
+
# Returns the usage data for this user. If a hash is provided then a more
|
69
|
+
# detailed breakdown using interaction types is retrieved and returned.
|
70
|
+
# === Parameters
|
71
|
+
#
|
72
|
+
# * +period+ - An optional period for which to fetch data ('hour' or 'day')
|
73
|
+
def getUsage(period = 'hour')
|
74
|
+
if period != 'hour' and period != 'day'
|
75
|
+
raise EInvalidData, 'Period must be hour or day'
|
76
|
+
end
|
77
|
+
|
78
|
+
params = { 'period' => period }
|
79
|
+
|
80
|
+
callAPI('usage', params)
|
81
|
+
end
|
82
|
+
|
57
83
|
# Returns the user agent this library should use for all API calls.
|
58
84
|
def getUserAgent()
|
59
85
|
USER_AGENT
|
data/test/test_definition.rb
CHANGED
@@ -74,7 +74,7 @@ class TestDefinition < Test::Unit::TestCase
|
|
74
74
|
@user.api_client.setResponse(200, {
|
75
75
|
'hash' => @testdata['definition_hash'],
|
76
76
|
'created_at' => Time.now.strftime('%Y-%m-%d %H:%M:%S'),
|
77
|
-
'
|
77
|
+
'dpu' => 10,
|
78
78
|
}, 200, 150)
|
79
79
|
@definition.compile()
|
80
80
|
rescue InvalidDataError
|
@@ -90,26 +90,26 @@ class TestDefinition < Test::Unit::TestCase
|
|
90
90
|
@user.api_client.setResponse(200, {
|
91
91
|
'hash' => @testdata['definition_hash'],
|
92
92
|
'created_at' => Time.now.strftime('%Y-%m-%d %H:%M:%S'),
|
93
|
-
'
|
93
|
+
'dpu' => 10,
|
94
94
|
}, 200, 150)
|
95
95
|
assert_equal @testdata['definition_hash'], @definition.hash
|
96
96
|
end
|
97
97
|
|
98
|
-
should "have a positive
|
98
|
+
should "have a positive DPU" do
|
99
99
|
@user.api_client.setResponse(200, {
|
100
100
|
'hash' => @testdata['definition_hash'],
|
101
101
|
'created_at' => Time.now.strftime('%Y-%m-%d %H:%M:%S'),
|
102
|
-
'
|
102
|
+
'dpu' => 10,
|
103
103
|
}, 200, 150)
|
104
104
|
@definition.compile()
|
105
|
-
assert @definition.
|
105
|
+
assert @definition.total_dpu > 0
|
106
106
|
end
|
107
107
|
|
108
108
|
should "have a valid created_at date" do
|
109
109
|
@user.api_client.setResponse(200, {
|
110
110
|
'hash' => @testdata['definition_hash'],
|
111
111
|
'created_at' => Time.now.strftime('%Y-%m-%d %H:%M:%S'),
|
112
|
-
'
|
112
|
+
'dpu' => 10,
|
113
113
|
}, 200, 150)
|
114
114
|
@definition.compile()
|
115
115
|
assert @definition.created_at
|
@@ -138,7 +138,7 @@ class TestDefinition < Test::Unit::TestCase
|
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
|
-
context "The
|
141
|
+
context "The DPU returned from a valid Definition object" do
|
142
142
|
setup do
|
143
143
|
init()
|
144
144
|
initUser()
|
@@ -147,35 +147,35 @@ class TestDefinition < Test::Unit::TestCase
|
|
147
147
|
@user.api_client.setResponse(200, {
|
148
148
|
'hash' => @testdata['definition_hash'],
|
149
149
|
'created_at' => Time.now.strftime('%Y-%m-%d %H:%M:%S'),
|
150
|
-
'
|
150
|
+
'dpu' => 10,
|
151
151
|
}, 200, 150)
|
152
152
|
@definition.compile()
|
153
|
-
# Now get the
|
153
|
+
# Now get the DPU
|
154
154
|
@user.api_client.setResponse(200, {
|
155
|
-
'
|
155
|
+
'detail' => {
|
156
156
|
'contains' => {
|
157
157
|
'count' => 1,
|
158
|
-
'
|
158
|
+
'dpu' => 4,
|
159
159
|
'targets' => {
|
160
160
|
'interaction.content' => {
|
161
161
|
'count' => 1,
|
162
|
-
'
|
162
|
+
'dpu' => 4,
|
163
163
|
},
|
164
164
|
},
|
165
165
|
},
|
166
166
|
},
|
167
|
-
'
|
167
|
+
'dpu' => 4
|
168
168
|
}, 200, 150)
|
169
|
-
@
|
169
|
+
@dpu = @definition.getDPUBreakdown()
|
170
170
|
end
|
171
171
|
|
172
|
-
should "contain valid
|
173
|
-
assert @
|
174
|
-
assert @
|
172
|
+
should "contain valid DPU data" do
|
173
|
+
assert @dpu.has_key?('detail')
|
174
|
+
assert @dpu.has_key?('dpu')
|
175
175
|
end
|
176
176
|
|
177
|
-
should "have a positive total
|
178
|
-
assert @
|
177
|
+
should "have a positive total DPU" do
|
178
|
+
assert @dpu['dpu'] > 0
|
179
179
|
end
|
180
180
|
end
|
181
181
|
|
@@ -188,7 +188,7 @@ class TestDefinition < Test::Unit::TestCase
|
|
188
188
|
@user.api_client.setResponse(200, {
|
189
189
|
'hash' => @testdata['definition_hash'],
|
190
190
|
'created_at' => Time.now.strftime('%Y-%m-%d %H:%M:%S'),
|
191
|
-
'
|
191
|
+
'dpu' => 10,
|
192
192
|
}, 200, 150)
|
193
193
|
@definition.compile()
|
194
194
|
# Now get some buffered interactions
|
@@ -268,7 +268,7 @@ class TestDefinition < Test::Unit::TestCase
|
|
268
268
|
@user.api_client.setResponse(200, {
|
269
269
|
'hash' => @testdata['definition_hash'],
|
270
270
|
'created_at' => Time.now.strftime('%Y-%m-%d %H:%M:%S'),
|
271
|
-
'
|
271
|
+
'dpu' => 10,
|
272
272
|
}, 200, 150)
|
273
273
|
@definition.compile()
|
274
274
|
# Now get a consumer
|
data/test/test_live_api.rb
CHANGED
@@ -26,9 +26,9 @@ class TestDefinitionLive < Test::Unit::TestCase
|
|
26
26
|
assert_equal @testdata['definition_hash'], @definition.hash
|
27
27
|
end
|
28
28
|
|
29
|
-
should "have a positive
|
29
|
+
should "have a positive DPU" do
|
30
30
|
@definition.compile()
|
31
|
-
assert @definition.
|
31
|
+
assert @definition.total_dpu > 0
|
32
32
|
end
|
33
33
|
|
34
34
|
should "have a valid created_at date" do
|
@@ -54,21 +54,21 @@ class TestDefinitionLive < Test::Unit::TestCase
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
context "The
|
57
|
+
context "The DPU returned from a valid Definition object" do
|
58
58
|
setup do
|
59
59
|
init()
|
60
60
|
initUser(false)
|
61
61
|
@definition = @user.createDefinition(@testdata['definition'])
|
62
|
-
@
|
62
|
+
@dpu = @definition.getDPUBreakdown()
|
63
63
|
end
|
64
64
|
|
65
|
-
should "contain valid
|
66
|
-
assert @
|
67
|
-
assert @
|
65
|
+
should "contain valid DPU data" do
|
66
|
+
assert @dpu.has_key?('detail')
|
67
|
+
assert @dpu.has_key?('dpu')
|
68
68
|
end
|
69
69
|
|
70
|
-
should "have a positive total
|
71
|
-
assert @
|
70
|
+
should "have a positive total DPU" do
|
71
|
+
assert @dpu['dpu'] > 0
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
data/test/test_user.rb
CHANGED
@@ -16,6 +16,28 @@ class TestUser < Test::Unit::TestCase
|
|
16
16
|
assert_not_nil @user
|
17
17
|
assert_equal @config['api_key'], @user.api_key
|
18
18
|
end
|
19
|
+
|
20
|
+
should "return valid summary usage information" do
|
21
|
+
@user.api_client.setResponse(200, {
|
22
|
+
'start' => 'Mon, 07 Nov 2011 14:20:00 +0000',
|
23
|
+
'streams' => {
|
24
|
+
'5e82aa9ac3dcf4dec1cce08a0cec914a' => {
|
25
|
+
'seconds' => 313,
|
26
|
+
'licenses' => {
|
27
|
+
'twitter' => 17,
|
28
|
+
'facebook' => 5
|
29
|
+
}
|
30
|
+
}
|
31
|
+
},
|
32
|
+
'end' => 'Mon, 07 Nov 2011 15:20:00 +0000'
|
33
|
+
}, 200, 150)
|
34
|
+
usage = @user.getUsage()
|
35
|
+
assert_equal "Mon, 07 Nov 2011 14:20:00 +0000", usage['start']
|
36
|
+
assert_equal "Mon, 07 Nov 2011 15:20:00 +0000", usage['end']
|
37
|
+
assert_equal 313, usage['streams']['5e82aa9ac3dcf4dec1cce08a0cec914a']['seconds']
|
38
|
+
assert_equal 17, usage['streams']['5e82aa9ac3dcf4dec1cce08a0cec914a']['licenses']['twitter']
|
39
|
+
assert_equal 5, usage['streams']['5e82aa9ac3dcf4dec1cce08a0cec914a']['licenses']['facebook']
|
40
|
+
end
|
19
41
|
end
|
20
42
|
|
21
43
|
context "Given an empty definition from the User factory" do
|
@@ -52,7 +74,7 @@ class TestUser < Test::Unit::TestCase
|
|
52
74
|
@user.api_client.setResponse(200, {
|
53
75
|
'hash' => @testdata['definition_hash'],
|
54
76
|
'created_at' => Time.now.strftime('%Y-%m-%d %H:%M:%S'),
|
55
|
-
'
|
77
|
+
'dpu' => 10,
|
56
78
|
}, 200, 150)
|
57
79
|
@definition.compile()
|
58
80
|
end
|
@@ -65,4 +87,31 @@ class TestUser < Test::Unit::TestCase
|
|
65
87
|
assert @user.rate_limit_remaining == 150
|
66
88
|
end
|
67
89
|
end
|
90
|
+
|
91
|
+
context "The exception raised by the User.getUsage method" do
|
92
|
+
setup do
|
93
|
+
init()
|
94
|
+
initUser()
|
95
|
+
end
|
96
|
+
|
97
|
+
should "be APIError given a 400 response" do
|
98
|
+
@user.api_client.setResponse(400, { 'error' => 'Bad request from user supplied data'}, 200, 150)
|
99
|
+
assert_raise(DataSift::APIError) { usage = @user.getUsage() }
|
100
|
+
end
|
101
|
+
|
102
|
+
should "be AccessDenied given a 401 response" do
|
103
|
+
@user.api_client.setResponse(401, { 'error' => 'User banned because they are a very bad person'}, 200, 150)
|
104
|
+
assert_raise(DataSift::AccessDeniedError) { usage = @user.getUsage() }
|
105
|
+
end
|
106
|
+
|
107
|
+
should "be APIError given a 404 response" do
|
108
|
+
@user.api_client.setResponse(404, { 'error' => 'Endpoint or data not found'}, 200, 150)
|
109
|
+
assert_raise(DataSift::APIError) { usage = @user.getUsage() }
|
110
|
+
end
|
111
|
+
|
112
|
+
should "be APIError given a 500 response" do
|
113
|
+
@user.api_client.setResponse(500, { 'error' => 'Problem with an internal service'}, 200, 150)
|
114
|
+
assert_raise(DataSift::APIError) { usage = @user.getUsage() }
|
115
|
+
end
|
116
|
+
end
|
68
117
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datasift
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-11-21 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
16
|
-
requirement: &
|
16
|
+
requirement: &8779460 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.6.3
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *8779460
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: crack
|
27
|
-
requirement: &
|
27
|
+
requirement: &8778640 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *8778640
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: yajl-ruby
|
38
|
-
requirement: &
|
38
|
+
requirement: &8777980 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 0.8.2
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *8777980
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rdoc
|
49
|
-
requirement: &
|
49
|
+
requirement: &8777260 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *8777260
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: shoulda
|
60
|
-
requirement: &
|
60
|
+
requirement: &8776460 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 2.11.3
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *8776460
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
|
-
requirement: &
|
71
|
+
requirement: &8775820 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: 2.6.0
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *8775820
|
80
80
|
description: The official Ruby library for accessing the DataSift API. See http://datasift.net/
|
81
81
|
for full details and to sign up for an account.
|
82
82
|
email:
|
@@ -91,7 +91,8 @@ files:
|
|
91
91
|
- VERSION
|
92
92
|
- config.yml
|
93
93
|
- datasift.gemspec
|
94
|
-
- examples/
|
94
|
+
- examples/consume-stream.rb
|
95
|
+
- examples/dpu.rb
|
95
96
|
- examples/football-buffered.rb
|
96
97
|
- examples/football.rb
|
97
98
|
- examples/twitter-track.rb
|