gnip_api 1.1.3 → 1.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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +16 -37
  4. data/lib/gnip_api/adapter.rb +42 -28
  5. data/lib/gnip_api/configuration.rb +4 -6
  6. data/lib/gnip_api/errors.rb +3 -0
  7. data/lib/gnip_api/gnip/gnip_data.rb +1 -1
  8. data/lib/gnip_api/gnip/system_message.rb +4 -0
  9. data/lib/gnip_api/power_track/buffer.rb +42 -0
  10. data/lib/gnip_api/power_track/rule.rb +77 -0
  11. data/lib/gnip_api/power_track/rule_validator.rb +6 -0
  12. data/lib/gnip_api/power_track/rules.rb +81 -0
  13. data/lib/gnip_api/power_track/stream.rb +122 -0
  14. data/lib/gnip_api/request.rb +8 -1
  15. data/lib/gnip_api/response.rb +21 -0
  16. data/lib/gnip_api/search.rb +108 -0
  17. data/lib/gnip_api/version.rb +1 -1
  18. data/lib/gnip_api.rb +5 -7
  19. data/spec/fixtures/rule_value_examples.json +27 -0
  20. data/spec/gnip_api/adapter_spec.rb +0 -87
  21. data/spec/gnip_api/configuration_spec.rb +0 -15
  22. data/spec/gnip_api/{apis/power_track → power_track}/buffer_spec.rb +2 -2
  23. data/spec/gnip_api/power_track/rule_spec.rb +89 -0
  24. data/spec/gnip_api/{apis/power_track → power_track}/rules_spec.rb +8 -8
  25. data/spec/gnip_api/power_track/stream_spec.rb +53 -0
  26. data/spec/gnip_api/response_spec.rb +27 -0
  27. data/spec/gnip_api/{apis/search_spec.rb → search_spec.rb} +9 -9
  28. data/spec/spec_helper.rb +4 -3
  29. metadata +20 -26
  30. data/lib/gnip_api/adapters/base_adapter.rb +0 -94
  31. data/lib/gnip_api/adapters/httparty_adapter.rb +0 -65
  32. data/lib/gnip_api/apis/power_track/buffer.rb +0 -38
  33. data/lib/gnip_api/apis/power_track/rule.rb +0 -33
  34. data/lib/gnip_api/apis/power_track/rule_validator.rb +0 -8
  35. data/lib/gnip_api/apis/power_track/rules.rb +0 -83
  36. data/lib/gnip_api/apis/power_track/stream.rb +0 -84
  37. data/lib/gnip_api/apis/search.rb +0 -109
  38. data/spec/gnip_api/adapters/base_adapter_spec.rb +0 -0
  39. data/spec/gnip_api/adapters/httparty_adapter_spec.rb +0 -0
  40. data/spec/gnip_api/apis/power_track/rule_spec.rb +0 -62
  41. data/spec/gnip_api/apis/power_track/stream_spec.rb +0 -93
  42. data/spec/lib/test_adapter.rb +0 -16
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gnip_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rayko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-14 00:00:00.000000000 Z
11
+ date: 2017-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -169,14 +169,6 @@ files:
169
169
  - gnip_api.gemspec
170
170
  - lib/gnip_api.rb
171
171
  - lib/gnip_api/adapter.rb
172
- - lib/gnip_api/adapters/base_adapter.rb
173
- - lib/gnip_api/adapters/httparty_adapter.rb
174
- - lib/gnip_api/apis/power_track/buffer.rb
175
- - lib/gnip_api/apis/power_track/rule.rb
176
- - lib/gnip_api/apis/power_track/rule_validator.rb
177
- - lib/gnip_api/apis/power_track/rules.rb
178
- - lib/gnip_api/apis/power_track/stream.rb
179
- - lib/gnip_api/apis/search.rb
180
172
  - lib/gnip_api/configuration.rb
181
173
  - lib/gnip_api/endpoints.rb
