datasift 3.7.2 → 3.8.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.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/datasift.gemspec +6 -3
  4. data/lib/api/api_resource.rb +1 -1
  5. data/lib/datasift.rb +53 -16
  6. data/lib/errors.rb +8 -0
  7. data/lib/live_stream.rb +7 -7
  8. data/lib/pylon.rb +59 -26
  9. data/lib/tasks.rb +51 -0
  10. data/lib/version.rb +3 -0
  11. metadata +5 -83
  12. data/.gitignore +0 -12
  13. data/.rubocop.yml +0 -12
  14. data/.rubocop_todo.yml +0 -497
  15. data/.travis.yml +0 -17
  16. data/Gemfile +0 -15
  17. data/LICENSE +0 -19
  18. data/MIGRATING_TO_V.3.0.0.md +0 -262
  19. data/Rakefile +0 -10
  20. data/VERSION +0 -1
  21. data/examples/account_eg.rb +0 -33
  22. data/examples/account_identity_eg.rb +0 -50
  23. data/examples/account_identity_limit_eg.rb +0 -72
  24. data/examples/account_identity_token_eg.rb +0 -73
  25. data/examples/auth.rb +0 -55
  26. data/examples/cli.sh +0 -155
  27. data/examples/core_api_eg.rb +0 -50
  28. data/examples/historics_eg.rb +0 -66
  29. data/examples/historics_preview_eg.rb +0 -31
  30. data/examples/ingestion/twitter_gnip_batch_eg.rb +0 -61
  31. data/examples/live_stream_eg.rb +0 -92
  32. data/examples/managed_source_fb_eg.rb +0 -129
  33. data/examples/managed_source_ig_eg.rb +0 -126
  34. data/examples/pull.rb +0 -47
  35. data/examples/push_eg.rb +0 -51
  36. data/examples/pylon/pylon_api_v1.2_eg.rb +0 -166
  37. data/examples/pylon/pylon_api_v1.3_eg.rb +0 -201
  38. data/test/datasift/account/account_api_test.rb +0 -35
  39. data/test/datasift/core_api_test.rb +0 -179
  40. data/test/datasift/historics_preview_api_test.rb +0 -56
  41. data/test/datasift/odp/batch_upload_test.rb +0 -52
  42. data/test/datasift/push_api_test.rb +0 -238
  43. data/test/fixtures/cassettes/account/usage/default.json +0 -1
  44. data/test/fixtures/cassettes/account/usage/invalid.json +0 -1
  45. data/test/fixtures/cassettes/account/usage/valid_params.json +0 -1
  46. data/test/fixtures/cassettes/core/after_historic_dpu.json +0 -1
  47. data/test/fixtures/cassettes/core/balance_get.json +0 -1
  48. data/test/fixtures/cassettes/core/before_dpu.json +0 -1
  49. data/test/fixtures/cassettes/core/before_historic_dpu.json +0 -1
  50. data/test/fixtures/cassettes/core/compile_success.json +0 -1
  51. data/test/fixtures/cassettes/core/dpu_get_cost.json +0 -1
  52. data/test/fixtures/cassettes/core/dpu_throw_badrequest.json +0 -1
  53. data/test/fixtures/cassettes/core/historic_dpu.json +0 -1
  54. data/test/fixtures/cassettes/core/usage_success.json +0 -1
  55. data/test/fixtures/cassettes/core/validate_invalid_hash.json +0 -1
  56. data/test/fixtures/cassettes/core/validate_success_bool.json +0 -1
  57. data/test/fixtures/cassettes/core/validate_success_hash.json +0 -1
  58. data/test/fixtures/cassettes/odp/batch/after_upload.json +0 -1
  59. data/test/fixtures/cassettes/odp/batch/before_upload.json +0 -1
  60. data/test/fixtures/cassettes/odp/batch/upload_failure_no_source.json +0 -1
  61. data/test/fixtures/cassettes/odp/batch/upload_success.json +0 -1
  62. data/test/fixtures/cassettes/preview/before_preview_create.json +0 -1
  63. data/test/fixtures/cassettes/preview/before_preview_get.json +0 -1
  64. data/test/fixtures/cassettes/preview/preview_create_success.json +0 -1
  65. data/test/fixtures/cassettes/preview/preview_get_success.json +0 -1
  66. data/test/fixtures/cassettes/push/after_push_create.json +0 -1
  67. data/test/fixtures/cassettes/push/after_push_get.json +0 -1
  68. data/test/fixtures/cassettes/push/after_push_log.json +0 -1
  69. data/test/fixtures/cassettes/push/after_push_pause.json +0 -1
  70. data/test/fixtures/cassettes/push/after_push_resume.json +0 -1
  71. data/test/fixtures/cassettes/push/after_push_stop.json +0 -1
  72. data/test/fixtures/cassettes/push/after_push_update.json +0 -1
  73. data/test/fixtures/cassettes/push/before_push_create.json +0 -1
  74. data/test/fixtures/cassettes/push/before_push_delete.json +0 -1
  75. data/test/fixtures/cassettes/push/before_push_get.json +0 -1
  76. data/test/fixtures/cassettes/push/before_push_log.json +0 -1
  77. data/test/fixtures/cassettes/push/before_push_pause.json +0 -1
  78. data/test/fixtures/cassettes/push/before_push_resume.json +0 -1
  79. data/test/fixtures/cassettes/push/before_push_stop.json +0 -1
  80. data/test/fixtures/cassettes/push/before_push_update.json +0 -1
  81. data/test/fixtures/cassettes/push/push_create.json +0 -1
  82. data/test/fixtures/cassettes/push/push_delete.json +0 -1
  83. data/test/fixtures/cassettes/push/push_get_by_id.json +0 -1
  84. data/test/fixtures/cassettes/push/push_log_with_id.json +0 -1
  85. data/test/fixtures/cassettes/push/push_pause.json +0 -1
  86. data/test/fixtures/cassettes/push/push_resume.json +0 -1
  87. data/test/fixtures/cassettes/push/push_stop.json +0 -1
  88. data/test/fixtures/cassettes/push/push_update.json +0 -1
  89. data/test/fixtures/cassettes/push/push_validate.json +0 -1
  90. data/test/fixtures/data/fake_gnip_tweets.json +0 -10
  91. data/test/test_helper.rb +0 -49
