datasift 1.5.0 → 2.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/.gitignore +1 -0
- data/LICENSE +1 -1
- data/README.md +6 -4
- data/VERSION +1 -1
- data/config.yml +2 -2
- data/datasift.gemspec +11 -11
- data/examples/historics.sh +2 -0
- data/examples/historics/create-from-csdl.rb +71 -0
- data/examples/historics/create-from-hash.rb +65 -0
- data/examples/historics/delete.rb +30 -0
- data/examples/historics/env.rb +37 -0
- data/examples/historics/list.rb +30 -0
- data/examples/historics/start.rb +30 -0
- data/examples/historics/stop.rb +30 -0
- data/examples/historics/view.rb +28 -0
- data/examples/push.sh +2 -0
- data/examples/push/delete.rb +33 -0
- data/examples/push/env.rb +53 -0
- data/examples/push/list.rb +30 -0
- data/examples/push/pause.rb +33 -0
- data/examples/push/push-from-hash.rb +72 -0
- data/examples/push/push-historic-from-csdl.rb +98 -0
- data/examples/push/push-stream-from-csdl.rb +70 -0
- data/examples/push/resume.rb +33 -0
- data/examples/push/stop.rb +33 -0
- data/examples/push/view-log.rb +45 -0
- data/examples/push/view.rb +31 -0
- data/lib/DataSift/apiclient.rb +20 -25
- data/lib/DataSift/definition.rb +97 -57
- data/lib/DataSift/exceptions.rb +25 -8
- data/lib/DataSift/historic.rb +321 -0
- data/lib/DataSift/mockapiclient.rb +23 -34
- data/lib/DataSift/push_definition.rb +115 -0
- data/lib/DataSift/push_subscription.rb +330 -0
- data/lib/DataSift/stream_consumer.rb +53 -70
- data/lib/DataSift/stream_consumer_http.rb +11 -15
- data/lib/DataSift/user.rb +189 -61
- data/lib/datasift.rb +5 -10
- data/test/helper.rb +80 -6
- data/test/test_definition.rb +0 -9
- data/test/test_historics.rb +233 -0
- data/test/test_pushdefinition.rb +92 -0
- data/test/test_pushsubscription.rb +17 -0
- data/test/test_user.rb +0 -6
- data/test/testdata.yml +26 -0
- metadata +38 -23
- data/test/test_live_api.rb +0 -100
@@ -0,0 +1,53 @@
|
|
1
|
+
# This class is used by the Push examples to remove the noise of
|
2
|
+
# dealing with command line arguments.
|
3
|
+
#
|
4
|
+
|
5
|
+
# Include the DataSift library
|
6
|
+
require File.dirname(__FILE__) + '/../../lib/datasift'
|
7
|
+
|
8
|
+
class Env
|
9
|
+
attr_reader :user, :args
|
10
|
+
|
11
|
+
def initialize(args = false)
|
12
|
+
if args === false
|
13
|
+
args = ARGV
|
14
|
+
end
|
15
|
+
|
16
|
+
abort('Please specify your DataSift username and API key as the first two command line arguments!') unless args.size() >= 2
|
17
|
+
|
18
|
+
username = args.shift
|
19
|
+
api_key = args.shift
|
20
|
+
@user = DataSift::User.new(username, api_key)
|
21
|
+
|
22
|
+
@args = args
|
23
|
+
end
|
24
|
+
|
25
|
+
def displaySubscriptionDetails(subscription)
|
26
|
+
puts 'ID: ' + subscription.id
|
27
|
+
puts 'Name: ' + subscription.name
|
28
|
+
puts 'Status: ' + subscription.status
|
29
|
+
puts 'Created at: ' + subscription.created_at.strftime('%Y-%m-%d %H:%M:%S')
|
30
|
+
puts 'Last request: ' + (subscription.last_request.nil? ? 'None' : subscription.last_request.strftime('%Y-%m-%d %H:%M:%S'))
|
31
|
+
puts 'Last success: ' + (subscription.last_success.nil? ? 'None' : subscription.last_success.strftime('%Y-%m-%d %H:%M:%S'))
|
32
|
+
puts 'Output type: ' + subscription.output_type
|
33
|
+
|
34
|
+
puts 'Output Params:'
|
35
|
+
subscription.output_params.each do |k,v|
|
36
|
+
puts ' ' + k + ' = ' + String(v)
|
37
|
+
end
|
38
|
+
puts '--'
|
39
|
+
end
|
40
|
+
|
41
|
+
def displayHistoricDetails(historic)
|
42
|
+
puts 'Playback ID: ' + historic.hash
|
43
|
+
puts 'Stream hash: ' + historic.stream_hash
|
44
|
+
puts 'Name: ' + historic.name
|
45
|
+
puts 'Start time: ' + historic.start_date.strftime('%Y-%m-%d %H:%M:%S')
|
46
|
+
puts 'End time: ' + historic.end_date.strftime('%Y-%m-%d %H:%M:%S')
|
47
|
+
puts 'Sources: ' + historic.sources.join(', ')
|
48
|
+
puts 'Sample: ' + String(historic.sample)
|
49
|
+
puts 'Created at: ' + (historic.created_at.nil? ? 'None' : historic.created_at.strftime('%Y-%m-%d %H:%M:%S'))
|
50
|
+
puts 'Status: ' + historic.status
|
51
|
+
puts '--'
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# This script lists Push subscription in your account.
|
2
|
+
#
|
3
|
+
# NB: Most of the error handling (exception catching) has been removed for
|
4
|
+
# the sake of simplicity. Nearly everything in this library may throw
|
5
|
+
# exceptions, and production code should catch them. See the documentation
|
6
|
+
# for full details.
|
7
|
+
#
|
8
|
+
|
9
|
+
# Include the shared Env class
|
10
|
+
require File.dirname(__FILE__) + '/env'
|
11
|
+
|
12
|
+
# Create the env object. This reads the command line arguments, creates the
|
13
|
+
# user object, and provides access to both along with helper functions.
|
14
|
+
env = Env.new()
|
15
|
+
|
16
|
+
begin
|
17
|
+
subscriptions = env.user.listPushSubscriptions()
|
18
|
+
|
19
|
+
if subscriptions['subscriptions'].size() == 0
|
20
|
+
puts 'No Push subscriptions exist in your account.'
|
21
|
+
else
|
22
|
+
for subscription in subscriptions['subscriptions']
|
23
|
+
env.displaySubscriptionDetails(subscription)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
puts 'Rate limit remainining: ' + String(env.user.rate_limit_remaining)
|
28
|
+
rescue DataSift::DataSiftError => err
|
29
|
+
puts 'ERR: [' + err.class.name + '] ' + err.message
|
30
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# This script pauses Push subscriptions in your account.
|
2
|
+
#
|
3
|
+
# NB: Most of the error handling (exception catching) has been removed for
|
4
|
+
# the sake of simplicity. Nearly everything in this library may throw
|
5
|
+
# exceptions, and production code should catch them. See the documentation
|
6
|
+
# for full details.
|
7
|
+
#
|
8
|
+
|
9
|
+
# Include the shared Env class
|
10
|
+
require File.dirname(__FILE__) + '/env'
|
11
|
+
|
12
|
+
# Create the env object. This reads the command line arguments, creates the
|
13
|
+
# user object, and provides access to both along with helper functions.
|
14
|
+
env = Env.new()
|
15
|
+
|
16
|
+
# Make sure we have something to do
|
17
|
+
abort('Please specify one or more subscription IDs') unless env.args.size() > 0
|
18
|
+
|
19
|
+
for sub_id in env.args
|
20
|
+
begin
|
21
|
+
sub = env.user.getPushSubscription(sub_id)
|
22
|
+
print 'Pausing ' + sub_id + ', "' + sub.name + '"...'
|
23
|
+
sub.pause()
|
24
|
+
rescue DataSift::DataSiftError => err
|
25
|
+
puts 'ERR: [' + err.class.name + '] ' + err.message
|
26
|
+
else
|
27
|
+
puts 'done'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
if env.user.rate_limit_remaining != -1
|
32
|
+
puts 'Rate limit remainining: ' + String(env.user.rate_limit_remaining)
|
33
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# This script creates a Push subscription for a stream hash or Historics
|
2
|
+
# playback ID.
|
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
|
+
# Include the shared Env class
|
11
|
+
require File.dirname(__FILE__) + '/env'
|
12
|
+
|
13
|
+
# Display usage information, with an error message if provided.
|
14
|
+
def usage(message = '', end_of_story = true)
|
15
|
+
puts message + '\n' unless message.length() == 0
|
16
|
+
puts
|
17
|
+
puts 'Usage: push-from-hash.rb <username> <api_key> \\'
|
18
|
+
puts ' <output_type> <hash_type> <hash> <name> ...'
|
19
|
+
puts
|
20
|
+
puts 'Where: output_type = http (currently only http is supported)'
|
21
|
+
puts ' hash_type = stream | historic'
|
22
|
+
puts ' hash = the hash'
|
23
|
+
puts ' name = a friendly name for the subscription'
|
24
|
+
puts ' key=val = output_type-specific arguments'
|
25
|
+
puts
|
26
|
+
puts 'Example'
|
27
|
+
puts ' push-from-hash.rb http stream <hash> PushName delivery_frequency=10 \\'
|
28
|
+
puts ' url=http://www.example.com/push_endpoint auth.type=none'
|
29
|
+
puts
|
30
|
+
exit 1 unless not end_of_story
|
31
|
+
end
|
32
|
+
|
33
|
+
# Create the env object. This reads the command line arguments, creates the
|
34
|
+
# user object, and provides access to both along with helper functions.
|
35
|
+
env = Env.new()
|
36
|
+
|
37
|
+
# Check that we have enough arguments
|
38
|
+
usage() if env.args.size() < 4
|
39
|
+
|
40
|
+
# Read the arguments
|
41
|
+
output_type = env.args.shift
|
42
|
+
hash_type = env.args.shift
|
43
|
+
hash = env.args.shift
|
44
|
+
name = env.args.shift
|
45
|
+
|
46
|
+
begin
|
47
|
+
# Create the Push definition
|
48
|
+
pushdef = env.user.createPushDefinition()
|
49
|
+
pushdef.output_type = output_type
|
50
|
+
|
51
|
+
# Now add the output_type-specific args from the command line
|
52
|
+
while env.args.size() > 0
|
53
|
+
k, v = env.args.shift.split('=', 2)
|
54
|
+
pushdef.output_params[k] = v
|
55
|
+
end
|
56
|
+
|
57
|
+
# Subscribe the hash to the Push endpoint
|
58
|
+
if hash_type == 'stream'
|
59
|
+
sub = pushdef.subscribeStreamHash(hash, name)
|
60
|
+
elsif hash_type == 'historic'
|
61
|
+
sub = pushdef.subscribeHistoricPlaybackId(hash, name)
|
62
|
+
else
|
63
|
+
usage('Invalid hash_type: ' + hash_type)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Display the details of the new subscription
|
67
|
+
env.displaySubscriptionDetails(sub)
|
68
|
+
|
69
|
+
puts 'Rate limit remainining: ' + String(env.user.rate_limit_remaining)
|
70
|
+
rescue DataSift::DataSiftError => err
|
71
|
+
puts 'ERR: [' + err.class.name + '] ' + err.message
|
72
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# This script creates a Push subscription for a Historics query from the
|
2
|
+
# provided CSDL.
|
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
|
+
# Include the shared Env class
|
11
|
+
require File.dirname(__FILE__) + '/env'
|
12
|
+
|
13
|
+
# Display usage information, with an error message if provided.
|
14
|
+
def usage(message = '', end_of_story = true)
|
15
|
+
puts message + '\n' unless message.length() == 0
|
16
|
+
puts
|
17
|
+
puts 'Usage: push-historic-from-csdl.rb <username> <api_key> \\'
|
18
|
+
puts ' <csdl_filename> <output_type> <name> ...'
|
19
|
+
puts
|
20
|
+
puts 'Where: csdl_filename = a file containing the CSDL'
|
21
|
+
puts ' start_date = Historics query start date (yyyymmddhhmmss)'
|
22
|
+
puts ' end_date = Historics query end date (yyyymmddhhmmss)'
|
23
|
+
puts ' sources = comma separated list of sources (twitter,digg,etc)'
|
24
|
+
puts ' sample = percentage of matches to return'
|
25
|
+
puts ' output_type = see http://dev.datasift.com/docs/push/connectors'
|
26
|
+
puts ' name = a friendly name for the subscription'
|
27
|
+
puts ' key=val = output_type-specific arguments'
|
28
|
+
puts
|
29
|
+
puts 'Example'
|
30
|
+
puts ' push-historic-from-csdl.rb csdl.txt csdl.txt 20120101000000 \\'
|
31
|
+
puts ' 20120101235959 twitter 100 http PushName delivery_frequency=10 \\'
|
32
|
+
puts ' url=http://www.example.com/push_endpoint auth.type=none'
|
33
|
+
puts
|
34
|
+
exit 1 unless not end_of_story
|
35
|
+
end
|
36
|
+
|
37
|
+
# Create the env object. This reads the command line arguments, creates the
|
38
|
+
# user object, and provides access to both along with helper functions.
|
39
|
+
env = Env.new()
|
40
|
+
|
41
|
+
# Check that we have enough arguments
|
42
|
+
usage() if env.args.size() < 7
|
43
|
+
|
44
|
+
# Read the arguments
|
45
|
+
csdl_filename = env.args.shift
|
46
|
+
start_date = env.args.shift
|
47
|
+
end_date = env.args.shift
|
48
|
+
sources = env.args.shift
|
49
|
+
sample = env.args.shift
|
50
|
+
output_type = env.args.shift
|
51
|
+
name = env.args.shift
|
52
|
+
|
53
|
+
# Parse the dates
|
54
|
+
date_format = '%Y%m%d%H%M%S'
|
55
|
+
start_date = DateTime.strptime(start_date, date_format)
|
56
|
+
end_date = DateTime.strptime(end_date, date_format)
|
57
|
+
|
58
|
+
# Read the CSDL
|
59
|
+
csdl = File.open(csdl_filename, 'r').read
|
60
|
+
|
61
|
+
begin
|
62
|
+
# Create the Definition object
|
63
|
+
definition = env.user.createDefinition(csdl)
|
64
|
+
|
65
|
+
# Create the Historics query
|
66
|
+
historic = definition.createHistoric(start_date, end_date, sources.split(','), sample, name + '_historic')
|
67
|
+
|
68
|
+
# Display the details of the Historics query
|
69
|
+
puts 'Historics query:'
|
70
|
+
env.displayHistoricDetails(historic)
|
71
|
+
|
72
|
+
# Create the Push definition
|
73
|
+
pushdef = env.user.createPushDefinition()
|
74
|
+
pushdef.output_type = output_type
|
75
|
+
|
76
|
+
# Now add the output_type-specific args from the command line
|
77
|
+
while env.args.size() > 0
|
78
|
+
k, v = env.args.shift.split('=', 2)
|
79
|
+
pushdef.output_params[k] = v
|
80
|
+
end
|
81
|
+
|
82
|
+
# Subscribe the Push endpoint to the Historics query
|
83
|
+
sub = pushdef.subscribeHistoric(historic, name)
|
84
|
+
|
85
|
+
# Start the Historics query
|
86
|
+
print 'Starting Historits query...'
|
87
|
+
historic.start()
|
88
|
+
puts 'done'
|
89
|
+
puts '--'
|
90
|
+
|
91
|
+
# Display the details of the new subscription
|
92
|
+
puts 'Push subscription:'
|
93
|
+
env.displaySubscriptionDetails(sub)
|
94
|
+
|
95
|
+
puts 'Rate limit remainining: ' + String(env.user.rate_limit_remaining)
|
96
|
+
rescue DataSift::DataSiftError => err
|
97
|
+
puts 'ERR: [' + err.class.name + '] ' + err.message
|
98
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# This script creates a Push subscription for a live stream from the provided
|
2
|
+
# CSDL.
|
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
|
+
# Include the shared Env class
|
11
|
+
require File.dirname(__FILE__) + '/env'
|
12
|
+
|
13
|
+
# Display usage information, with an error message if provided.
|
14
|
+
def usage(message = '', end_of_story = true)
|
15
|
+
puts message + '\n' unless message.length() == 0
|
16
|
+
puts
|
17
|
+
puts 'Usage: push-stream-from-csdl.py <username> <api_key> \\'
|
18
|
+
puts ' <csdl_filename> <output_type> <name> ...'
|
19
|
+
puts
|
20
|
+
puts 'Where: csdl_filename = a file containing the CSDL'
|
21
|
+
puts ' output_type = see http://dev.datasift.com/docs/push/connectors'
|
22
|
+
puts ' name = a friendly name for the subscription'
|
23
|
+
puts ' key=val = output_type-specific arguments'
|
24
|
+
puts
|
25
|
+
puts 'Example'
|
26
|
+
puts ' push-stream-from-csdl.py csdl.txt http PushName delivery_frequency=10 \\'
|
27
|
+
puts ' url=http://www.example.com/push_endpoint auth.type=none'
|
28
|
+
puts
|
29
|
+
exit 1 unless not end_of_story
|
30
|
+
end
|
31
|
+
|
32
|
+
# Create the env object. This reads the command line arguments, creates the
|
33
|
+
# user object, and provides access to both along with helper functions.
|
34
|
+
env = Env.new()
|
35
|
+
|
36
|
+
# Check that we have enough arguments
|
37
|
+
usage() if env.args.size() < 3
|
38
|
+
|
39
|
+
# Read the arguments
|
40
|
+
csdl_filename = env.args.shift
|
41
|
+
output_type = env.args.shift
|
42
|
+
name = env.args.shift
|
43
|
+
|
44
|
+
# Read the CSDL
|
45
|
+
csdl = File.open(csdl_filename, 'r').read
|
46
|
+
|
47
|
+
begin
|
48
|
+
# Create the Definition object
|
49
|
+
definition = env.user.createDefinition(csdl)
|
50
|
+
|
51
|
+
# Create the Push definition
|
52
|
+
pushdef = env.user.createPushDefinition()
|
53
|
+
pushdef.output_type = output_type
|
54
|
+
|
55
|
+
# Now add the output_type-specific args from the command line
|
56
|
+
while env.args.size() > 0
|
57
|
+
k, v = env.args.shift.split('=', 2)
|
58
|
+
pushdef.output_params[k] = v
|
59
|
+
end
|
60
|
+
|
61
|
+
# Subscribe the Push endpoint to the Definition
|
62
|
+
sub = pushdef.subscribeDefinition(definition, name)
|
63
|
+
|
64
|
+
# Display the details of the new subscription
|
65
|
+
env.displaySubscriptionDetails(sub)
|
66
|
+
|
67
|
+
puts 'Rate limit remainining: ' + String(env.user.rate_limit_remaining)
|
68
|
+
rescue DataSift::DataSiftError => err
|
69
|
+
puts 'ERR: [' + err.class.name + '] ' + err.message
|
70
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# This script resumes Push subscriptions in your account.
|
2
|
+
#
|
3
|
+
# NB: Most of the error handling (exception catching) has been removed for
|
4
|
+
# the sake of simplicity. Nearly everything in this library may throw
|
5
|
+
# exceptions, and production code should catch them. See the documentation
|
6
|
+
# for full details.
|
7
|
+
#
|
8
|
+
|
9
|
+
# Include the shared Env class
|
10
|
+
require File.dirname(__FILE__) + '/env'
|
11
|
+
|
12
|
+
# Create the env object. This reads the command line arguments, creates the
|
13
|
+
# user object, and provides access to both along with helper functions.
|
14
|
+
env = Env.new()
|
15
|
+
|
16
|
+
# Make sure we have something to do
|
17
|
+
abort('Please specify one or more subscription IDs') unless env.args.size() > 0
|
18
|
+
|
19
|
+
for sub_id in env.args
|
20
|
+
begin
|
21
|
+
sub = env.user.getPushSubscription(sub_id)
|
22
|
+
print 'Resuming ' + sub_id + ', "' + sub.name + '"...'
|
23
|
+
sub.resume()
|
24
|
+
rescue DataSift::DataSiftError => err
|
25
|
+
puts 'ERR: [' + err.class.name + '] ' + err.message
|
26
|
+
else
|
27
|
+
puts 'done'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
if env.user.rate_limit_remaining != -1
|
32
|
+
puts 'Rate limit remainining: ' + String(env.user.rate_limit_remaining)
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# This script stops Push subscriptions in your account.
|
2
|
+
#
|
3
|
+
# NB: Most of the error handling (exception catching) has been removed for
|
4
|
+
# the sake of simplicity. Nearly everything in this library may throw
|
5
|
+
# exceptions, and production code should catch them. See the documentation
|
6
|
+
# for full details.
|
7
|
+
#
|
8
|
+
|
9
|
+
# Include the shared Env class
|
10
|
+
require File.dirname(__FILE__) + '/env'
|
11
|
+
|
12
|
+
# Create the env object. This reads the command line arguments, creates the
|
13
|
+
# user object, and provides access to both along with helper functions.
|
14
|
+
env = Env.new()
|
15
|
+
|
16
|
+
# Make sure we have something to do
|
17
|
+
abort('Please specify one or more subscription IDs') unless env.args.size() > 0
|
18
|
+
|
19
|
+
for sub_id in env.args
|
20
|
+
begin
|
21
|
+
sub = env.user.getPushSubscription(sub_id)
|
22
|
+
print 'Stopping ' + sub_id + ', "' + sub.name + '"...'
|
23
|
+
sub.stop()
|
24
|
+
rescue DataSift::DataSiftError => err
|
25
|
+
puts 'ERR: [' + err.class.name + '] ' + err.message
|
26
|
+
else
|
27
|
+
puts 'done'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
if env.user.rate_limit_remaining != -1
|
32
|
+
puts 'Rate limit remainining: ' + String(env.user.rate_limit_remaining)
|
33
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# This script resumes Push subscriptions in your account.
|
2
|
+
#
|
3
|
+
# NB: Most of the error handling (exception catching) has been removed for
|
4
|
+
# the sake of simplicity. Nearly everything in this library may throw
|
5
|
+
# exceptions, and production code should catch them. See the documentation
|
6
|
+
# for full details.
|
7
|
+
#
|
8
|
+
|
9
|
+
# Include the shared Env class
|
10
|
+
require File.dirname(__FILE__) + '/env'
|
11
|
+
|
12
|
+
# Create the env object. This reads the command line arguments, creates the
|
13
|
+
# user object, and provides access to both along with helper functions.
|
14
|
+
env = Env.new()
|
15
|
+
|
16
|
+
# Make sure we have 0 or 1 arguments
|
17
|
+
abort('Please specify one or more subscription IDs') unless env.args.size() < 2
|
18
|
+
|
19
|
+
begin
|
20
|
+
# Get the log
|
21
|
+
arg_count = env.args.size()
|
22
|
+
if arg_count == 0
|
23
|
+
log = env.user.getPushSubscriptionLog()
|
24
|
+
else
|
25
|
+
subscription_id = env.args[0]
|
26
|
+
log = env.user.getPushSubscriptionLog(subscription_id)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Make sure we have some log entries
|
30
|
+
abort('No log entries found.') unless log['count'] > 0
|
31
|
+
|
32
|
+
# Display the log entries in reverse order
|
33
|
+
log['log_entries'].reverse().each do |log_entry|
|
34
|
+
print (DateTime.strptime(String(log_entry['request_time']), '%s')).strftime('%Y-%m-%d %H:%M:%S') + ' '
|
35
|
+
print '[' + log_entry['subscription_id'] + '] ' if arg_count == 0
|
36
|
+
print 'Success ' if log_entry['success']
|
37
|
+
puts log_entry['message']
|
38
|
+
end
|
39
|
+
rescue DataSift::DataSiftError => err
|
40
|
+
puts 'ERR: [' + err.class.name + '] ' + err.message
|
41
|
+
end
|
42
|
+
|
43
|
+
if env.user.rate_limit_remaining != -1
|
44
|
+
puts 'Rate limit remainining: ' + String(env.user.rate_limit_remaining)
|
45
|
+
end
|