datasift 3.1.5 → 3.2.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 (98) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -2
  3. data/.yardopts +4 -0
  4. data/CHANGELOG.md +23 -0
  5. data/Gemfile +13 -0
  6. data/README.md +17 -16
  7. data/VERSION +1 -1
  8. data/datasift.gemspec +8 -14
  9. data/examples/account_identity_eg.rb +48 -0
  10. data/examples/account_identity_limit_eg.rb +68 -0
  11. data/examples/account_identity_token_eg.rb +70 -0
  12. data/examples/auth.rb +4 -4
  13. data/examples/core_api_eg.rb +1 -2
  14. data/examples/historics_eg.rb +7 -1
  15. data/examples/pylon_eg.rb +116 -0
  16. data/lib/account.rb +6 -0
  17. data/lib/account_identity.rb +73 -0
  18. data/lib/account_identity_limit.rb +85 -0
  19. data/lib/account_identity_token.rb +86 -0
  20. data/lib/api/api_resource.rb +14 -5
  21. data/lib/cli.rb +306 -132
  22. data/lib/datasift.rb +82 -47
  23. data/lib/errors.rb +21 -5
  24. data/lib/historics.rb +71 -40
  25. data/lib/historics_preview.rb +25 -8
  26. data/lib/managed_source.rb +69 -25
  27. data/lib/managed_source_auth.rb +21 -6
  28. data/lib/managed_source_resource.rb +21 -6
  29. data/lib/push.rb +132 -65
  30. data/lib/pylon.rb +122 -0
  31. data/test/datasift/core_api_test.rb +116 -90
  32. data/test/datasift/historics_preview_api_test.rb +27 -58
  33. data/test/datasift/push_api_test.rb +156 -141
  34. data/test/fixtures/cassettes/core/after_historic_dpu.json +1 -0
  35. data/test/fixtures/cassettes/core/balance_get.json +1 -0
  36. data/test/fixtures/cassettes/core/before_dpu.json +1 -0
  37. data/test/fixtures/cassettes/core/before_historic_dpu.json +1 -0
  38. data/test/fixtures/cassettes/core/compile_success.json +1 -0
  39. data/test/fixtures/cassettes/core/dpu_get_cost.json +1 -0
  40. data/test/fixtures/cassettes/core/dpu_throw_badrequest.json +1 -0
  41. data/test/fixtures/cassettes/core/historic_dpu.json +1 -0
  42. data/test/fixtures/cassettes/core/usage_success.json +1 -0
  43. data/test/fixtures/cassettes/core/validate_invalid_hash.json +1 -0
  44. data/test/fixtures/cassettes/core/validate_success_bool.json +1 -0
  45. data/test/fixtures/cassettes/core/validate_success_hash.json +1 -0
  46. data/test/fixtures/cassettes/preview/before_preview_create.json +1 -0
  47. data/test/fixtures/cassettes/preview/before_preview_get.json +1 -0
  48. data/test/fixtures/cassettes/preview/preview_create_success.json +1 -0
  49. data/test/fixtures/cassettes/preview/preview_get_success.json +1 -0
  50. data/test/fixtures/cassettes/push/after_push_create.json +1 -0
  51. data/test/fixtures/cassettes/push/after_push_get.json +1 -0
  52. data/test/fixtures/cassettes/push/after_push_log.json +1 -0
  53. data/test/fixtures/cassettes/push/after_push_pause.json +1 -0
  54. data/test/fixtures/cassettes/push/after_push_resume.json +1 -0
  55. data/test/fixtures/cassettes/push/after_push_stop.json +1 -0
  56. data/test/fixtures/cassettes/push/after_push_update.json +1 -0
  57. data/test/fixtures/cassettes/push/before_push_create.json +1 -0
  58. data/test/fixtures/cassettes/push/before_push_delete.json +1 -0
  59. data/test/fixtures/cassettes/push/before_push_get.json +1 -0
  60. data/test/fixtures/cassettes/push/before_push_log.json +1 -0
  61. data/test/fixtures/cassettes/push/before_push_pause.json +1 -0
  62. data/test/fixtures/cassettes/push/before_push_resume.json +1 -0
  63. data/test/fixtures/cassettes/push/before_push_stop.json +1 -0
  64. data/test/fixtures/cassettes/push/before_push_update.json +1 -0
  65. data/test/fixtures/cassettes/push/push_create.json +1 -0
  66. data/test/fixtures/cassettes/push/push_delete.json +1 -0
  67. data/test/fixtures/cassettes/push/push_get_by_id.json +1 -0
  68. data/test/fixtures/cassettes/push/push_log_with_id.json +1 -0
  69. data/test/fixtures/cassettes/push/push_pause.json +1 -0
  70. data/test/fixtures/cassettes/push/push_resume.json +1 -0
  71. data/test/fixtures/cassettes/push/push_stop.json +1 -0
  72. data/test/fixtures/cassettes/push/push_update.json +1 -0
  73. data/test/fixtures/cassettes/push/push_validate.json +1 -0
  74. data/test/test_helper.rb +31 -1
  75. metadata +64 -104
  76. data/examples/dynamic_list_eg.rb +0 -74
  77. data/examples/dynamic_list_replace_eg.rb +0 -45
  78. data/lib/dynamic_list.rb +0 -66
  79. data/lib/dynamic_list_replace.rb +0 -45
  80. data/test/fixtures/balance.json +0 -1
  81. data/test/fixtures/compile_csdl_invalid.json +0 -1
  82. data/test/fixtures/compile_csdl_valid.json +0 -1
  83. data/test/fixtures/dpu_valid.json +0 -1
  84. data/test/fixtures/preview_create_valid.json +0 -1
  85. data/test/fixtures/preview_get_running.json +0 -1
  86. data/test/fixtures/preview_get_succeeded.json +0 -1
  87. data/test/fixtures/push_create_valid.json +0 -1
  88. data/test/fixtures/push_get_list_by_hash_valid.json +0 -1
  89. data/test/fixtures/push_get_list_by_historics_id_valid.json +0 -1
  90. data/test/fixtures/push_get_list_valid.json +0 -1
  91. data/test/fixtures/push_get_valid.json +0 -1
  92. data/test/fixtures/push_log_valid.json +0 -1
  93. data/test/fixtures/push_pause_valid.json +0 -1
  94. data/test/fixtures/push_stop_valid.json +0 -1
  95. data/test/fixtures/push_validate_valid.json +0 -1
  96. data/test/fixtures/usage_current.json +0 -1
  97. data/test/fixtures/validate_csdl_invalid.json +0 -1
  98. data/test/fixtures/validate_csdl_valid.json +0 -1
