datasift 2.1.1 → 3.0.0.beta

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.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +100 -0
  4. data/Gemfile.lock +32 -0
  5. data/README.md +38 -79
  6. data/VERSION +1 -1
  7. data/datasift.gemspec +21 -24
  8. data/examples/auth.rb +44 -0
  9. data/examples/core_api_eg.rb +46 -0
  10. data/examples/historics_eg.rb +50 -0
  11. data/examples/historics_preview_eg.rb +30 -0
  12. data/examples/live_stream_eg.rb +89 -0
  13. data/examples/managed_source_eg.rb +56 -0
  14. data/examples/pull.rb +44 -0
  15. data/examples/push_eg.rb +56 -0
  16. data/lib/api/api_resource.rb +23 -0
  17. data/lib/datasift.rb +287 -14
  18. data/lib/errors.rb +59 -0
  19. data/lib/historics.rb +76 -0
  20. data/lib/historics_preview.rb +20 -0
  21. data/lib/live_stream.rb +53 -0
  22. data/lib/managed_source.rb +57 -0
  23. data/lib/push.rb +156 -0
  24. data/tests/core_api_test.rb +42 -0
  25. metadata +51 -73
  26. data/Rakefile +0 -34
  27. data/config.yml +0 -2
  28. data/examples/consume-stream.rb +0 -63
  29. data/examples/deletes.rb +0 -52
  30. data/examples/dpu.rb +0 -115
  31. data/examples/football-buffered.rb +0 -51
  32. data/examples/football.rb +0 -53
  33. data/examples/historics.sh +0 -2
  34. data/examples/historics/create-from-csdl.rb +0 -71
  35. data/examples/historics/create-from-hash.rb +0 -65
  36. data/examples/historics/delete.rb +0 -30
  37. data/examples/historics/env.rb +0 -37
  38. data/examples/historics/list.rb +0 -30
  39. data/examples/historics/start.rb +0 -30
  40. data/examples/historics/stop.rb +0 -30
  41. data/examples/historics/view.rb +0 -28
  42. data/examples/push.sh +0 -2
  43. data/examples/push/delete.rb +0 -33
  44. data/examples/push/env.rb +0 -53
  45. data/examples/push/list.rb +0 -30
  46. data/examples/push/pause.rb +0 -33
  47. data/examples/push/push-from-hash.rb +0 -72
  48. data/examples/push/push-historic-from-csdl.rb +0 -98
  49. data/examples/push/push-stream-from-csdl.rb +0 -70
  50. data/examples/push/resume.rb +0 -33
  51. data/examples/push/stop.rb +0 -33
  52. data/examples/push/view-log.rb +0 -45
  53. data/examples/push/view.rb +0 -31
  54. data/examples/twitter-track.rb +0 -61
  55. data/lib/DataSift/apiclient.rb +0 -73
  56. data/lib/DataSift/definition.rb +0 -202
  57. data/lib/DataSift/exceptions.rb +0 -33
  58. data/lib/DataSift/historic.rb +0 -316
  59. data/lib/DataSift/managed_source.rb +0 -263
  60. data/lib/DataSift/mockapiclient.rb +0 -44
  61. data/lib/DataSift/push_definition.rb +0 -115
  62. data/lib/DataSift/push_subscription.rb +0 -330
  63. data/lib/DataSift/stream_consumer.rb +0 -166
  64. data/lib/DataSift/stream_consumer_http.rb +0 -188
  65. data/lib/DataSift/user.rb +0 -311
  66. data/test/helper.rb +0 -95
  67. data/test/test_definition.rb +0 -273
  68. data/test/test_historics.rb +0 -233
  69. data/test/test_pushdefinition.rb +0 -92
  70. data/test/test_pushsubscription.rb +0 -17
  71. data/test/test_user.rb +0 -130
  72. data/test/testdata.yml +0 -30
@@ -1,53 +0,0 @@
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
@@ -1,30 +0,0 @@
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
@@ -1,33 +0,0 @@
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
@@ -1,72 +0,0 @@
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
@@ -1,98 +0,0 @@
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
@@ -1,70 +0,0 @@
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.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 ' 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.rb 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
@@ -1,33 +0,0 @@
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
@@ -1,33 +0,0 @@
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
@@ -1,45 +0,0 @@
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