182
174
  - lib/gnip_api/errors.rb
@@ -188,8 +180,14 @@ files:
188
180
  - lib/gnip_api/gnip/twitter_compliance_message.rb
189
181
  - lib/gnip_api/gnip/url.rb
190
182
  - lib/gnip_api/json_parser.rb
183
+ - lib/gnip_api/power_track/buffer.rb
184
+ - lib/gnip_api/power_track/rule.rb
185
+ - lib/gnip_api/power_track/rule_validator.rb
186
+ - lib/gnip_api/power_track/rules.rb
187
+ - lib/gnip_api/power_track/stream.rb
191
188
  - lib/gnip_api/request.rb
192
189
  - lib/gnip_api/response.rb
190
+ - lib/gnip_api/search.rb
193
191
  - lib/gnip_api/version.rb
194
192
  - spec/fixtures/activities/full_activity.json
195
193
  - spec/fixtures/activities/nil_urls.json
@@ -197,6 +195,7 @@ files:
197
195
  - spec/fixtures/activities/real_activity.json
198
196
  - spec/fixtures/activities/real_activity_long_object.json
199
197
  - spec/fixtures/activities/real_activity_long_rules.json
198
+ - spec/fixtures/rule_value_examples.json
200
199
  - spec/fixtures/search_api/search_activities_response.json
201
200
  - spec/fixtures/search_api/search_counts_response.json
202
201
  - spec/fixtures/system_messages/error.json
@@ -218,13 +217,6 @@ files:
218
217
  - spec/fixtures/twitter_messages/user_unsuspend.json
219
218
  - spec/fixtures/twitter_messages/user_withheld.json
220
219
  - spec/gnip_api/adapter_spec.rb
221
- - spec/gnip_api/adapters/base_adapter_spec.rb
222
- - spec/gnip_api/adapters/httparty_adapter_spec.rb
223
- - spec/gnip_api/apis/power_track/buffer_spec.rb
224
- - spec/gnip_api/apis/power_track/rule_spec.rb
225
- - spec/gnip_api/apis/power_track/rules_spec.rb
226
- - spec/gnip_api/apis/power_track/stream_spec.rb
227
- - spec/gnip_api/apis/search_spec.rb
228
220
  - spec/gnip_api/configuration_spec.rb
229
221
  - spec/gnip_api/endpoints_spec.rb
230
222
  - spec/gnip_api/gnip/activity_spec.rb
@@ -233,9 +225,13 @@ files:
233
225
  - spec/gnip_api/gnip/twitter_compliance_message_spec.rb
234
226
  - spec/gnip_api/gnip/url_spec.rb
235
227
  - spec/gnip_api/json_parser_spec.rb
228
+ - spec/gnip_api/power_track/buffer_spec.rb
229
+ - spec/gnip_api/power_track/rule_spec.rb
230
+ - spec/gnip_api/power_track/rules_spec.rb
231
+ - spec/gnip_api/power_track/stream_spec.rb
236
232
  - spec/gnip_api/request_spec.rb
237
233
  - spec/gnip_api/response_spec.rb
238
- - spec/lib/test_adapter.rb
234
+ - spec/gnip_api/search_spec.rb
239
235
  - spec/spec_helper.rb
240
236
  - spec/test_spec.rb
241
237
  homepage: ''
@@ -269,6 +265,7 @@ test_files:
269
265
  - spec/fixtures/activities/real_activity.json
270
266
  - spec/fixtures/activities/real_activity_long_object.json
271
267
  - spec/fixtures/activities/real_activity_long_rules.json
268
+ - spec/fixtures/rule_value_examples.json
272
269
  - spec/fixtures/search_api/search_activities_response.json
273
270
  - spec/fixtures/search_api/search_counts_response.json
274
271
  - spec/fixtures/system_messages/error.json
@@ -290,13 +287,6 @@ test_files:
290
287
  - spec/fixtures/twitter_messages/user_unsuspend.json