data/lib/pylon.rb ADDED
@@ -0,0 +1,122 @@
1
+ module DataSift
2
+ #
3
+ # Class for accessing DataSift's PYLON API
4
+ class Pylon < DataSift::ApiResource
5
+ # Check PYLON CSDL is valid by making an /pylon/validate API call
6
+ #
7
+ # @param csdl [String] CSDL you wish to validate
8
+ # @param boolResponse [Boolean] True if you want a boolean response.
9
+ # False if you want the full response object
10
+ # @return [Boolean, Object] Dependent on value of boolResponse
11
+ def valid?(csdl = '', boolResponse = true)
12
+ fail BadParametersError, 'csdl is required' if csdl.empty?
13
+ params = { csdl: csdl }
14
+
15
+ res = DataSift.request(:POST, 'pylon/validate', @config, params)
16
+ boolResponse ? res[:http][:status] == 200 : res
17
+ end
18
+
19
+ # Compile PYLON CSDL by making an /pylon/compile API call
20
+ #
21
+ # @param csdl [String] CSDL you wish to compile
22
+ # @return [Object] API reponse object
23
+ def compile(csdl)
24
+ fail BadParametersError, 'csdl is required' if csdl.empty?
25
+ params = { csdl: csdl }
26
+
27
+ DataSift.request(:POST, 'pylon/compile', @config, params)
28
+ end
29
+
30
+ # Perform /pylon/get API call to query status of your PYLON recordings
31
+ #
32
+ # @param hash [String] Hash you with the get the status for
33
+ # @return [Object] API reponse object
34
+ def get(hash)
35
+ fail BadParametersError, 'hash is required' if hash.empty?
36
+ params = { hash: hash }
37
+
38
+ DataSift.request(:GET, 'pylon/get', @config, params)
39
+ end
40
+
41
+ # Perform /pylon/get API call to list all PYLON Recordings
42
+ #
43
+ # @param page [Integer] Which page of recordings to retreive
44
+ # @param per_page [Integer] How many recordings to return per page
45
+ # @param order_by [String, Symbol] Which field to sort results by
46
+ # @param order_dir [String, Symbol] Order results in ascending or descending
47
+ # order
48
+ # @return [Object] API reponse object
49
+ def list(page = nil, per_page = nil, order_by = '', order_dir = '')
50
+ params = {}
51
+ params.merge!(page: page) unless page.nil?
52
+ params.merge!(per_page: per_page) unless per_page.nil?
53
+ params.merge!(order_by: order_by) unless order_by.empty?
54
+ params.merge!(order_dir: order_dir) unless order_dir.empty?
55
+
56
+ DataSift.request(:GET, 'pylon/get', @config, params)
57
+ end
58
+
59
+ # Start recording a PYLON filter by making an /pylon/start API call
60
+ #
61
+ # @param hash [String] CSDL you wish to begin (or resume) recording
62
+ # @param name [String] Give your recording a name. Required when starting a
63
+ # new recording
64
+ # @return [Object] API reponse object
65
+ def start(hash = '', name = '')
66
+ fail BadParametersError, 'hash is required' if hash.empty?
67
+ params = { hash: hash }
68
+ params.merge!(name: name) unless name.empty?
69
+
70
+ DataSift.request(:PUT, 'pylon/start', @config, params)
71
+ end
72
+
73
+ # Stop an active PYLON recording by making an /pylon/stop API call
74
+ #
75
+ # @param hash [String] CSDL you wish to stop recording
76
+ # @return [Object] API reponse object
77
+ def stop(hash)
78
+ fail BadParametersError, 'hash is required' if hash.empty?
79
+ params = { hash: hash }
80
+
81
+ DataSift.request(:PUT, 'pylon/stop', @config, params)
82
+ end
83
+
84
+ # Perform a PYLON analysis query by making an /pylon/analyze API call
85
+ #
86
+ # @param hash [String] Hash of the recording you wish to perform an
87
+ # analysis against
88
+ # @param parameters [String] Parameters of the analysis you wish to perform.
89
+ # See the
90
+ # {http://dev.datasift.com/pylon/docs/api-endpoints/pylonanalyze
91
+ # /pylon/analyze API Docs} for full documentation
92
+ # @param filter [String] Optional PYLON CSDL for a query filter
93
+ # @param start_time [Integer] Optional start timestamp for filtering by date
94
+ # @param end_time [Integer] Optional end timestamp for filtering by date
95
+ # @return [Object] API reponse object
96
+ def analyze(hash = '', parameters = '', filter = '', start_time = nil, end_time = nil)
97
+ fail BadParametersError, 'hash is required' if hash.empty?
98
+ fail BadParametersError, 'parameters is required' if parameters.empty?
99
+ params = {
100
+ hash: hash,
101
+ parameters: parameters
102
+ }
103
+ params.merge!(filter: filter) unless filter.empty?
104
+ params.merge!(start: start_time) unless start_time.nil?
105
+ params.merge!(end: end_time) unless end_time.nil?
106
+
107
+ DataSift.request(:POST, 'pylon/analyze', @config, params)
108
+ end
109
+
110
+ # Query the tag hierarchy on interactions populated by a particular
111
+ # recording
112
+ #
113
+ # @param hash [String] Hash of the recording you wish to query
114
+ # @return [Object] API reponse object
115
+ def tags(hash)
116
+ fail BadParametersError, 'hash is required' if hash.empty?
117
+ params = { hash: hash }
118
+
119
+ DataSift.request(:GET, 'pylon/tags', @config, params)
120
+ end
121
+ end
122
+ end
@@ -6,148 +6,174 @@ describe 'DataSift' do
6
6
  auth = DataSiftExample.new
