gnip_api 1.2.0 → 1.2.1
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/gnip_api.rb +1 -0
- data/lib/gnip_api/adapter.rb +90 -19
- data/lib/gnip_api/endpoints.rb +15 -7
- data/lib/gnip_api/errors.rb +1 -5
- data/lib/gnip_api/power_track/rules.rb +28 -17
- data/lib/gnip_api/power_track/stream.rb +95 -19
- data/lib/gnip_api/request.rb +19 -1
- data/lib/gnip_api/response.rb +1 -1
- data/lib/gnip_api/search.rb +8 -11
- data/lib/gnip_api/version.rb +1 -1
- data/spec/gnip_api/endpoints_spec.rb +6 -8
- data/spec/gnip_api/power_track/rules_spec.rb +4 -4
- data/spec/gnip_api/search_spec.rb +2 -2
- metadata +2 -3
- data/lib/gnip_api/power_track/rule_validator.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5beeb3c15e9e6e05694dbcb5e5ddc8bce5985659
|
4
|
+
data.tar.gz: 36c3b182f4d95e503c0963a0859c6d3b3c57a4ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cac268d5f61308340ad2f391f007684e4b0276eea9202dce3dc61d8871b81bc8ed6b2d62157617a3709446e9dd2fd661e4fffd6d44e818d1526d0017b2f5f869
|
7
|
+
data.tar.gz: ed8da7a8e75e2d5f68ea75c95d59a7598cf37427c39862a5dd0027e8bda8f80233b21e0ecffe0691b84656852f93bf5503ffab2ff74a924bf3c7a103cc3797a5
|
data/Gemfile.lock
CHANGED
data/lib/gnip_api.rb
CHANGED
data/lib/gnip_api/adapter.rb
CHANGED
@@ -1,4 +1,33 @@
|
|
1
1
|
module GnipApi
|
2
|
+
# The interface to the world. Wraps the net adapter of choice and exposes common methods
|
3
|
+
# for the rest of the classes to use, abstracting details of the request/response.
|
4
|
+
# A note on the data:
|
5
|
+
# HTTParty was selected over Excon for the simple reason that Excon doesn't handle
|
6
|
+
# GZip responses. HTTParty uses net/http under the hood and handles this as expected.
|
7
|
+
# However, for reasons I don't know at this point, the Zlib responsible of inflating
|
8
|
+
# the GZip compressed data waits to fill in a buffer in order to return a decompressed
|
9
|
+
# chunk. You can test this on a farily busy stream and you'll see that all chunks you
|
10
|
+
# receive decompressed are almsot always 16384 bytes. Additionally, the \r\n Gnip sends
|
11
|
+
# as a keep alive signal seems to be buffered further.
|
12
|
+
# As a result I expose 2 additional methods for consuming the stream that uses Curl
|
13
|
+
# instead. Curl handles the GZip data better. You can launch it in a shell and the
|
14
|
+
# keep alive signals are properly there.
|
15
|
+
# These alternatives are a bit of a cheat, but allows delegation of handling the actual
|
16
|
+
# connection and the GZip data.
|
17
|
+
#
|
18
|
+
# #stream_get will work as usual, using HTTParty and Net::HTTP stuff.
|
19
|
+
#
|
20
|
+
# #io_curl_stream will launch a subprocess and capture output with IO.popen. This method
|
21
|
+
# behaves similarly to #stream_get regarding the keep alive signals. However, these are
|
22
|
+
# returned all at once when a bigger chunk of data is sent over the stream. Still, it reads
|
23
|
+
# them well and can be handled.
|
24
|
+
#
|
25
|
+
# #pty_curl_stream is different. Using the PTY features, a shell is opened and the output
|
26
|
+
# captured is as (in my opinion) should be. All keep-alive signals are returned when received
|
27
|
+
# with no wait at all.
|
28
|
+
#
|
29
|
+
# All this will remain experimental until tested on a real environment. I recomment to use
|
30
|
+
# #stream_get which was already tested and works as expected.
|
2
31
|
class Adapter
|
3
32
|
GET = 'GET'
|
4
33
|
POST = 'POST'
|
@@ -13,30 +42,21 @@ module GnipApi
|
|
13
42
|
end
|
14
43
|
|
15
44
|
def get request
|
16
|
-
request
|
17
|
-
data = HTTParty.get request.uri,
|
18
|
-
|
19
|
-
response.check_for_errors!
|
20
|
-
return response.body unless response.body.empty?
|
21
|
-
return true
|
45
|
+
options = default_options(request)
|
46
|
+
data = HTTParty.get request.uri, options
|
47
|
+
create_response(request, data.code, data.body, data.headers)
|
22
48
|
end
|
23
49
|
|
24
50
|
def post request
|
25
|
-
request
|
26
|
-
data = HTTParty.post request.uri,
|
27
|
-
|
28
|
-
response.check_for_errors!
|
29
|
-
return response.body unless response.body.empty?
|
30
|
-
return true
|
51
|
+
options = default_options(request)
|
52
|
+
data = HTTParty.post request.uri, options
|
53
|
+
create_response(request, data.code, data.body, data.headers)
|
31
54
|
end
|
32
55
|
|
33
56
|
def delete request
|
34
|
-
request
|
35
|
-
data = HTTParty.post request.uri,
|
36
|
-
|
37
|
-
response.check_for_errors!
|
38
|
-
return response.body unless response.body.empty?
|
39
|
-
return true
|
57
|
+
options = default_options(request)
|
58
|
+
data = HTTParty.post request.uri, options
|
59
|
+
create_response(request, data.code, data.body, data.headers)
|
40
60
|
end
|
41
61
|
|
42
62
|
def stream_get request
|
@@ -46,12 +66,63 @@ module GnipApi
|
|
46
66
|
yield(data)
|
47
67
|
end
|
48
68
|
rescue Zlib::BufError => error
|
49
|
-
|
69
|
+
logger.error "STREAM ERROR -> #{error.class} -- #{error.message}\n" + error.backtrace.join("\n")
|
50
70
|
raise error
|
51
71
|
end
|
52
72
|
end
|
53
73
|
|
74
|
+
def io_curl_stream request
|
75
|
+
request.log!
|
76
|
+
auth_header = "Authorization: Basic #{base64_auth}"
|
77
|
+
cmd = "curl --compressed -s --header \"#{auth_header}\" \"#{request.uri}\""
|
78
|
+
begin
|
79
|
+
IO.popen(cmd) do |io|
|
80
|
+
while line = io.gets.strip do
|
81
|
+
logger.info "Keep alive received" if line == ''
|
82
|
+
next if line == ''
|
83
|
+
yield(line)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
ensure
|
87
|
+
logger.warn "Stream closed"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def pty_curl_stream request
|
92
|
+
request.log!
|
93
|
+
auth_header = "Authorization: Basic #{base64_auth}"
|
94
|
+
cmd = "curl --compressed -s --header \"#{auth_header}\" \"#{request.uri}\""
|
95
|
+
begin
|
96
|
+
PTY.spawn(cmd) do |stdout, stdin, pid|
|
97
|
+
begin
|
98
|
+
stdout.each do |line|
|
99
|
+
logger.info "Keep alive received" if line.strip == ''
|
100
|
+
next if line.strip == ''
|
101
|
+
yield(line.strip)
|
102
|
+
end
|
103
|
+
rescue Errno::EIO
|
104
|
+
end
|
105
|
+
end
|
106
|
+
rescue PTY::ChildExited
|
107
|
+
logger.warn "Stream closed"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
54
111
|
private
|
112
|
+
def default_options request
|
113
|
+
{
|
114
|
+
:headers => request.headers,
|
115
|
+
:basic_auth => auth,
|
116
|
+
:timeout => default_timeout,
|
117
|
+
:debug_output => (debug ? logger : nil),
|
118
|
+
:body => request.payload
|
119
|
+
}.delete_if{|k,v| v.nil? || v == ''}
|
120
|
+
end
|
121
|
+
|
122
|
+
def base64_auth
|
123
|
+
Base64.encode64("#{auth[:username]}:#{auth[:password]}").strip
|
124
|
+
end
|
125
|
+
|
55
126
|
def auth
|
56
127
|
{
|
57
128
|
:username => username,
|
data/lib/gnip_api/endpoints.rb
CHANGED
@@ -1,31 +1,35 @@
|
|
1
1
|
module GnipApi
|
2
2
|
class Endpoints
|
3
3
|
class << self
|
4
|
-
def
|
4
|
+
def powertrack_rule_validator
|
5
|
+
URI("https://gnip-api.twitter.com/rules/powertrack/accounts/#{account}/publishers/twitter/#{label}/validation.json")
|
6
|
+
end
|
7
|
+
|
8
|
+
def powertrack_rules
|
5
9
|
URI("https://gnip-api.twitter.com/rules/powertrack/accounts/#{account}/publishers/twitter/#{label}.json")
|
6
10
|
end
|
7
11
|
|
8
|
-
def powertrack_stream
|
12
|
+
def powertrack_stream
|
9
13
|
URI("https://gnip-stream.twitter.com/stream/powertrack/accounts/#{account}/publishers/twitter/#{label}.json")
|
10
14
|
end
|
11
15
|
|
12
|
-
def powertrack_rule_validator
|
16
|
+
def powertrack_rule_validator
|
13
17
|
URI("https://gnip-api.twitter.com/rules/powertrack/accounts/#{account}/publishers/twitter/#{label}/validation.json")
|
14
18
|
end
|
15
19
|
|
16
|
-
def powertrack_stream_replay
|
20
|
+
def powertrack_stream_replay
|
17
21
|
URI("https://gnip-stream.twitter.com/replay/powertrack/accounts/#{account}/publishers/twitter/#{label}.json")
|
18
22
|
end
|
19
23
|
|
20
|
-
def powertrack_rule_replay
|
24
|
+
def powertrack_rule_replay
|
21
25
|
URI("https://gnip-api.twitter.com/rules/powertrack-replay/accounts/#{account}/publishers/twitter/#{label}.json")
|
22
26
|
end
|
23
27
|
|
24
|
-
def search_activities
|
28
|
+
def search_activities
|
25
29
|
URI("https://gnip-api.twitter.com/search/fullarchive/accounts/#{account}/#{label}.json")
|
26
30
|
end
|
27
31
|
|
28
|
-
def search_counts
|
32
|
+
def search_counts
|
29
33
|
URI("https://gnip-api.twitter.com/search/fullarchive/accounts/#{account}/#{label}/counts.json")
|
30
34
|
end
|
31
35
|
|
@@ -33,6 +37,10 @@ module GnipApi
|
|
33
37
|
def account
|
34
38
|
GnipApi.configuration.account
|
35
39
|
end
|
40
|
+
|
41
|
+
def label
|
42
|
+
GnipApi.configuration.label
|
43
|
+
end
|
36
44
|
end
|
37
45
|
end
|
38
46
|
end
|
data/lib/gnip_api/errors.rb
CHANGED
@@ -14,11 +14,7 @@ module GnipApi
|
|
14
14
|
end
|
15
15
|
|
16
16
|
module Adapter
|
17
|
-
class RequestError < StandardError
|
18
|
-
def initialize msg='Request failed'
|
19
|
-
@message = msg
|
20
|
-
end
|
21
|
-
end
|
17
|
+
class RequestError < StandardError; end
|
22
18
|
|
23
19
|
class RateLimitError < StandardError
|
24
20
|
def initialize msg='Exceded rate limits'
|
@@ -5,29 +5,19 @@
|
|
5
5
|
module GnipApi
|
6
6
|
module PowerTrack
|
7
7
|
class Rules
|
8
|
-
attr_reader :adapter
|
9
|
-
|
10
|
-
# In order to do any operation, you need to specify:
|
11
|
-
# - label: the label of your stream
|
12
|
-
# - source: which data source to use (I think only twitter is available)
|
13
|
-
def initialize params={}
|
14
|
-
@adapter = GnipApi::Adapter.new
|
15
|
-
@label = params[:label] || GnipApi.config.label
|
16
|
-
end
|
17
|
-
|
18
8
|
# Returns an array of defined rules
|
19
9
|
def list
|
20
10
|
request = create_get_request
|
21
|
-
rules =
|
11
|
+
rules = fetch_data(request)
|
22
12
|
parse_rules(rules)
|
23
13
|
end
|
24
14
|
|
25
15
|
# Creates the specified rule. Parameters:
|
26
16
|
# - rules: GnipApi::PowerTrack::Rule object
|
27
17
|
def create rules
|
28
|
-
raise
|
18
|
+
raise ArgumentError.new('No rules provided') if rules.nil? || rules.empty?
|
29
19
|
request = create_post_request(construct_rules(rules))
|
30
|
-
response =
|
20
|
+
response = fetch_data(request)
|
31
21
|
return true if response.nil?
|
32
22
|
return GnipApi::JsonParser.new.parse(response)
|
33
23
|
end
|
@@ -35,9 +25,18 @@ module GnipApi
|
|
35
25
|
# Deletes the specified rule. Parameters:
|
36
26
|
# - rules: GnipApi::PowerTrack::Rule object
|
37
27
|
def delete rules
|
38
|
-
raise
|
28
|
+
raise ArgumentError.new('No rules provided') if rules.nil? || rules.empty?
|
39
29
|
request = create_delete_request(construct_rules(rules))
|
40
|
-
response =
|
30
|
+
response = fetch_data(request)
|
31
|
+
return true if response.nil?
|
32
|
+
return GnipApi::JsonParser.new.parse(response)
|
33
|
+
end
|
34
|
+
|
35
|
+
def validate rules
|
36
|
+
raise ArgumentError.new('No rules provided') if rules.nil? || rules.empty?
|
37
|
+
byebug
|
38
|
+
request = create_validation_request(construct_rules(rules))
|
39
|
+
response = fetch_data(request)
|
41
40
|
return true if response.nil?
|
42
41
|
return GnipApi::JsonParser.new.parse(response)
|
43
42
|
end
|
@@ -58,8 +57,20 @@ module GnipApi
|
|
58
57
|
end
|
59
58
|
|
60
59
|
private
|
60
|
+
def fetch_data(request)
|
61
|
+
request.execute!
|
62
|
+
end
|
63
|
+
|
61
64
|
def endpoint
|
62
|
-
GnipApi::Endpoints.powertrack_rules
|
65
|
+
GnipApi::Endpoints.powertrack_rules
|
66
|
+
end
|
67
|
+
|
68
|
+
def validation_endpoint
|
69
|
+
GnipApi::Endpoints.powertrack_rule_validator
|
70
|
+
end
|
71
|
+
|
72
|
+
def create_validation_request payload
|
73
|
+
GnipApi::Request.new_post(validation_endpoint, payload)
|
63
74
|
end
|
64
75
|
|
65
76
|
def create_get_request
|
@@ -73,7 +84,7 @@ module GnipApi
|
|
73
84
|
def create_delete_request payload
|
74
85
|
delete_url = endpoint
|
75
86
|
delete_url.query = '_method=delete'
|
76
|
-
GnipApi::Request.
|
87
|
+
GnipApi::Request.new_post(delete_url, payload)
|
77
88
|
end
|
78
89
|
|
79
90
|
end
|
@@ -1,13 +1,10 @@
|
|
1
1
|
module GnipApi
|
2
2
|
module PowerTrack
|
3
3
|
class Stream
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
@
|
8
|
-
@user = params[:user] || GnipApi.configuration.user
|
9
|
-
@password = params[:password] || GnipApi.configuration.password
|
10
|
-
@account = params[:account] || GnipApi.configuration.account
|
4
|
+
def initialize
|
5
|
+
@user = GnipApi.configuration.user
|
6
|
+
@password = GnipApi.configuration.password
|
7
|
+
@account = GnipApi.configuration.account
|
11
8
|
@adapter = GnipApi::Adapter.new
|
12
9
|
@buffer = GnipApi::PowerTrack::Buffer.new
|
13
10
|
@running = false
|
@@ -41,21 +38,100 @@ module GnipApi
|
|
41
38
|
end
|
42
39
|
end
|
43
40
|
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
# The following methods are different ways of consuming the stream
|
42
|
+
# There are 3 different methods that return data slighly different.
|
43
|
+
# :common method uses a simple HTTParty request reading chunks and
|
44
|
+
# decoding the GZip. This method has a flaw that it waits for certain
|
45
|
+
# data to be buffered by Zlib in order to return a decoded chunk.
|
46
|
+
# :common will return chunks that may contain more than 1 objects.
|
47
|
+
#
|
48
|
+
# :io method uses curl under the hood, in combination with IO.popen
|
49
|
+
# to captrue stdout. For this method a single line is returned, which
|
50
|
+
# would be an object sent to stream. Curl handles the GZip decoding
|
51
|
+
# better, however the read method for the IO buffers up the keep alive
|
52
|
+
# signals due to not flushing STDOUT.
|
53
|
+
#
|
54
|
+
# :pty method is an alternative for :io in where the stdout output
|
55
|
+
# is captured as it comes using PTY features. It almost works the
|
56
|
+
# same as :io, but the keep alive signals are now captured properly.
|
57
|
+
def consume stream_method=:common
|
58
|
+
raise ArgumentError, "Block required, non given" unless block_given?
|
59
|
+
if stream_method == :common
|
60
|
+
read_stream do |data|
|
61
|
+
yield(process_entries(data))
|
62
|
+
end
|
63
|
+
elsif stream_method == :io
|
64
|
+
read_io_stream do |data|
|
65
|
+
yield(process_entries([data]))
|
66
|
+
end
|
67
|
+
elsif stream_method == :pty
|
68
|
+
read_pty_stream do |data|
|
69
|
+
yield(process_entries([data]))
|
70
|
+
end
|
71
|
+
else
|
72
|
+
raise ArgumentError, "Undefined stream method #{stream_method}"
|
47
73
|
end
|
48
74
|
end
|
49
75
|
|
50
|
-
def consume_raw
|
51
|
-
|
52
|
-
|
76
|
+
def consume_raw stream_method=:common
|
77
|
+
raise ArgumentError, "Block required, non given" unless block_given?
|
78
|
+
if stream_method == :common
|
79
|
+
read_stream do |data|
|
80
|
+
yield(data)
|
81
|
+
end
|
82
|
+
elsif stream_method == :io
|
83
|
+
read_io_stream do |data|
|
84
|
+
yield(data)
|
85
|
+
end
|
86
|
+
elsif stream_method == :pty
|
87
|
+
read_pty_stream do |data|
|
88
|
+
yield(data)
|
89
|
+
end
|
90
|
+
else
|
91
|
+
raise ArgumentError, "Undefined stream method #{stream_method}"
|
53
92
|
end
|
54
93
|
end
|
55
94
|
|
56
|
-
def consume_json
|
57
|
-
|
58
|
-
|
95
|
+
def consume_json stream_method=:common
|
96
|
+
raise ArgumentError, "Block required, non given" unless block_given?
|
97
|
+
if stream_method == :common
|
98
|
+
read_stream do |data|
|
99
|
+
yield(data.map{|item| parse_json(item)})
|
100
|
+
end
|
101
|
+
elsif stream_method == :io
|
102
|
+
read_io_stream do |data|
|
103
|
+
yield(parse_json(data))
|
104
|
+
end
|
105
|
+
elsif stream_method == :pty
|
106
|
+
read_pty_stream do |data|
|
107
|
+
yield(parse_json(data))
|
108
|
+
end
|
109
|
+
else
|
110
|
+
raise ArgumentError, "Undefined stream method #{stream_method}"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def read_io_stream
|
115
|
+
request = create_request
|
116
|
+
logger.info "Opening PowerTrack parsed stream"
|
117
|
+
begin
|
118
|
+
@adapter.io_curl_stream(request) do |data|
|
119
|
+
yield data
|
120
|
+
end
|
121
|
+
ensure
|
122
|
+
logger.warn "Closing stream"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def read_pty_stream
|
127
|
+
request = create_request
|
128
|
+
logger.info "Opening PowerTrack parsed stream"
|
129
|
+
begin
|
130
|
+
@adapter.pty_curl_stream(request) do |data|
|
131
|
+
yield data
|
132
|
+
end
|
133
|
+
ensure
|
134
|
+
logger.warn "Closing stream"
|
59
135
|
end
|
60
136
|
end
|
61
137
|
|
@@ -63,8 +139,8 @@ module GnipApi
|
|
63
139
|
request = create_request
|
64
140
|
logger.info "Opening PowerTrack parsed stream"
|
65
141
|
begin
|
66
|
-
adapter.stream_get request do |chunk|
|
67
|
-
stream_running!
|
142
|
+
@adapter.stream_get request do |chunk|
|
143
|
+
stream_running!(@buffer, chunk)
|
68
144
|
@buffer.insert! chunk
|
69
145
|
yield @buffer.read! if block_given?
|
70
146
|
end
|
@@ -114,7 +190,7 @@ module GnipApi
|
|
114
190
|
end
|
115
191
|
|
116
192
|
def endpoint
|
117
|
-
GnipApi::Endpoints.powertrack_stream
|
193
|
+
GnipApi::Endpoints.powertrack_stream
|
118
194
|
end
|
119
195
|
|
120
196
|
end
|
data/lib/gnip_api/request.rb
CHANGED
@@ -21,6 +21,24 @@ module GnipApi
|
|
21
21
|
@payload = params[:payload]
|
22
22
|
@headers = params[:headers]
|
23
23
|
@request_method = params[:request_method]
|
24
|
+
@adapter = GnipApi::Adapter.new
|
25
|
+
end
|
26
|
+
|
27
|
+
def execute!
|
28
|
+
log!
|
29
|
+
case request_method
|
30
|
+
when GnipApi::Adapter::GET
|
31
|
+
response = @adapter.get(self)
|
32
|
+
when GnipApi::Adapter::POST
|
33
|
+
response = @adapter.post(self)
|
34
|
+
when GnipApi::Adapter::DELETE
|
35
|
+
response = @adapter.delete(self)
|
36
|
+
else
|
37
|
+
raise 'RequestNotAllowed'
|
38
|
+
end
|
39
|
+
response.check_for_errors!
|
40
|
+
return response.body unless response.body.empty?
|
41
|
+
return true
|
24
42
|
end
|
25
43
|
|
26
44
|
def log!
|
@@ -28,6 +46,6 @@ module GnipApi
|
|
28
46
|
GnipApi.logger.debug "Headers -> #{headers.inspect}"
|
29
47
|
GnipApi.logger.debug "Payload -> #{payload.inspect}"
|
30
48
|
end
|
31
|
-
|
49
|
+
|
32
50
|
end
|
33
51
|
end
|
data/lib/gnip_api/response.rb
CHANGED
@@ -48,7 +48,7 @@ module GnipApi
|
|
48
48
|
GnipApi.logger.debug "Request payload -> #{request.payload.inspect}"
|
49
49
|
raise GnipApi::Errors::Adapter::GnipSoftwareError.new error_message if status == 503
|
50
50
|
raise GnipApi::Errors::Adapter::RateLimitError.new error_message if status == 429
|
51
|
-
raise GnipApi::Errors::Adapter::RequestError.new error_message
|
51
|
+
raise GnipApi::Errors::Adapter::RequestError.new("Status #{status} #{error_message}")
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
data/lib/gnip_api/search.rb
CHANGED
@@ -4,18 +4,11 @@
|
|
4
4
|
|
5
5
|
module GnipApi
|
6
6
|
class Search
|
7
|
-
attr_reader :adapter
|
8
|
-
|
9
|
-
def initialize params={}
|
10
|
-
@adapter = GnipApi::Adapter.new
|
11
|
-
@label = params[:label] || GnipApi.config.label
|
12
|
-
end
|
13
|
-
|
14
7
|
def activities options={}
|
15
8
|
required_options?(options)
|
16
9
|
payload = construct_activities_payload(options)
|
17
10
|
request = GnipApi::Request.new_post(activities_endpoint, payload)
|
18
|
-
data =
|
11
|
+
data = fetch_data(request)
|
19
12
|
return parse_activities_response(data)
|
20
13
|
end
|
21
14
|
|
@@ -23,17 +16,21 @@ module GnipApi
|
|
23
16
|
required_options?(options)
|
24
17
|
payload = construct_counts_payload(options)
|
25
18
|
request = GnipApi::Request.new_post(count_endpoint, payload)
|
26
|
-
data =
|
19
|
+
data = fetch_data(request)
|
27
20
|
return parse_counts_response(data)
|
28
21
|
end
|
29
22
|
|
30
23
|
private
|
24
|
+
def fetch_data(request)
|
25
|
+
request.execute!
|
26
|
+
end
|
27
|
+
|
31
28
|
def count_endpoint
|
32
|
-
GnipApi::Endpoints.search_counts
|
29
|
+
GnipApi::Endpoints.search_counts
|
33
30
|
end
|
34
31
|
|
35
32
|
def activities_endpoint
|
36
|
-
GnipApi::Endpoints.search_activities
|
33
|
+
GnipApi::Endpoints.search_activities
|
37
34
|
end
|
38
35
|
|
39
36
|
def required_options
|
data/lib/gnip_api/version.rb
CHANGED
@@ -3,22 +3,20 @@ require 'spec_helper'
|
|
3
3
|
describe GnipApi::Endpoints do
|
4
4
|
before do
|
5
5
|
configure_gem
|
6
|
-
@source = 'somewhere'
|
7
|
-
@label = 'stream'
|
8
6
|
end
|
9
7
|
|
10
8
|
describe '.powertrack_rules' do
|
11
9
|
it 'returns URI object' do
|
12
|
-
expect(GnipApi::Endpoints.powertrack_rules
|
10
|
+
expect(GnipApi::Endpoints.powertrack_rules.kind_of?(URI)).to eq(true)
|
13
11
|
end
|
14
12
|
|
15
13
|
describe 'URI returned' do
|
16
14
|
before do
|
17
|
-
@uri = GnipApi::Endpoints.powertrack_rules
|
15
|
+
@uri = GnipApi::Endpoints.powertrack_rules
|
18
16
|
end
|
19
17
|
|
20
18
|
it 'contains label in path' do
|
21
|
-
expect(@uri.path.include?(
|
19
|
+
expect(@uri.path.include?(GnipApi.configuration.label)).to eq(true)
|
22
20
|
end
|
23
21
|
|
24
22
|
it 'includes account in path' do
|
@@ -29,16 +27,16 @@ describe GnipApi::Endpoints do
|
|
29
27
|
|
30
28
|
describe '.powertrack_stream' do
|
31
29
|
it 'returns URI object' do
|
32
|
-
expect(GnipApi::Endpoints.powertrack_stream
|
30
|
+
expect(GnipApi::Endpoints.powertrack_stream.kind_of?(URI)).to eq(true)
|
33
31
|
end
|
34
32
|
|
35
33
|
describe 'URI returned' do
|
36
34
|
before do
|
37
|
-
@uri = GnipApi::Endpoints.powertrack_stream
|
35
|
+
@uri = GnipApi::Endpoints.powertrack_stream
|
38
36
|
end
|
39
37
|
|
40
38
|
it 'contains label in path' do
|
41
|
-
expect(@uri.path.include?(
|
39
|
+
expect(@uri.path.include?(GnipApi.configuration.label)).to eq(true)
|
42
40
|
end
|
43
41
|
|
44
42
|
it 'includes account in path' do
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe GnipApi::PowerTrack::Rules do
|
4
4
|
before do
|
5
|
-
@api = GnipApi::PowerTrack::Rules.new
|
5
|
+
@api = GnipApi::PowerTrack::Rules.new
|
6
6
|
@rules = [GnipApi::PowerTrack::Rule.new(:value => 'r1', :tag => 't1'),
|
7
7
|
GnipApi::PowerTrack::Rule.new(:value => 'r2')]
|
8
8
|
@json = {:rules => [{:value => 'r1', :tag => 't1'}, {:value => 'r2'}]}.to_json
|
@@ -23,19 +23,19 @@ describe GnipApi::PowerTrack::Rules do
|
|
23
23
|
|
24
24
|
describe '#delete' do
|
25
25
|
it 'raises error if no rules passed' do
|
26
|
-
expect(Proc.new{@api.delete([])}).to raise_error(
|
26
|
+
expect(Proc.new{@api.delete([])}).to raise_error(ArgumentError)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
describe '#create' do
|
31
31
|
it 'raises error if no rules passed' do
|
32
|
-
expect(Proc.new{@api.create([])}).to raise_error(
|
32
|
+
expect(Proc.new{@api.create([])}).to raise_error(ArgumentError)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
describe '#list' do
|
37
37
|
before do
|
38
|
-
|
38
|
+
allow(@api).to receive(:fetch_data).and_return(@json)
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'returns an array' do
|
@@ -13,7 +13,7 @@ describe GnipApi::Search do
|
|
13
13
|
before do
|
14
14
|
@raw_response = File.read(fixture_path.join('search_api/search_counts_response.json'))
|
15
15
|
@api = GnipApi::Search.new
|
16
|
-
allow(@api
|
16
|
+
allow(@api).to receive(:fetch_data).and_return(@raw_response)
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'raises error if missing params' do
|
@@ -66,7 +66,7 @@ describe GnipApi::Search do
|
|
66
66
|
before do
|
67
67
|
@raw_response = File.read(fixture_path.join('search_api/search_activities_response.json'))
|
68
68
|
@api = GnipApi::Search.new
|
69
|
-
allow(@api
|
69
|
+
allow(@api).to receive(:fetch_data).and_return(@raw_response)
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'raises error if missing params' do
|
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.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rayko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -182,7 +182,6 @@ files:
|
|
182
182
|
- lib/gnip_api/json_parser.rb
|
183
183
|
- lib/gnip_api/power_track/buffer.rb
|
184
184
|
- lib/gnip_api/power_track/rule.rb
|
185
|
-
- lib/gnip_api/power_track/rule_validator.rb
|
186
185
|
- lib/gnip_api/power_track/rules.rb
|
187
186
|
- lib/gnip_api/power_track/stream.rb
|
188
187
|
- lib/gnip_api/request.rb
|