datasift 3.0.0.beta4 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/CHANGELOG.md +12 -0
- data/LICENSE +1 -1
- data/MIGRATING_TO_V.3.0.0.md +1 -1
- data/README.md +23 -2
- data/Rakefile +10 -0
- data/VERSION +1 -1
- data/datasift.gemspec +4 -4
- data/examples/auth.rb +14 -10
- data/examples/cli.sh +2 -2
- data/examples/core_api_eg.rb +6 -1
- data/examples/dynamic_list_eg.rb +74 -0
- data/examples/dynamic_list_replace_eg.rb +45 -0
- data/examples/historics_eg.rb +20 -13
- data/examples/historics_preview_eg.rb +5 -4
- data/examples/live_stream_eg.rb +2 -1
- data/examples/managed_source_eg.rb +11 -10
- data/examples/pull.rb +8 -8
- data/examples/push_eg.rb +32 -15
- data/lib/cli.rb +2 -2
- data/lib/datasift.rb +7 -3
- data/lib/dynamic_list.rb +66 -0
- data/lib/dynamic_list_replace.rb +45 -0
- data/lib/historics.rb +17 -0
- data/lib/historics_preview.rb +2 -1
- data/lib/push.rb +10 -17
- data/test/datasift/core_api_test.rb +153 -0
- data/test/datasift/historics_preview_api_test.rb +83 -0
- data/test/datasift/push_api_test.rb +223 -0
- data/test/fixtures/balance.json +1 -0
- data/test/fixtures/compile_csdl_invalid.json +1 -0
- data/test/fixtures/compile_csdl_valid.json +1 -0
- data/test/fixtures/dpu_valid.json +1 -0
- data/test/fixtures/preview_create_valid.json +1 -0
- data/test/fixtures/preview_get_running.json +1 -0
- data/test/fixtures/preview_get_succeeded.json +1 -0
- data/test/fixtures/push_create_valid.json +1 -0
- data/test/fixtures/push_get_list_by_hash_valid.json +1 -0
- data/test/fixtures/push_get_list_by_historics_id_valid.json +1 -0
- data/test/fixtures/push_get_list_valid.json +1 -0
- data/test/fixtures/push_get_valid.json +1 -0
- data/test/fixtures/push_log_valid.json +1 -0
- data/test/fixtures/push_pause_valid.json +1 -0
- data/test/fixtures/push_stop_valid.json +1 -0
- data/test/fixtures/push_validate_valid.json +1 -0
- data/test/fixtures/usage_current.json +1 -0
- data/test/fixtures/validate_csdl_invalid.json +1 -0
- data/test/fixtures/validate_csdl_valid.json +1 -0
- data/test/test_helper.rb +17 -0
- metadata +36 -9
- data/tests/core_api_test.rb +0 -95
data/examples/live_stream_eg.rb
CHANGED
@@ -10,13 +10,14 @@ class ManagedSourceApi < DataSiftExample
|
|
10
10
|
puts 'Creating a managed source'
|
11
11
|
parameters = {:likes => true,
|
12
12
|
:posts_by_others => true,
|
13
|
-
:comments => true
|
13
|
+
:comments => true,
|
14
|
+
:page_likes => true
|
14
15
|
}
|
15
16
|
resources = [{
|
16
17
|
:parameters => {
|
17
|
-
:url => 'http://www.facebook.com/
|
18
|
+
:url => 'http://www.facebook.com/theguardian',
|
18
19
|
:title => 'Some news page',
|
19
|
-
:id => :
|
20
|
+
:id => :theguardian
|
20
21
|
}
|
21
22
|
}]
|
22
23
|
auth = [{
|
@@ -30,22 +31,22 @@ class ManagedSourceApi < DataSiftExample
|
|
30
31
|
|
31
32
|
id = source[:data][:id]
|
32
33
|
|
33
|
-
puts
|
34
|
+
puts "\nStarting delivery for my Managed Source"
|
34
35
|
puts @datasift.managed_source.start id
|
35
36
|
|
36
|
-
puts
|
37
|
+
puts "\nUpdating"
|
37
38
|
puts @datasift.managed_source.update(id, 'facebook_page', 'Updated source', parameters, resources, auth)
|
38
39
|
|
39
|
-
puts
|
40
|
+
puts "\nGetting info from DataSift about my page"
|
40
41
|
puts @datasift.managed_source.get id
|
41
42
|
|
42
|
-
puts
|
43
|
+
puts "\nFetching logs"
|
43
44
|
puts @datasift.managed_source.log id
|
44
45
|
|
45
|
-
puts
|
46
|
+
puts "\nStopping"
|
46
47
|
puts @datasift.managed_source.stop id
|
47
48
|
|
48
|
-
puts
|
49
|
+
puts "\nDeleting"
|
49
50
|
puts @datasift.managed_source.delete id
|
50
51
|
rescue DataSiftError => dse
|
51
52
|
puts dse.message
|
@@ -53,4 +54,4 @@ class ManagedSourceApi < DataSiftExample
|
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
56
|
-
ManagedSourceApi.new
|
57
|
+
ManagedSourceApi.new
|
data/examples/pull.rb
CHANGED
@@ -7,7 +7,7 @@ class PushApi < DataSiftExample
|
|
7
7
|
def run
|
8
8
|
begin
|
9
9
|
@params = {:output_type => 'pull'}
|
10
|
-
puts 'Validating'
|
10
|
+
puts 'Validating the Pull subscription'
|
11
11
|
if @datasift.push.valid? @params
|
12
12
|
stream = @datasift.compile 'interaction.content contains "music"'
|
13
13
|
subscription = create_push(stream[:data][:hash])
|
@@ -16,22 +16,22 @@ class PushApi < DataSiftExample
|
|
16
16
|
#pull a bunch of interactions from the push queue - only work if we had set the output_type above to pull
|
17
17
|
#pull @datasift.pull subscription_id
|
18
18
|
|
19
|
-
puts
|
19
|
+
puts "\nPulling data a first time, then waiting 10 seconds"
|
20
20
|
@datasift.push.pull(subscription_id).each { |e| puts e }
|
21
21
|
|
22
22
|
sleep 10
|
23
23
|
|
24
|
-
puts
|
24
|
+
puts "\nPulling data a second time, then waiting 10 seconds"
|
25
25
|
@datasift.push.pull(subscription_id).each { |e| puts e }
|
26
26
|
|
27
27
|
sleep 10
|
28
28
|
|
29
|
-
puts
|
29
|
+
puts "\nPulling data the third and final time time"
|
30
30
|
#passing a lambda is more efficient because it is executed once for each interaction received
|
31
31
|
#this saves having to iterate over the array returned so the same iteration isn't done twice
|
32
|
-
@datasift.push.pull(subscription_id,20971520,'', lambda{ |e| puts "on_message => #{e}" })
|
32
|
+
@datasift.push.pull(subscription_id, 20971520, '', lambda{ |e| puts "on_message => #{e}" })
|
33
33
|
|
34
|
-
puts
|
34
|
+
puts "\nDeleting the Pull subscription"
|
35
35
|
@datasift.push.delete subscription_id
|
36
36
|
end
|
37
37
|
#rescue DataSiftError
|
@@ -39,6 +39,6 @@ class PushApi < DataSiftExample
|
|
39
39
|
puts dse.inspect
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
43
42
|
end
|
44
|
-
|
43
|
+
|
44
|
+
PushApi.new().run
|
data/examples/push_eg.rb
CHANGED
@@ -2,32 +2,49 @@ require './auth'
|
|
2
2
|
class PushApi < DataSiftExample
|
3
3
|
def initialize
|
4
4
|
super
|
5
|
+
run
|
5
6
|
end
|
6
7
|
|
7
|
-
def run
|
8
|
+
def run
|
8
9
|
begin
|
9
|
-
|
10
|
+
puts 'Creating Push subscription'
|
11
|
+
subscription = @datasift.push.create @params.merge(hash: '54dbfc8464258de162b7f1a057e630c5', name: 'Ruby Client Example')
|
10
12
|
|
11
13
|
subscription_id = subscription[:data][:id]
|
12
|
-
|
13
|
-
#pull @datasift.pull subscription_id
|
14
|
+
puts "\nPush subscription created! Push Subscription ID #{subscription_id}"
|
14
15
|
|
15
|
-
puts
|
16
|
-
#
|
16
|
+
puts "\nGetting subscription info"
|
17
|
+
# Get details for a subscription. Also available are
|
17
18
|
# push.[get, get_by_hash,get_by_historics_id]
|
18
19
|
puts @datasift.push.get_by_subscription subscription_id
|
20
|
+
|
21
|
+
puts "\nPausing Push subscription"
|
22
|
+
# Push subscriptions can be paused for up to an hour
|
23
|
+
@datasift.push.pause subscription_id
|
24
|
+
|
25
|
+
puts "\nResuming Push subscription"
|
26
|
+
# Push subscriptions must be resumed to continue delivering data
|
27
|
+
@datasift.push.resume subscription_id
|
28
|
+
|
29
|
+
puts "\nGetting subscription logs"
|
30
|
+
# Get logs for a subscription. Also available is
|
31
|
+
# push.log to get logs for all subscriptions
|
32
|
+
puts @datasift.push.log_for subscription_id
|
33
|
+
|
34
|
+
puts "\nStopping Push subscription"
|
35
|
+
# Push subscriptions can be stopped. Once stopped, a
|
36
|
+
# subscription can not be resumed
|
37
|
+
@datasift.push.stop subscription_id
|
38
|
+
|
39
|
+
puts "\nDeleting Push subscription"
|
40
|
+
# Push subscriptions can be deleted. On delete, any undelivered
|
41
|
+
# data is dropped. A delete is permenent.
|
42
|
+
@datasift.push.delete subscription_id
|
43
|
+
|
19
44
|
rescue DataSiftError => dse
|
20
45
|
puts dse.message
|
21
46
|
end
|
22
47
|
end
|
23
|
-
|
24
|
-
def get_all
|
25
|
-
puts MultiJson.dump(@datasift.push.get(1, 500))
|
26
|
-
end
|
27
48
|
end
|
28
49
|
|
29
|
-
|
30
|
-
#for i in 1..1000
|
31
|
-
# p.run(i)
|
32
|
-
#end
|
33
|
-
p.get_all()
|
50
|
+
PushApi.new()
|
data/lib/cli.rb
CHANGED
@@ -178,8 +178,8 @@ def run_push_command (c, command, p)
|
|
178
178
|
c.push.get_by_subscription(p['id'], opt(p['page'], 0), opt(p['per_page'], 20), opt(p['order_by'], :request_time))
|
179
179
|
elsif p['hash']
|
180
180
|
c.push.get_by_hash(p['hash'], opt(p['page'], 0), opt(p['per_page'], 20), opt(p['order_by'], :request_time), opt(p['order_dir'], :desc))
|
181
|
-
elsif p['
|
182
|
-
c.push.get_by_historics_id(p['
|
181
|
+
elsif p['historics_id']
|
182
|
+
c.push.get_by_historics_id(p['historics_id'], opt(p['page'], 0), opt(p['per_page'], 20), opt(p['order_by'], :request_time), opt(p['order_dir'], :desc))
|
183
183
|
else
|
184
184
|
c.push.get(opt(p['page'], 0), opt(p['per_page'], 20), opt(p['order_by'], :request_time), opt(p['order_dir'], :desc))
|
185
185
|
end
|
data/lib/datasift.rb
CHANGED
@@ -13,6 +13,8 @@ require dir + '/historics'
|
|
13
13
|
require dir + '/historics_preview'
|
14
14
|
require dir + '/managed_source'
|
15
15
|
require dir + '/live_stream'
|
16
|
+
require dir + '/dynamic_list'
|
17
|
+
require dir + '/dynamic_list_replace'
|
16
18
|
#
|
17
19
|
require 'rbconfig'
|
18
20
|
|
@@ -53,9 +55,11 @@ module DataSift
|
|
53
55
|
@push = DataSift::Push.new(config)
|
54
56
|
@managed_source = DataSift::ManagedSource.new(config)
|
55
57
|
@historics_preview = DataSift::HistoricsPreview.new(config)
|
58
|
+
@dynamic_list = DataSift::DynamicList.new(config)
|
59
|
+
@dynamic_list_replace = DataSift::DynamicListReplace.new(config)
|
56
60
|
end
|
57
61
|
|
58
|
-
attr_reader :historics, :push, :managed_source, :historics_preview
|
62
|
+
attr_reader :historics, :push, :managed_source, :historics_preview, :dynamic_list, :dynamic_list_replace
|
59
63
|
|
60
64
|
##
|
61
65
|
# Checks if the syntax of the given CSDL is valid
|
@@ -63,7 +67,7 @@ module DataSift
|
|
63
67
|
# the response object itself is returned
|
64
68
|
def valid?(csdl, boolResponse = true)
|
65
69
|
requires({:csdl => csdl})
|
66
|
-
res= DataSift.request(:POST, 'validate', @config, {:csdl => csdl})
|
70
|
+
res = DataSift.request(:POST, 'validate', @config, {:csdl => csdl})
|
67
71
|
boolResponse ? res[:http][:status] == 200 : res
|
68
72
|
end
|
69
73
|
|
@@ -92,7 +96,7 @@ module DataSift
|
|
92
96
|
##
|
93
97
|
# Determine your credit balance or DPU balance.
|
94
98
|
def balance
|
95
|
-
DataSift.request(:POST, 'balance', @config
|
99
|
+
DataSift.request(:POST, 'balance', @config)
|
96
100
|
end
|
97
101
|
|
98
102
|
##
|
data/lib/dynamic_list.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
module DataSift
|
2
|
+
class DynamicList < DataSift::ApiResource
|
3
|
+
|
4
|
+
##
|
5
|
+
# Get all lists and their ids.
|
6
|
+
def get
|
7
|
+
params = {}
|
8
|
+
requires params
|
9
|
+
DataSift.request(:GET, 'list/get', @config, params)
|
10
|
+
end
|
11
|
+
|
12
|
+
##
|
13
|
+
# Create a new dynamic list
|
14
|
+
def create (type, name)
|
15
|
+
params = {
|
16
|
+
:type => type
|
17
|
+
}
|
18
|
+
requires params
|
19
|
+
params[:name] = name
|
20
|
+
DataSift.request(:POST, 'list/create', @config, params)
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# Delete a dynamic list
|
25
|
+
def delete (id)
|
26
|
+
params = {
|
27
|
+
:id => id
|
28
|
+
}
|
29
|
+
requires params
|
30
|
+
DataSift.request(:DELETE, 'list/delete', @config, params)
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# Check if items exist in given list
|
35
|
+
def exists (id, items)
|
36
|
+
params = {
|
37
|
+
:id => id,
|
38
|
+
:items => items
|
39
|
+
}
|
40
|
+
requires params
|
41
|
+
DataSift.request(:POST, 'list/exists', @config, params)
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Add items to a given list
|
46
|
+
def add (id, items)
|
47
|
+
params = {
|
48
|
+
:id => id,
|
49
|
+
:items => items
|
50
|
+
}
|
51
|
+
requires params
|
52
|
+
DataSift.request(:POST, 'list/add', @config, params)
|
53
|
+
end
|
54
|
+
|
55
|
+
##
|
56
|
+
# Remove items from a given list
|
57
|
+
def remove (id, items)
|
58
|
+
params = {
|
59
|
+
:id => id,
|
60
|
+
:items => items
|
61
|
+
}
|
62
|
+
requires params
|
63
|
+
DataSift.request(:POST, 'list/remove', @config, params)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module DataSift
|
2
|
+
class DynamicListReplace < DataSift::ApiResource
|
3
|
+
|
4
|
+
##
|
5
|
+
# Start a new replace list
|
6
|
+
def start (list_id)
|
7
|
+
params = {
|
8
|
+
:list_id => list_id
|
9
|
+
}
|
10
|
+
requires params
|
11
|
+
DataSift.request(:POST, 'list/replace/start', @config, params)
|
12
|
+
end
|
13
|
+
|
14
|
+
##
|
15
|
+
# Commit the replace list
|
16
|
+
def commit (id)
|
17
|
+
params = {
|
18
|
+
:id => id
|
19
|
+
}
|
20
|
+
requires params
|
21
|
+
DataSift.request(:POST, 'list/replace/commit', @config, params)
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Abort the replace list
|
26
|
+
def abort (id)
|
27
|
+
params = {
|
28
|
+
:id => id
|
29
|
+
}
|
30
|
+
requires params
|
31
|
+
DataSift.request(:POST, 'list/replace/abort', @config, params)
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# Add items to the replace list
|
36
|
+
def add (id, items)
|
37
|
+
params = {
|
38
|
+
:id => id,
|
39
|
+
:items => items
|
40
|
+
}
|
41
|
+
requires params
|
42
|
+
DataSift.request(:POST, 'list/replace/add', @config, params)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/historics.rb
CHANGED
@@ -16,6 +16,22 @@ module DataSift
|
|
16
16
|
DataSift.request(:POST, 'historics/prepare', @config, params)
|
17
17
|
end
|
18
18
|
|
19
|
+
# Pause historics query.
|
20
|
+
def pause(id, reason = '')
|
21
|
+
params = {:id => id}
|
22
|
+
requires params
|
23
|
+
params[:reason] = reason
|
24
|
+
DataSift.request(:PUT, 'historics/pause', @config, params)
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Resume historics query.
|
29
|
+
def resume(id)
|
30
|
+
params = {:id => id}
|
31
|
+
requires params
|
32
|
+
DataSift.request(:PUT, 'historics/resume', @config, params)
|
33
|
+
end
|
34
|
+
|
19
35
|
##
|
20
36
|
# Starts historics query.
|
21
37
|
def start(id)
|
@@ -32,6 +48,7 @@ module DataSift
|
|
32
48
|
params[:reason] = reason
|
33
49
|
DataSift.request(:POST, 'historics/stop', @config, params)
|
34
50
|
end
|
51
|
+
##
|
35
52
|
|
36
53
|
##
|
37
54
|
# Check the data coverage in the archive for a specified interval.
|
data/lib/historics_preview.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
module DataSift
|
2
2
|
class HistoricsPreview < DataSift::ApiResource
|
3
3
|
|
4
|
-
def create(hash, parameters, start, end_time = nil)
|
4
|
+
def create(hash, sources, parameters, start, end_time = nil)
|
5
5
|
params = {
|
6
6
|
:hash => hash,
|
7
|
+
:sources => sources,
|
7
8
|
:parameters => parameters,
|
8
9
|
:start => start
|
9
10
|
}
|
data/lib/push.rb
CHANGED
@@ -24,7 +24,6 @@ module DataSift
|
|
24
24
|
DataSift.request(:POST, 'push/create', @config, params)
|
25
25
|
end
|
26
26
|
|
27
|
-
|
28
27
|
##
|
29
28
|
# Update the name or output parameters for an existing subscription
|
30
29
|
def update (params)
|
@@ -36,7 +35,7 @@ module DataSift
|
|
36
35
|
def pause(id)
|
37
36
|
params = {:id => id}
|
38
37
|
requires params
|
39
|
-
DataSift.request(:
|
38
|
+
DataSift.request(:PUT, 'push/pause', @config, params)
|
40
39
|
end
|
41
40
|
|
42
41
|
##
|
@@ -44,7 +43,7 @@ module DataSift
|
|
44
43
|
def resume(id)
|
45
44
|
params = {:id => id}
|
46
45
|
requires params
|
47
|
-
DataSift.request(:
|
46
|
+
DataSift.request(:PUT, 'push/resume', @config, params)
|
48
47
|
end
|
49
48
|
|
50
49
|
##
|
@@ -52,7 +51,7 @@ module DataSift
|
|
52
51
|
def stop(id)
|
53
52
|
params = {:id => id}
|
54
53
|
requires params
|
55
|
-
DataSift.request(:
|
54
|
+
DataSift.request(:PUT, 'push/stop', @config, params)
|
56
55
|
end
|
57
56
|
|
58
57
|
##
|
@@ -65,7 +64,7 @@ module DataSift
|
|
65
64
|
|
66
65
|
##
|
67
66
|
# Retrieve log messages for a specific subscription
|
68
|
-
def
|
67
|
+
def log_for(id, page = 1, per_page = 20, order_by = :request_time, order_dir = :desc)
|
69
68
|
params = {
|
70
69
|
:id => id,
|
71
70
|
:page => page,
|
@@ -78,7 +77,7 @@ module DataSift
|
|
78
77
|
|
79
78
|
##
|
80
79
|
# Retrieve log messages for all subscriptions
|
81
|
-
def
|
80
|
+
def log(page = 1, per_page = 20, order_by = :request_time, order_dir = :desc)
|
82
81
|
params = {
|
83
82
|
:page => page,
|
84
83
|
:per_page => per_page,
|
@@ -90,20 +89,14 @@ module DataSift
|
|
90
89
|
|
91
90
|
##
|
92
91
|
# Get details of the subscription with the given ID
|
93
|
-
def get_by_subscription(id
|
94
|
-
params = {
|
95
|
-
:id => id,
|
96
|
-
:page => page,
|
97
|
-
:per_page => per_page,
|
98
|
-
:order_by => order_by,
|
99
|
-
:order_dir => order_dir
|
100
|
-
}
|
92
|
+
def get_by_subscription(id)
|
93
|
+
params = { :id => id }
|
101
94
|
DataSift.request(:GET, 'push/get', @config, params)
|
102
95
|
end
|
103
96
|
|
104
97
|
##
|
105
98
|
# Get details of the subscription with the given stream ID/hash
|
106
|
-
def get_by_hash(hash, page = 1, per_page = 20, order_by = :
|
99
|
+
def get_by_hash(hash, page = 1, per_page = 20, order_by = :created_at, order_dir = :desc)
|
107
100
|
params = {
|
108
101
|
:hash => hash,
|
109
102
|
:page => page,
|
@@ -116,7 +109,7 @@ module DataSift
|
|
116
109
|
|
117
110
|
##
|
118
111
|
# Get details of the subscription with the given Historics ID
|
119
|
-
def get_by_historics_id(id, page = 1, per_page = 20, order_by = :
|
112
|
+
def get_by_historics_id(id, page = 1, per_page = 20, order_by = :created_at, order_dir = :desc)
|
120
113
|
params = {
|
121
114
|
:historics_id => id,
|
122
115
|
:page => page,
|
@@ -141,7 +134,7 @@ module DataSift
|
|
141
134
|
|
142
135
|
##
|
143
136
|
# Pull data from a 'pull' type Push Subscription
|
144
|
-
def pull(id, size =
|
137
|
+
def pull(id, size = 52428800, cursor = '', callback = nil)
|
145
138
|
params = {
|
146
139
|
:id => id,
|
147
140
|
:size => size,
|