7
7
  @datasift = auth.datasift
8
8
  @data = OpenStruct.new
9
- @statuses = OpenStruct.new
10
- @headers = OpenStruct.new
11
9
 
12
10
  @data.valid_csdl = 'interaction.content contains "test"'
13
11
  @data.invalid_csdl = 'interaction.nonsense is not valid'
12
+ @data.invalid_hash = 'this_is_not_a_valid_stream_hash'
13
+ end
14
14
 
15
- @statuses.valid = 200
16
- @statuses.bad_request = 400
17
-
15
+ ##
16
+ # Client
17
+ #
18
+ describe 'client' do
19
+ it 'raises_InvalidConfigError_without_auth_credentials' do
20
+ assert_raises InvalidConfigError do
21
+ DataSift::Client.new({})
22
+ end
23
+ end
18
24
  end
19
25
 
20
- describe '#compile/validate' do
21
- before do
22
- @headers.csdl_compile = {
23
- "date" => "Thu, 30 Jan 2014 10:09:19 GMT", "content-type" => "application/json",
24
- "transfer-encoding" => "chunked", "connection" => "close", "x-api-version" => "1",
25
- "x-ratelimit-limit" => "10000", "x-ratelimit-remaining" => "10000", "x-ratelimit-cost" => "5"}
26
-
27
- #valid CSDL
28
- stub_request(:post, /api.datasift.com\/.*\/validate/).
29
- with(:body => {"csdl" => @data.valid_csdl}).
30
- to_return(:status => @statuses.valid,
31
- :body => fixture('validate_csdl_valid.json'),
32
- :headers => @headers.csdl_compile)
33
- #invalid CSDL
34
- stub_request(:post, /api.datasift.com\/.*\/validate/).
35
- with(:body => {"csdl" => @data.invalid_csdl}).
36
- to_return(:status => @statuses.bad_request,
37
- :body => fixture('validate_csdl_invalid.json'),
38
- :headers => @headers.csdl_compile)
39
- #valid stream compilation
40
- stub_request(:post, /api.datasift.com\/.*\/compile/).
41
- with(:body => {"csdl" => @data.valid_csdl}).
42
- to_return(:status => @statuses.valid,
43
- :body => fixture('compile_csdl_valid.json'),
44
- :headers => @headers.csdl_compile)
45
- end
46
-
47
- it 'test_csdl_cant_be_nil_when_validating' do
26
+ ##
27
+ # /validate
28
+ #
29
+ describe '#validate' do
30
+ it 'csdl_cant_be_nil_when_validating' do
48
31
  assert_raises InvalidParamError do