@@ -1,73 +0,0 @@
1
- require './auth'
2
- class AccountIdentityTokenEg < DataSiftExample
3
- def initialize
4
- super
5
- @datasift = DataSift::Client.new(@config)
6
- run
7
- end
8
-
9
- def run
10
- begin
11
- puts "Create a new identity to create tokens for"
12
- identity = @datasift.account_identity.create(
13
- "Ruby Identity for Tokena",
14
- "active",
15
- false
16
- )
17
- identity_id = identity[:data][:id]
18
- puts identity[:data].to_json
19
-
20
- puts "\nCreate a Token for our Identity"
21
- puts @datasift.account_identity_token.create(
22
- identity_id,
23
- 'facebook',
24
- 'YOUR_TOKEN'
25
- )[:data].to_json
26
-
27
- puts "\nList all existing Tokens for this Identity"
28
- puts @datasift.account_identity_token.list(
29
- identity_id
30
- )[:data].to_json
31
-
32
- puts "\nGet existing Token by Identity and Service"
33
- puts @datasift.account_identity_token.get(
34
- identity_id,
35
- 'facebook'
36
- )[:data].to_json
37
-
38
- puts "\nUpdate a Token for a given Identity"
39
- puts @datasift.account_identity_token.update(
40
- identity_id,
41
- 'facebook',
42
- 'YOUR_NEW_TOKEN'
43
- )[:data].to_json
44
-
45
- puts "\nDelete an Token for a given Identity and Service"
46
- puts @datasift.account_identity_token.delete(
47
- identity_id,
48
- 'facebook'
49
- )[:data].to_json
50
-
51
- puts "\nCleanup and remove the Identity"
52
- @datasift.account_identity.delete(identity_id)
53
-
54
- rescue DataSiftError => dse
55
- puts dse.inspect
56
- # Then match specific error to take action;
57
- # All errors thrown by the client extend DataSiftError
58
- case dse
59
- when ConnectionError
60
- # some connection error
61
- when AuthError
62
- when BadRequestError
63
- puts '[WARNING] You will need to use a valid token to run through this example'
64
- else
65
- # do something else...
66
- end
67
- puts "\nCleanup and remove the Identity"
68
- @datasift.account_identity.delete(identity_id)
69
- end
70
- end
71
- end
72
-
73
- AccountIdentityTokenEg.new
@@ -1,55 +0,0 @@
1
- class DataSiftExample
2
- require 'datasift'
3
-
4
- def initialize
5
- @config = {
6
- username: 'DATASIFT_USERNAME',
7
- api_key: 'DATASIFT_API_KEY',
8
- api_version: 'v1.3'
9
- }
10
- @params = {
11
- output_type: 's3',
12
- output_params: {
13
- bucket: 'YOUR_BUCKET_NAME',
14
- directory: 'ruby',
15
- acl: 'private',
16
- delivery_frequency: 0,
17
- max_size: 104857600,
18
- file_prefix: 'DataSift',
19
- auth: {
20
- access_key: 'ADD_YOUR_ACCESS_KEY',
21
- secret_key: 'ADD_YOUR_SECRET_KEY',
22
- }
23
- }
24
- }
25
- @pull_params = {
26
- output_type: 'pull',
27
- output_params: {
28
- max_size: 52428800
29
- }
30
- }
31
- @datasift = DataSift::Client.new(@config)
32
- end
33
-
34
- attr_reader :datasift, :params
35
-
36
- def create_push(hash, is_historics_id = false)
37
- create_params = @params.merge ({
38
- # Hash or historics_id can be used, but not both
39
- name: 'My awesome push subscription',
40
- initial_status: 'active', # or 'paused' or 'waiting_for_start'
41
- })
42
- if is_historics_id
43
- create_params.merge!(historics_id: hash)
44
- else
45
- # Start and end are not valid for historics
46
- create_params.merge!(
47
- hash: hash,
48
- start: Time.now.to_i,
49
- end: Time.now.to_i + 320
50
- )
51
- end
52
- puts 'Creating subscription'
53
- @datasift.push.create create_params
54
- end
55
- end
@@ -1,155 +0,0 @@
1
- #!/bin/bash
2
- command -v jq >/dev/null 2>&1 || { echo >&2 "jq command must be available. See http://stedolan.github.io/jq/. Aborting."; exit 1; }
3
-
4
- set -e
5
-
6
- DEFAULT_API='api.datasift.com'
7
-
8
- CC=${1:$CC}
9
- DU=${2:-$DU}
10
- DK=${3:-$DK}
11
- API=${4:-$DEFAULT_API}
12
-
13
- function ds(){
14
- ${CC} -a ${DU} ${DK} --u ${API} "$@" #| jq .
15
- }
16
-
17
- # core API - validate our hash, compile it, check our usage, dpu and balance
18
- echo 'Validating CSDL'
19
- csdl='interaction.content contains "music"'
20
- valid=$(ds -e core -c validate -p csdl "$csdl" | jq .status)
21
-
22
- if [ ${valid} != 200 ]; then
23
- echo "Validating CSDL failed"
24
- echo ${valid}
25
- exit -1
26
- fi
27
-
28
- echo 'Compiling'
29
- hash=$(ds -e core -c compile -p csdl "$csdl" | jq -r .body.hash)
30
- echo "Compiled and got $hash"
31
-
32
- echo 'Usage :'
33
- ds -e core -c usage | jq .
34
-
35
- echo 'DPU :'
36
- ds -e core -c dpu -p hash $hash | jq .
37
-
38
- echo 'Balance :'
39
- ds -e core -c usage | jq .
40
-
41
- echo 'Preparing Historic query'
42
- end=`expr $(date +%s) - 7200`
43
- start=`expr $end - 3600`
44
-
45
- historic=$(ds -e historics -c prepare -p start ${start} -p end ${end} -p name "Historics CLI @ $start" -p hash ${hash})
46
- echo ${historic} | jq .
47
- historic_id=$(echo ${historic} | jq -r .body.id)
48
- echo "Historic created with ID $historic_id"
49
-
50
- echo 'Validating Push subscription'
51
- push_v=$(ds -e push -c validate -p historics_id ${historic_id} -p name "Playback CLI @ $start" -p output_type http \
52
- -p output_params.method post -p output_params.url 'http://ec2-50-19-63-138.compute-1.amazonaws.com:80' \
53
- -p output_params.delivery_frequency 0 -p output_params.max_size 102400 -p output_params.auth.type none \
54
- -p output_params.verify_ssl false -p output_params.use_gzip true)
55
- push_status=$(echo ${push_v} | jq .status)
56
- echo ${push_v} | jq .
57
-
58
- if [ ${push_status} != 200 ]; then
59
- echo "Validating Push subscription failed"
60
- exit -1
61
- fi
62
-
63
- echo 'Creating Push from Historic'
64
- push=$(ds -e push -c create -p historics_id ${historic_id} -p name "Playback CLI @ $start" -p output_type http \
65
- -p output_params.method post -p output_params.url 'http://ec2-50-19-63-138.compute-1.amazonaws.com:80' \
66
- -p output_params.delivery_frequency 0 -p output_params.max_size 102400 -p output_params.auth.type none \
67
- -p output_params.verify_ssl false -p output_params.use_gzip true)
68
-
69
- echo "Created push subscription for historic"
70
- echo ${push} | jq .
71
- push_id=$(echo ${push} | jq -r .body.id)
72
-
73
- echo 'Starting Historic query'
74
- ds -e historics -c start -p id ${historic_id} | jq .
75
-
76
- echo 'Getting Historic status'
77
- ds -e historics -c status -p start ${start} -p end ${end} | jq .
78
-
79
- echo 'Getting Historics'
80
- ds -e historics -c get -p id ${historic_id} | jq .
81
-
82
- echo 'Updating historic'
83
- ds -e historics -c update -p id ${historic_id} -p name "Some name @ $start - CLI" | jq .
84
-
85
- echo 'Getting push'
86
- ds -e push -c get -p id ${push_id} | jq .
87
-
88
- echo 'Getting push logs'
89
- ds -e push -c log -p id ${push_id} | jq .
90
-
91
- echo 'Pausing push'
92
- ds -e push -c pause -p id ${push_id} | jq .
93
-
94
- echo 'Resuming push'
95
- ds -e push -c resume -p id ${push_id} | jq .
96
-
97
- echo 'Stopping Historic'
98
- ds -e historics -c stop -p id ${historic_id} | jq .
99
-
100
- echo 'Deleting Historic'
101
- ds -e historics -c delete -p id ${historic_id} | jq .
102
-
103
- echo 'Stopping push'
104
- ds -e push -c stop -p id ${push_id} | jq .
105
-
106
- echo 'Deleting push'
107
- ds -e push -c delete -p id ${push_id} | jq .
108
- #todo update push, pull
109
-
110
- echo "Attempting to create a Historics preview"
111
- preview=$(ds -e preview -c create -p start ${start} -p end ${end} -p hash ${hash} -p sources tumblr \
112
- -p parameters 'interaction.author.link,targetVol,hour;interaction.type,freqDist,10')
113
-
114
- echo ${preview} | jq .
115
- preview_id=$(echo ${preview} | jq -r .body.id)
116
-
117
-
118
- echo "Getting the preview we created"
119
- ds -e preview -c get -p id ${preview_id} | jq .
120
-
121
- echo "Creating a managed source"
122
- source=$(ds -e managed_sources -c create -p source_type instagram -p name api \
123
- -p auth "[{\"parameters\":{\"value\":\"$start$end\"}}]" \
124
- -p resources '[{"parameters":{"value":"cats","type":"tag"}}]' \
125
- -p parameters '{"comments":true,"likes":false}')
126
- echo ${source}
127
- source_id=$(echo ${source}| jq -r .body.id)
128
- echo ${source_id}
129
-
130
- echo "Starting managed source"
131
- ds -e managed_sources -c start -p source_id ${source_id} | jq .
132
-
133
- echo "Getting managed sources"
134
- ds -e managed_sources -c get | jq .
135
-
136
- echo "Getting Instagram sources"
137
- ds -e managed_sources -c get -p source_type instagram | jq .
138
-
139
- echo "Getting Facebook page sources"
140
- ds -e managed_sources -c get -p source_type facebook_page | jq .
141
-
142
- echo "Getting page 2 of instagram sources"
143
- ds -e managed_sources -c get -p source_type instagram -p page 2 | jq .
144
-
145
- echo "Getting source for $source_id"
146
- ds -e managed_sources -c get -p source_id ${source_id} | jq .
147
-
148
- echo "Getting logs for source $source_id"
149
- ds -e managed_sources -c log -p source_id ${source_id} -p page 2 -p per_page 1 | jq .
150
-
151
- echo "Stopping managed source"
152
- ds -e managed_sources -c stop -p source_id ${source_id} | jq .
153
-
154
- echo "Deleting managed source $source_id"
155
- ds -e managed_sources -c delete -p source_id ${source_id} | jq .
@@ -1,50 +0,0 @@
1
- require './auth'
2
- class CoreApiEg < DataSiftExample
3
- def initialize
4
- super
5
- @datasift = DataSift::Client.new(@config)
6
- run
7
- end
8
-
9
- def run
10
- begin
11
- csdl = 'interaction.content contains "test"'
12
- # see docs at http://dev.datasift.com/docs/rest-api/validate
13
- puts "Is the following CSDL valid? #{csdl}"
14
- puts @datasift.valid? csdl
15
-
16
- # http://dev.datasift.com/docs/rest-api/compile
17
- puts "\nCompile the CSDL and get a stream hash"
18
- stream = @datasift.compile csdl
19
- puts stream[:data]
20
-
21
- # http://dev.datasift.com/docs/rest-api/dpu
22
- puts "\nGet the DPU cost of the compiled CSDL"
23
- dpu = @datasift.dpu stream[:data][:hash]
24
- puts dpu[:data][:dpu]
25
-
26
- # http://dev.datasift.com/docs/rest-api/balance
27
- puts "\nGet the remaining balance for my account"
28
- balance = @datasift.balance
29
- puts balance[:data]
30
-
31
- #http://dev.datasift.com/docs/rest-api/usage
32
- puts "\nGet my recent account usage"
33
- usage = @datasift.usage
34
- puts usage[:data]
35
-
36
- rescue DataSiftError => dse
37
- puts dse.message
38
- # Then match specific one to take action; All errors thrown by the client extend DataSiftError
39
- case dse
40
- when ConnectionError
41
- # some connection error
42
- when AuthError
43
- when BadRequestError
44
- else
45
- # do something else...
46
- end
47
- end
48
- end
49
- end
50
- CoreApiEg.new
@@ -1,66 +0,0 @@
1
- require './auth'
2
- class HistoricsApi < DataSiftExample
3
- def initialize
4
- super
5
- run_historics
6
- end
7
-
8
- def run_historics
9
- begin
10
- stream = @datasift.compile 'interaction.content contains "datasift"'
11
- hash = stream[:data][:hash]
12
- start = Time.now.to_i - 10800
13
- end_time = start + 3600
14
-
15
- puts 'Check the data coverage for this Historic period'
16
- puts @datasift.historics.status(start, end_time)
17
-
18
- puts "\nPreparing"
19
- # Prepare an Historics query to start from three hours ago and run for 1
20
- # hour using Tumblr as a data source and using only a 10% sample
21
- historics = @datasift.historics.prepare(
22
- hash, start, end_time, 'My ruby historics', 'tumblr', 10
23
- )
24
- puts historics
25
-
26
- id = historics[:data][:id]
27
-
28
- puts "\nCheck the DPU cost of this Historics query"
29
- puts "#{@datasift.dpu('', id)[:data][:dpu]} DPUs"
30
-
31
- puts "\nCreating push subscription for historics"
32
- subscription = create_push(id, true)
33
-
34
- puts "\nStarting historics #{id}"
35
- puts @datasift.historics.start id
36
-
37
- puts "\nPausing historics #{id}"
38
- puts @datasift.historics.pause id
39
-
40
- puts "\nResuming historics #{id}"
41
- puts @datasift.historics.resume id
42
-
43
- puts "\nUpdating historics"
44
- puts @datasift.historics.update(id, 'The new name of my historics')
45
-
46
- puts "\nGet info for the historics"
47
- puts @datasift.historics.get_by_id id
48
-
49
- puts "\nGetting info for all my historics"
50
- puts @datasift.historics.get
51
-
52
- puts "\nStopping historics"
53
- puts @datasift.historics.stop id
54
-
55
- puts "\nDeleting historics"
56
- puts @datasift.historics.delete id
57
-
58
- puts "\nCleanup and delete Push subscription"
59
- puts @datasift.push.delete subscription[:data][:id]
60
- rescue DataSiftError => dse
61
- puts dse.message
62
- end
63
- end
64
- end
65
-
66
- HistoricsApi.new
@@ -1,31 +0,0 @@
1
- require './auth'
2
- class HistoricsPreviewApi < DataSiftExample
3
- def initialize
4
- super
5
- run
6
- end
7
-
8
- def run
9
- begin
10
- puts 'Creating hash'
11
- stream = @datasift.compile 'interaction.content contains "datasift"'
12
- hash = stream[:data][:hash]
13
-
14
- puts "\nCreating a preview"
15
- # see http://dev.datasift.com/docs/rest-api/previewcreate for docs
16
- sources = 'tumblr'
17
- parameters = 'interaction.author.link,targetVol,hour;interaction.type,freqDist,10'
18
- start = Time.now.to_i - (3600 * 48) # 48hrs ago
19
- source = @datasift.historics_preview.create(hash, sources, parameters, start)
20
- puts source
21
-
22
- puts "\nGetting preview data"
23
- puts @datasift.historics_preview.get source[:data][:id]
24
-
25
- rescue DataSiftError => dse
26
- puts dse.message
27
- end
28
- end
29
- end
30
-
31
- HistoricsPreviewApi.new
@@ -1,61 +0,0 @@
1
- require './../auth'
2
- class TwitterGnipBatchEg < DataSiftExample
3
- def initialize
4
- super
5
- @datasift = DataSift::Client.new(@config)
6
- run
7
- end
8
-
9
- def run
10
- begin
11
- # "gnip_1" is the default mapping used to map Tweets ingested from Gnip into a
12
- # format DataSift can use. Using this mapping will altomatically define the
13
- # IDML you need to use for this source
14
- resource = [{
15
- parameters: {
16
- mapping: "gnip_1"
17
- }
18
- }]
19
- puts "Creating Managed Source for ODP Ingestion\n"
20
- source = @datasift.managed_source.create('twitter_gnip', 'Ruby ODP API', {}, resource)
21
- puts "Manage Source with ID #{source[:data][:id]} created"
22
-
23
- lines = 0
24
- payload = ''
25
- # Read interactions out of the fake Tweets fixture file
26
- File.readlines('./../../test/fixtures/data/fake_gnip_tweets.json').each do |line|
27
- lines += 1
28
- payload += line
29
-
30
- # Upload interactions as batches of five
31
- if lines % 5 == 0
32
- puts "\nUploading a batch of five interactions\n"
33
- puts @datasift.odp.ingest(source[:data][:id], payload)[:data].to_json
34
- payload = ''
35
- end
36
- end
37
-
38
- puts "\nCleanup after this test and delete the Managed Source"
39
- @datasift.managed_source.delete(source[:data][:id])
40
-
41
- rescue DataSiftError => dse
42
- puts dse.message
43
- # Then match specific one to take action - All errors thrown by the client extend
44
- # DataSiftError
45
- case dse
46
- when ConnectionError
47
- # some connection error
48
- when AuthError
49
- when BadRequestError
50
- when PayloadTooLargeError
51
- # You've probably hit your x_ingestion_data_ratelimit_limit rate limit; back off
52
- # and try again in a bit. Check your x_ingestion_request_ratelimit_reset header
53
- # to see when you can retry this request successfully
54
- else
55
- # do something else...
56
- end
57
- end
58
- end
59
- end
60
-
61
- TwitterGnipBatchEg.new