291
288
  - spec/fixtures/twitter_messages/user_withheld.json
292
289
  - spec/gnip_api/adapter_spec.rb
293
- - spec/gnip_api/adapters/base_adapter_spec.rb
294
- - spec/gnip_api/adapters/httparty_adapter_spec.rb
295
- - spec/gnip_api/apis/power_track/buffer_spec.rb
296
- - spec/gnip_api/apis/power_track/rule_spec.rb
297
- - spec/gnip_api/apis/power_track/rules_spec.rb
298
- - spec/gnip_api/apis/power_track/stream_spec.rb
299
- - spec/gnip_api/apis/search_spec.rb
300
290
  - spec/gnip_api/configuration_spec.rb
301
291
  - spec/gnip_api/endpoints_spec.rb
302
292
  - spec/gnip_api/gnip/activity_spec.rb
@@ -305,8 +295,12 @@ test_files:
305
295
  - spec/gnip_api/gnip/twitter_compliance_message_spec.rb
306
296
  - spec/gnip_api/gnip/url_spec.rb
307
297
  - spec/gnip_api/json_parser_spec.rb
298
+ - spec/gnip_api/power_track/buffer_spec.rb
299
+ - spec/gnip_api/power_track/rule_spec.rb
300
+ - spec/gnip_api/power_track/rules_spec.rb
301
+ - spec/gnip_api/power_track/stream_spec.rb
308
302
  - spec/gnip_api/request_spec.rb
309
303
  - spec/gnip_api/response_spec.rb
310
- - spec/lib/test_adapter.rb
304
+ - spec/gnip_api/search_spec.rb
311
305
  - spec/spec_helper.rb
312
306
  - spec/test_spec.rb