49
32
  @datasift.valid?(nil)
50
33
  end
51
34
  end
52
35
 
53
- it 'test_csdl_cant_be_empty_when_validating' do
36
+ it 'csdl_cant_be_empty_when_validating' do
54
37
  assert_raises InvalidParamError do
55
38
  @datasift.valid?('')
56
39
  end
57
40
  end
58
41
 
59
- it 'test_if_user_can_get_successful_validation_as_bool' do
60
- assert @datasift.valid?(@data.valid_csdl), 'Valid CSDL must return true'
42
+ it 'user_can_get_successful_validation_as_bool' do
43
+ VCR.use_cassette('core/validate_success_bool') do
44
+ assert @datasift.valid?(@data.valid_csdl), 'Valid CSDL must return true'
45
+ end
61
46
  end
62
47
 
63
- it 'test_if_user_can_get_successful_validation_as_hash' do
64
- validation = @datasift.valid?(@data.valid_csdl, false)
65
- assert_kind_of Hash, validation, 'Valid should return a hash here'
66
- assert_equal @statuses.valid, validation[:http][:status], "This request should have returned status as #{@statuses.validate_csdl}"
48
+ it 'user_can_get_successful_validation_as_hash' do
49
+ VCR.use_cassette('core/validate_success_hash') do
50
+ validation = @datasift.valid?(@data.valid_csdl, false)
51
+ assert_kind_of Hash, validation,
52
+ "Successful validation will return a hash"
53
+ assert_equal STATUS.valid, validation[:http][:status],
54
+ "This request should have returned #{STATUS.valid} status"
55
+ end
67
56
  end
68
57
 
69
- it 'test_failing_csdl_validation' do
70
- assert_raises BadRequestError do
71
- @datasift.valid?(@data.invalid_csdl)
58
+ it 'failing_csdl_validation' do
59
+ VCR.use_cassette('core/validate_invalid_hash') do
60
+ assert_raises BadRequestError do
61
+ @datasift.valid?(@data.invalid_csdl)
62
+ end
72
63
  end
73
64
  end
65
+ end
74
66
 
75
- it 'test_csdl_cant_be_nil_when_compiling' do
67
+ ##
68
+ # /compile
69
+ #
70
+ describe '#compile' do
71
+ it 'csdl_cant_be_nil_when_compiling' do
76
72
  assert_raises InvalidParamError do
77
73
  @datasift.compile(nil)
78
74
  end
79
75
  end
80
76
 
81
- it 'test_csdl_cant_be_empty_when_compiling' do
77
+ it 'csdl_cant_be_empty_when_compiling' do
82
78
  assert_raises InvalidParamError do
83
79
  @datasift.compile('')
84
80
  end
85
81
  end
86
- end
87
-
88
- describe '#usage' do
89
- describe 'with valid request' do
90
- before do
91
- @headers.valid_usage = {
92
- "date" => "Thu, 30 Jan 2014 10:09:19 GMT", "content-type" => "application/json",
93
- "transfer-encoding" => "chunked", "connection" => "close", "x-api-version" => "1",
94
- "x-ratelimit-limit" => "10000", "x-ratelimit-remaining" => "10000", "x-ratelimit-cost" => "25"}
95
82
 
96
- #valid /usage request
97
- stub_request(:post, /api.datasift.com\/.*\/usage/).
98
- with(:body => {:period => 'hour'}).
99
- to_return(status: @statuses.valid,
100
- body: fixture('usage_current.json'),
101
- headers: @headers.valid_usage)
83
+ it 'successful_compilation_returns_hash' do
84
+ VCR.use_cassette('core/compile_success') do
85
+ response = @datasift.compile @data.valid_csdl
86
+ assert_kind_of Hash, response,
87
+ "Successful compilation will return a hash"
88
+ assert_equal STATUS.valid, response[:http][:status],
89
+ "This request should have returned #{STATUS.valid} status"
102
90
  end
91
+ end
92
+ end
103
93
 
104
- it 'can get users usage' do
105
- @datasift.usage
106
- assert_requested(:post, "https://api.datasift.com/v1/usage", :body => {"period"=>"hour"})
94
+ ##
95
+ # /usage
96
+ #
97
+ describe '#usage' do
98
+ it 'can_get_users_usage' do
99
+ VCR.use_cassette('core/usage_success') do
100
+ response = @datasift.usage
101
+ assert_equal STATUS.valid, response[:http][:status]
102
+ assert_kind_of Hash, response
107
103
  end
108
104
  end
109
105
  end
110
106
 
107
+ ##
108
+ # /dpu
109
+ #
111
110
  describe '#dpu' do
112
111
  before do
113
- @data.dpu_hash_valid = '145ea24a4d83a14ecb9077b831f14809'
114
- @headers.dpu = {
115
- "date" => "Thu, 30 Jan 2014 10:09:19 GMT", "content-type" => "application/json",
116
- "transfer-encoding" => "chunked", "connection" => "close", "x-api-version" => "1",
117
- "x-ratelimit-limit" => "10000", "x-ratelimit-remaining" => "10000", "x-ratelimit-cost" => "5"}
112
+ VCR.use_cassette('core/before_dpu') do
113
+ @hash = @datasift.compile(@data.valid_csdl)[:data][:hash]
114
+ end
115
+ end
118
116
 