@@ -1,94 +0,0 @@
1
- # BaseAdapter should be used on any adapter for this gem. In order
2
- # to create your own adapter you must inherit this class to
3
- # let your adapter use the provided functionality of the gem. In
4
- # other words, this just defines basic methods to provide the
5
- # custom adapter with basic data.
6
- #
7
- # A few requirements to avoid issues for the adapter you want to use:
8
- # - Should support chunked read of stream
9
- # - Should handle compression (Excon seems to let user handle it)
10
- # - Shouldn't store chunked data (memory leak)
11
- # - Should allow custom headers
12
- # - Should allow block response
13
- #
14
- # To create a custom adapter, create your class, and implement the
15
- # following methods that GnipApi::Adapter will need.
16
- #
17
- # - #get
18
- # - #post
19
- # - #delete
20
- # - #stream_get
21
- #
22
- # All single-request methods (stream_get not included), should
23
- # return a GnipApi::Response object with:
24
- #
25
- # - status: integer value for status code (200, 403, etc)
26
- # - body: raw body, no matter if it's json or xml, the implementation of the api will know this
27
- # - headers: a hash with the response headers
28
- #
29
- # The response object is an effort to standarize the data and let Gnip::Adapter
30
- # operate without the concern of the data format. The helper method to create
31
- # this response is available in this class, and will be available to your class
32
- # when you write your adapter.
33
- #
34
- # The process of parsing the headers to a hash, setting authorization headers or
35
- # parsing response data to break it down to status, body and headers are responsabilities
36
- # of your custom adapter class.
37
- #
38
- # Gnip::Adapter will pass your adapter a Gnip::Request object that contains:
39
- #
40
- # - uri: URI object with url, schema, etc
41
- # - payload: a parsed text to send in the request's body
42
- # - headers: a hash that may contain additional headers
43
- #
44
- # Your adapter should process this object and translate it into a relevant request for
45
- # your desired connector. Note that payload and headers may be nil if not needed.
46
- #
47
- # Last thing to denote, GnipApi::Adapter will expect an instance of your adapter to use.
48
- # What you do inside your adapter or how you implement a specific adapter is up to you.
49
-
50
- module GnipApi
51
- module Adapters
52
- class BaseAdapter
53
- def username
54
- GnipApi.configuration.user
55
- end
56
-
57
- def password
58
- GnipApi.configuration.password
59
- end
60
-
61
- def default_timeout
62
- GnipApi.configuration.request_timeout
63
- end
64
-
65
- def create_response request, status, body, headers
66
- GnipApi::Response.new request, status, body, headers
67
- end
68
-
69
- private
70
- def debug_request options={}
71
- return nil unless GnipApi.config.debug
72
- request_headers = options[:request_headers]
73
- request_body = options[:request_body]
74
- request_method = options[:request_method]
75
- request_url = options[:request_url]
76
- response_headers = options[:response_headers]
77
- response_status = options[:response_status]
78
- response_body = options[:response_body]
79
- debug_message = "REQUEST/RESPONSE DEBUG\n"
80
- debug_message += "#{request_method} -- #{request_url}\n"
81
- debug_message += "Request Headers:\n"
82
- debug_message += request_headers.map{|k,v| "#{k} -> #{v.join(', ')}"}.join("\n")
83
- debug_message += "\n\nRequest Body:\n"
84
- debug_message += request_body
85
- debug_message += "\n\nResponse Headers:\n"
86
- debug_message += response_headers.map{|k,v| "#{k} -> #{v.join(', ')}"}.join("\n")
87
- debug_message += "\n\nResponse Status: #{response_status}"
88
- # debug_message += "\n\nResponse Body: #{response_body}\n\n"
89
- GnipApi.logger.debug debug_message
90
- return nil
91
- end
92
- end
93
- end
94
- end
@@ -1,65 +0,0 @@
1
- module GnipApi
2
- module Adapters
3
- class HTTPartyAdapter < GnipApi::Adapters::BaseAdapter
4
- def post request
5
- data = HTTParty.post request.uri, :basic_auth => auth, :body => request.payload, :timeout => default_timeout
6
- httparty_debugger(data)
7
- return response(request, data)
8
- end
9
-
10
- def delete request
11
- data = HTTParty.post request.uri, :basic_auth => auth, :body => request.payload, :timeout => default_timeout
12
- httparty_debugger(data)
13
- return response(request, data)
14
- end
15
-
16
- def get request
17
- data = HTTParty.get request.uri, :basic_auth => auth, :timeout => default_timeout
18
- httparty_debugger(data)
19
- return response(request, data)
20
- end
21
-
22
- def stream_get request
23
- begin
24
- HTTParty.get request.uri, :headers => request.headers, :stream_body => true, :basic_auth => auth do |data|
25
- yield(data)
26
- end
27
- rescue Zlib::BufError => error
28
- GnipApi.config.logger.error "STREAM ERROR -> #{error.class} -- #{error.message}\n" + error.backtrace.join("\n")
29
- raise error
30
- end
31
- end
32
-
33
- def auth
34
- {
35
- :username => username,
36
- :password => password
37
- }
38
- end
39
-
40
- def response request, data
41
- create_response request, data.code, data.body, data.headers
42
- end
43
-
44
- private
45
- def debug_data data
46
- {
47
- :request_headers => data.request.instance_variable_get(:@raw_request).to_hash,
48
- :request_body => data.request.instance_variable_get(:@raw_request).body,
49
- :request_method => data.request.http_method.to_s,
50
- :request_url => data.request.path.to_s,
51
- :response_headers => data.headers,
52
- :response_status => data.code,
53
- :response_body => data.body
54
- }
55
- end
56
-
57
- def httparty_debugger data
58
- return nil unless GnipApi.config.debug
59
- debug_request(debug_data(data))
60
- return nil
61
- end
62
-
63
- end
64
- end
65
- end
@@ -1,38 +0,0 @@
1
- module GnipApi
2
- module Apis
3
- module PowerTrack
4
- class Buffer
5
- attr_reader :terminator, :data
6
-
7
- def initialize options={}
8
- @terminator = options.delete(:terminator) || "\r\n"
9
- @data = ""
10
- end
11
-
12
- def size
13
- @data.size
14
- end
15
-
16
- def insert! chunk
17
- @data << chunk
18
- end
19
-
20
- def read!
21
- objects = @data.split(terminator)[0..-2]
22
- unless objects.empty?
23
- # Get the number of chars to read from buffer, counting
24
- # the size of each splited chunk plus the number of chunks by
25
- # terminator size, since it's still present in the buffer
26
- size = objects.map(&:size).reduce(:+) + objects.size * terminator.size
27
- consume!(size)
28
- end
29
- return objects
30
- end
31
-
32
- def consume! chars
33
- @data[0..chars-1] = ''
34
- end
35
- end
36
- end
37
- end
38
- end
@@ -1,33 +0,0 @@
1
- module GnipApi
2
- module Apis
3
- module PowerTrack
4
- class Rule
5
- attr_accessor :value, :tag, :id
6
-
7
- def initialize params={}
8
- @value = params[:value] || params['value']
9
- @tag = params[:tag] || params['tag']
10
- @id = params[:id] || params['id']
11
- end
12
-
13
- def to_json
14
- attributes.to_json
15
- end
16
-
17
- def attributes
18
- attrs = {}
19
- attrs[:value] = @value if @value
20
- attrs[:tag] = @tag if @tag
21
- attrs[:id] = @id if @id
22
- attrs
23
- end
24
-
25
- def uid
26
- rule = @value
27
- rule += "tag:#{@tag}" if @tag
28
- Digest::SHA2.hexdigest(rule)
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,8 +0,0 @@
1
- module GnipApi
2
- module Apis
3
- module PowerTrack
4
- class RuleValidator
5
- end
6
- end
7
- end
8
- end
@@ -1,83 +0,0 @@
1
- # Gnip PowerTrack Rules API
2
- #
3
- # Create, delete and list rules of a powetrack stream.
4
-
5
- module GnipApi
6
- module Apis
7
- module PowerTrack
8
- class Rules
9
- attr_reader :adapter
10
-
11
- # In order to do any operation, you need to specify:
12
- # - label: the label of your stream
13
- # - source: which data source to use (I think only twitter is available)
14
- def initialize params={}
15
- @adapter = GnipApi::Adapter.new
16
- @label = params[:label] || GnipApi.config.label
17
- end
18
-
19
- # Returns an array of defined rules
20
- def list
21
- request = create_get_request
22
- rules = adapter.get(request)
23
- parse_rules(rules)
24
- end
25
-
26
- # Creates the specified rule. Parameters:
27
- # - rules: GnipApi::Apis::PowerTrack::Rule object
28
- def create rules
29
- raise GnipApi::Errors::PowerTrack::MissingRules.new if rules.nil? || rules.empty?
30
- request = create_post_request(construct_rules(rules))
31
- response = adapter.post(request)
32
- return true if response.nil?
33
- return GnipApi::JsonParser.new.parse(response)
34
- end
35
-
36
- # Deletes the specified rule. Parameters:
37
- # - rules: GnipApi::Apis::PowerTrack::Rule object
38
- def delete rules
39
- raise GnipApi::Errors::PowerTrack::MissingRules.new if rules.nil? || rules.empty?
40
- request = create_delete_request(construct_rules(rules))
41
- response = adapter.delete(request)
42
- return true if response.nil?
43
- return GnipApi::JsonParser.new.parse(response)
44
- end
45
-
46
- # Parses an array of GnipApi::Apis::PowerTrack::Rule objects
47
- # to the necesary JSON format for the endpoint
48
- def construct_rules rules
49
- parsed_rules = {:rules => []}
50
- rules.each do |rule|
51
- parsed_rules[:rules] << rule.attributes
52
- end
53
- parsed_rules.to_json
54
- end
55
-
56
- def parse_rules data
57
- parsed_data = GnipApi::JsonParser.new.parse(data)
58
- parsed_data['rules'].map{|rule| GnipApi::Apis::PowerTrack::Rule.new(:value => rule['value'], :tag => rule['tag'], :id => rule['id'])}
59
- end
60
-
61
- private
62
- def endpoint
63
- GnipApi::Endpoints.powertrack_rules(@label)
64
- end
65
-
66
- def create_get_request
67
- GnipApi::Request.new_get(endpoint)
68
- end
69
-
70
- def create_post_request payload
71
- GnipApi::Request.new_post(endpoint, payload)
72
- end
73
-
74
- def create_delete_request payload
75
- delete_url = endpoint
76
- delete_url.query = '_method=delete'
77
- GnipApi::Request.new_delete(delete_url, payload)
78
- end
79
-
80
- end
81
- end
82
- end
83
- end
@@ -1,84 +0,0 @@
1
- module GnipApi
2
- module Apis
3
- module PowerTrack
4
- class Stream
5
- attr_reader :adapter
6
-
7
- def initialize params = {}
8
- @stream = params[:stream] || GnipApi.config.label
9
- @output_format = GnipApi.config.stream_output_format
10
- raise GnipApi::Errors::Configuration::InvalidOutputFormat unless GnipApi::Configuration::OUTPUT_FORMATS.include?(@output_format)
11
- set_config
12
- end
13
-
14
- def logger
15
- GnipApi.logger
16
- end
17
-
18
- def consume
19
- request = create_request
20
- adapter.stream_get request do |chunk|
21
- @buffer.insert! chunk
22
- begin
23
- yield process_entries(@buffer.read!)
24
- rescue Exception => e
25
- puts e.class
26
- puts e.message
27
- puts e.backtrace[0..10].join("\n")
28
- raise e
29
- end
30
- end
31
- end
32
-
33
- def process_entries entries
34
- return entries if @output_format == :json
35
- return entries.map{|e| parse_json(e)}.compact if @output_format == :parsed_json
36
- data = entries.map{|e| parse_json(e)}.compact
37
- data.map!{|e| build_message(e)}
38
- log_system_messages(data)
39
- return data
40
- end
41
-
42
- def log_system_messages entries
43
- entries.select{|message| message.system_message? }.each do |system_message|
44
- GnipApi.logger.send(system_message.log_method, system_message.message)
45
- end
46
- end
47
-
48
- def build_message params
49
- Gnip::Message.build(params)
50
- end
51
-
52
- def parse_json json
53
- begin
54
- GnipApi::JsonParser.new.parse json
55
- rescue GnipApi::Errors::JsonParser::ParseError
56
- nil
57
- end
58
- end
59
-
60
- private
61
- def create_request
62
- headers = {}
63
- headers['Accept-Encoding'] = 'gzip' if GnipApi.config.enable_gzip
64
- headers['Accept-Encoding'] ||= 'json'
65
- GnipApi::Request.new_get(endpoint, headers)
66
- end
67
-
68
- def set_config
69
- raise 'MissingStream' if @stream.nil?
70
- @user = GnipApi.configuration.user
71
- @password = GnipApi.configuration.password
72
- @account = GnipApi.configuration.account
73
- @adapter = GnipApi::Adapter.new
74
- @buffer = GnipApi::Apis::PowerTrack::Buffer.new
75
- end
76
-
77
- def endpoint
78
- GnipApi::Endpoints.powertrack_stream(@stream)
79
- end
80
-
81
- end
82
- end
83
- end
84
- end
@@ -1,109 +0,0 @@
1
- # Gnip Search Full Archive API
2
- #
3
- # Retrive counts with a provided rule
4
-
5
- module GnipApi
6
- module Apis
7
- class Search
8
- attr_reader :adapter
9
-
10
- def initialize params={}
11
- @adapter = GnipApi::Adapter.new
12
- @label = params[:label] || GnipApi.config.label
13
- end
14
-
15
- def activities options={}
16
- required_options?(options)
17
- payload = construct_activities_payload(options)
18
- request = GnipApi::Request.new_post(activities_endpoint, payload)
19
- data = adapter.post(request)
20
- return parse_activities_response(data)
21
- end
22
-
23
- def counts options={}
24
- required_options?(options)
25
- payload = construct_counts_payload(options)
26
- request = GnipApi::Request.new_post(count_endpoint, payload)
27
- data = adapter.post(request)
28
- return parse_counts_response(data)
29
- end
30
-
31
- private
32
- def count_endpoint
33
- GnipApi::Endpoints.search_counts(@label)
34
- end
35
-
36
- def activities_endpoint
37
- GnipApi::Endpoints.search_activities(@label)
38
- end
39
-
40
- def required_options
41
- [:rule]
42
- end
43
-
44
- def required_options? options
45
- provided_options = required_options - options.keys
46
- raise GnipApi::Errors::Search::MissingParameters.new(provided_options) if provided_options.any?
47
- end
48
-
49
- def parse_date date
50
- return nil unless date
51
- date.strftime('%Y%m%d%H%M')
52
- end
53
-
54
- def parse_counts_response data
55
- parsed_data = GnipApi::JsonParser.new.parse(data)
56
- result_set = parsed_data['results']
57
- params = parsed_data['requestParameters']
58
- result = {:results => [], :total_count => parsed_data['totalCount'], :next => parsed_data['next'], :request_parameters => {}}
59
- result[:request_parameters][:bucket] = params['bucket'] if params['bucket']
60
- result[:request_parameters][:from_date] = Time.parse("#{params['fromDate']}-0000") if params['fromDate']
61
- result[:request_parameters][:to_date] = Time.parse("#{params['toDate']}-0000") if params['toDate']
62
- result_set.each do |item|
63
- result[:results] << {:time_period => Time.parse("#{item['timePeriod']}-0000"), :count => item['count']}
64
- end
65
- return result
66
- end
67
-
68
- def parse_activities_response data
69
- parsed_data = GnipApi::JsonParser.new.parse(data)
70
- result_set = parsed_data['results']
71
- params = parsed_data['requestParameters']
72
- result = {:results => [], :next => parsed_data['next'], :request_parameters => {}}
73
- result[:request_parameters][:bucket] = params['bucket'] if params['bucket']
74
- result[:request_parameters][:from_date] = Time.parse("#{params['fromDate']}-0000") if params['fromDate']
75
- result[:request_parameters][:to_date] = Time.parse("#{params['toDate']}-0000") if params['toDate']
76
- result[:request_parameters][:max_results] = params['maxResults'] if params['maxResult']
77
- result_set.each do |item|
78
- result[:results] << Gnip::Activity.new(item)
79
- end
80
- return result
81
- end
82
-
83
- def construct_counts_payload options
84
- payload = {
85
- :query => options[:rule].value,
86
- :fromDate => parse_date(options[:from_date]),
87
- :toDate => parse_date(options[:to_date]),
88
- :bucket => options[:bucket],
89
- :next => options[:next_token]
90
- }
91
- payload.delete_if{|k,v| v.nil?}
92
- return payload.to_json
93
- end
94
-
95
- def construct_activities_payload options
96
- payload = {
97
- :query => options[:rule].value,
98
- :fromDate => parse_date(options[:from_date]),
99
- :toDate => parse_date(options[:to_date]),
100
- :tag => options[:rule].tag,
101
- :maxResults => options[:max_results],
102
- :next => options[:next_token]
103
- }
104
- payload.delete_if{|k,v| v.nil?}
105
- return payload.to_json
106
- end
107
- end
108
- end
109
- end
File without changes
File without changes