119
- #valid /dpu request
120
- stub_request(:post, /api.datasift.com\/.*\/dpu/).
121
- with(:body => {:hash => @data.dpu_hash_valid}).
122
- to_return(status: @statuses.valid,
123
- body: fixture('dpu_valid.json'),
124
- headers: @headers.dpu)
117
+ it 'can_get_dpu_cost' do
118
+ VCR.use_cassette('core/dpu_get_cost') do
119
+ response = @datasift.dpu @hash
120
+ assert_equal STATUS.valid, response[:http][:status]
121
+ end
122
+ end
123
+
124
+ it 'cannot_get_dpu_cost_for_invalid_hash' do
125
+ VCR.use_cassette('core/dpu_throw_badrequest') do
126
+ assert_raises BadRequestError do
127
+ @datasift.dpu @data.invalid_hash
128
+ end
129
+ end
125
130
  end
126
131
 
127
- it 'can get dpu cost for valid stream' do
128
- @datasift.dpu(@data.dpu_hash_valid)
129
- assert_requested(:post, "https://api.datasift.com/v1/dpu", body: {hash: @data.dpu_hash_valid})
132
+ it 'requires_at_least_one_param' do
133
+ assert_raises ArgumentError do
134
+ @datasift.dpu
135
+ end
130
136
  end
131
137
  end
132
138
 
133
- describe '#balance' do
139
+ describe '#dpu for Historics' do
134
140
  before do
135
- @headers.balance = {
136
- "date" => "Thu, 30 Jan 2014 10:09:19 GMT", "content-type" => "application/json",
137
- "transfer-encoding" => "chunked", "connection" => "close", "x-api-version" => "1",
138
- "x-ratelimit-limit" => "10000", "x-ratelimit-remaining" => "10000", "x-ratelimit-cost" => "25"}
141
+ VCR.use_cassette('core/before_historic_dpu') do
142
+ @hash = @datasift.compile(@data.valid_csdl)[:data][:hash]
143
+ @historic = @datasift.historics.prepare(
144
+ @hash,
145
+ Time.now.to_i - 10800,
146
+ Time.now.to_i - 7200,
147
+ 'Ruby test suite',
148
+ 'tumblr',
149
+ 10
150
+ )
151
+ end
152
+ end
139
153
 
140
- #valid /dpu request
141
- stub_request(:post, /api.datasift.com\/.*\/balance/).
142
- to_return(status: @statuses.valid,
143
- body: fixture('balance.json'),
144
- headers: @headers.balance)
154
+ after do
155
+ VCR.use_cassette('core/after_historic_dpu') do
156
+ @datasift.historics.delete @historic[:data][:id]
157
+ end
145
158
  end
146
159
 
147
- it 'can get account balance' do
148
- @datasift.balance
149
- assert_requested(:post, "https://api.datasift.com/v1/balance")
160
+ it 'can_get_dpu_cost_for_historic' do
161
+ VCR.use_cassette('core/historic_dpu') do
162
+ response = @datasift.dpu('', @historic[:data][:id])
163
+ assert_equal STATUS.valid, response[:http][:status]
164
+ end
150
165
  end
151
166
  end
152
167
 
168
+ ##
169
+ # /balance
170
+ #
171
+ describe '#balance' do
172
+ it 'can get account balance' do
173
+ VCR.use_cassette('core/balance_get') do
174
+ response = @datasift.balance
175
+ assert_equal STATUS.valid, response[:http][:status]
176
+ end
177
+ end
178
+ end
153
179
  end
@@ -1,83 +1,52 @@
1
1
  require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  describe 'DataSift::HistoricsPreview' do
4
-
5
4
  before do
6
5
  auth = DataSiftExample.new
7
6
  @datasift = auth.datasift
8
7
  @data = OpenStruct.new
9
- @statuses = OpenStruct.new
10
- @headers = OpenStruct.new
11
8
 
12
- @statuses.valid = 200
13
- @statuses.accepted = 202
9
+ @data.valid_csdl = 'interaction.content contains "ruby"'
10
+ @data.sources = 'facebook,twitter'
11
+ @data.parameters = 'language.tag,freqDist,5;interaction.id,targetVol,hour'
12
+ @data.start = '1398898800'
13
+ @data.end = '1398985200'
14
14
  end
15
15
 
16
+ ##
17
+ # /preview/create
18
+ #
16
19
  describe '#create' do
17
20
  before do
18
- @data.stream_hash = '145ea24a4d83a14ecb9077b831f14809'
19
- @data.sources = 'facebook,twitter'
20
- @data.parameters = 'language.tag,freqDist,5;interaction.id,targetVol,hour'
21
- @data.start = '1398898800'
22
- @data.end = '1398985200'
23
-
24
- @headers.preview_create = {
25
- "date" => "Thu, 30 Jan 2014 10:09:19 GMT", "content-type" => "application/json",
26
- "transfer-encoding" => "chunked", "connection" => "close", "x-api-version" => "1",
27
- "x-ratelimit-limit" => "10000", "x-ratelimit-remaining" => "10000", "x-ratelimit-cost" => "25"}
28
-
29
- #valid /preview/create request
30
- stub_request(:post, /api.datasift.com\/.*\/preview\/create/).
31
- with(:body => { :hash => @data.stream_hash,
32
- :sources => @data.sources,
33
- :parameters => @data.parameters,
34
- :start => @data.start,
35
- :end => @data.end}).
36
- to_return(status: @statuses.valid,
37
- body: fixture('preview_create_valid.json'),
38
- headers: @headers.preview_create)
21
+ VCR.use_cassette('preview/before_preview_create') do
22
+ @hash = @datasift.compile(@data.valid_csdl)[:data][:hash]
23
+ end
39
24
  end
40
25
 
41
- it 'can create an Historics Preview' do
42
- @datasift.historics_preview.create(@data.stream_hash, @data.sources, @data.parameters, @data.start, @data.end)
43
- assert_requested( :post,
44
- 'https://api.datasift.com/v1/preview/create',
45
- :body => {:start => @data.start,
46
- :end => @data.end,
47
- :hash => @data.stream_hash,
48
- :sources => @data.sources,
49
- :parameters => @data.parameters})
26
+ it 'can_create_historics_preview' do
27
+ VCR.use_cassette('preview/preview_create_success') do
28
+ response = @datasift.historics_preview.create(@hash, @data.sources, @data.parameters, @data.start, @data.end)
29
+ assert_equal STATUS.accepted, response[:http][:status]
30
+ end
50
31
  end
51
-
52
32
  end
53
33
 
34
+ ##
35
+ # /preview/get
36
+ #
54
37
  describe '#get' do
55
38
  before do
56
- @data.id = 'fbd5441ab17a46f2ac200f8cab6bdb79fe8efb31'
57
-
58
- @headers.preview_get = {
59
- "date" => "Thu, 30 Jan 2014 10:09:19 GMT", "content-type" => "application/json",
60
- "transfer-encoding" => "chunked", "connection" => "close", "x-api-version" => "1",
61
- "x-ratelimit-limit" => "10000", "x-ratelimit-remaining" => "10000", "x-ratelimit-cost" => "5"}
62
-
63
- #valid /preview/get running request
64
- stub_request(:post, /api.datasift.com\/.*\/preview\/get/).
65
- with(:body => { :id => @data.id}).
66
- to_return(status: @statuses.accepted,
67
- body: fixture('preview_get_running.json'),
68
- headers: @headers.preview_get)
69
-
70
- #valid /preview/get succeeded request
71
- stub_request(:post, /api.datasift.com\/.*\/preview\/get/).
72
- with(:body => { :id => @data.id}).
73
- to_return(status: @statuses.valid,
74
- body: fixture('preview_get_succeeded.json'),
75
- headers: @headers.preview_get)
39
+ VCR.use_cassette('preview/before_preview_get') do
40
+ @hash = @datasift.compile(@data.valid_csdl)[:data][:hash]
41
+ @preview = @datasift.historics_preview.create(@hash, @data.sources, @data.parameters, @data.start, @data.end)
42
+ end
76
43
  end
77
44
 
78
45
  it 'can get an Historics Preview' do
79
- @datasift.historics_preview.get(@data.id)
80
- assert_requested( :post, 'https://api.datasift.com/v1/preview/get', :body => {:id => @data.id})
46
+ VCR.use_cassette('preview/preview_get_success') do
47
+ response = @datasift.historics_preview.get(@preview[:data][:id])
48
+ assert_equal STATUS.accepted, response[:http][:status]
49
+ end
81
50
  end
82
51
  end
83
52
  end