gnip-stream 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.gitmodules +3 -0
- data/README.md +1 -0
- data/gnip-stream.gemspec +3 -3
- data/lib/gnip-stream/facebook_client.rb +2 -1
- data/lib/gnip-stream/powertrack_client.rb +2 -12
- data/lib/gnip-stream/stream.rb +3 -1
- data/lib/gnip-stream/version.rb +1 -1
- data/spec/gnip-stream/powertrack_client_spec.rb +2 -21
- metadata +48 -48
- data/lib/gnip-stream/powertrack_authentication.rb +0 -27
- data/spec/gnip-stream/powertrack_authentication_spec.rb +0 -34
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2a44363dec5f30d5653aa57acbc5c8ca83163829
|
4
|
+
data.tar.gz: 897cb6a887bca7d7190b0cf23b7e52a71a49f176
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9bb28a5bbcce731be4806b40a5c0bd95b9b08ab0653767dbeda4ebf1b370014ed212f8d27724b69c1c8c6739027584cfc331d2756c294f955b7109745ae6f1e6
|
7
|
+
data.tar.gz: 078d8c413a644f4b35a240a8596ea65f83d8c95a52108929c469b6c02bcc4f80e033996bf725ffc4d223a7a5b59b1cbfe980f2285e12379a530f04f4c3250993
|
data/.gitmodules
ADDED
data/README.md
CHANGED
@@ -37,6 +37,7 @@ end
|
|
37
37
|
|
38
38
|
* [Ryan Weald](https://github.com/rweald)
|
39
39
|
* [Sharethrough Team](https://github.com/sharethrough)
|
40
|
+
* [Eric Wendelin](http://eriwen.com)
|
40
41
|
|
41
42
|
##License
|
42
43
|
MIT. See [LICENSE](https://github.com/rweald/gnip-stream/blob/master/LICENSE) file for more details.
|
data/gnip-stream.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ["Ryan Weald"]
|
9
9
|
s.email = ["ryan@weald.com"]
|
10
10
|
s.homepage = "https://github.com/rweald/gnip-stream"
|
11
|
-
s.summary =
|
11
|
+
s.summary = "A library to connect and stream data from the GNIP streaming API"
|
12
12
|
s.description = %q{}
|
13
13
|
|
14
14
|
s.rubyforge_project = "gnip-stream"
|
@@ -16,9 +16,9 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.files = `git ls-files`.split("\n")
|
17
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
-
s.require_paths = ["lib"]
|
19
|
+
s.require_paths = ["lib", "vendor"]
|
20
20
|
|
21
21
|
s.add_development_dependency "rspec"
|
22
22
|
|
23
|
-
s.add_dependency "em-http-request", ">= 1.0.
|
23
|
+
s.add_dependency "em-http-request", ">= 1.0.3"
|
24
24
|
end
|
@@ -1,9 +1,7 @@
|
|
1
|
-
require 'gnip-stream/powertrack_authentication'
|
2
1
|
module GnipStream
|
3
2
|
class PowertrackClient
|
4
3
|
def initialize(url, username, password)
|
5
|
-
@
|
6
|
-
@stream = JsonStream.new(url)
|
4
|
+
@stream = JsonStream.new(url, {'authorization' => [username, password], 'accept-encoding' => 'gzip, compressed'})
|
7
5
|
@error_handler = ErrorReconnect.new(self, :consume)
|
8
6
|
@connection_close_handler = ErrorReconnect.new(self, :consume)
|
9
7
|
configure_handlers
|
@@ -15,17 +13,9 @@ module GnipStream
|
|
15
13
|
end
|
16
14
|
|
17
15
|
def consume(&block)
|
18
|
-
@client_callback = block
|
16
|
+
@client_callback = block if block
|
19
17
|
@stream.on_message(&@client_callback)
|
20
|
-
authenticate
|
21
18
|
@stream.connect
|
22
19
|
end
|
23
|
-
|
24
|
-
def authenticate
|
25
|
-
@authentication.authenticate
|
26
|
-
@stream.url = @authentication.location
|
27
|
-
@stream.headers = {"cookie" => @authentication.cookies}
|
28
|
-
end
|
29
|
-
|
30
20
|
end
|
31
21
|
end
|
data/lib/gnip-stream/stream.rb
CHANGED
@@ -3,6 +3,8 @@ require 'em-http-request'
|
|
3
3
|
|
4
4
|
module GnipStream
|
5
5
|
class Stream
|
6
|
+
|
7
|
+
EventMachine.threadpool_size = 3
|
6
8
|
|
7
9
|
attr_accessor :headers, :options, :url, :username, :password
|
8
10
|
|
@@ -26,7 +28,7 @@ module GnipStream
|
|
26
28
|
|
27
29
|
def connect
|
28
30
|
EM.run do
|
29
|
-
http = EM::HttpRequest.new(@url, :inactivity_timeout =>
|
31
|
+
http = EM::HttpRequest.new(@url, :inactivity_timeout => 2**16, :connection_timeout => 2**16).get(:head => @headers)
|
30
32
|
http.stream { |chunk| process_chunk(chunk) }
|
31
33
|
http.callback {
|
32
34
|
handle_connection_close(http)
|
data/lib/gnip-stream/version.rb
CHANGED
@@ -3,46 +3,27 @@ require 'gnip-stream/powertrack_client'
|
|
3
3
|
|
4
4
|
describe GnipStream::PowertrackClient do
|
5
5
|
let(:fake_stream) { double("GnipStream::JsonStream").as_null_object }
|
6
|
-
let(:fake_auth) { double("GnipStream::PowertrackAuthentication").as_null_object }
|
7
6
|
before do
|
8
7
|
GnipStream::JsonStream.stub(:new => fake_stream)
|
9
|
-
GnipStream::PowertrackAuthentication.stub(:new => fake_auth)
|
10
8
|
end
|
11
9
|
|
12
10
|
subject { GnipStream::PowertrackClient.new("http://example.com", "user", "password") }
|
13
11
|
|
14
12
|
describe "#initialize" do
|
15
|
-
it "initializes a PowertrackAuthentication instance" do
|
16
|
-
GnipStream::PowertrackAuthentication.should_receive(:new)
|
17
|
-
subject
|
18
|
-
end
|
19
|
-
|
20
13
|
it "initializes an instance JsonStream" do
|
21
|
-
GnipStream::JsonStream.should_receive(:new)
|
14
|
+
GnipStream::JsonStream.should_receive(:new)
|
22
15
|
subject
|
23
16
|
end
|
24
17
|
end
|
25
18
|
|
26
19
|
describe "configure_handlers" do
|
27
20
|
it "sets up the appropriate error and close handlers" do
|
28
|
-
fake_stream.should_receive(:on_error).twice
|
21
|
+
fake_stream.should_receive(:on_error).twice
|
29
22
|
fake_stream.should_receive(:on_connection_close).twice
|
30
23
|
subject.configure_handlers
|
31
24
|
end
|
32
25
|
end
|
33
26
|
|
34
|
-
describe "#authenticate" do
|
35
|
-
it "performs the necessary authentication and passes appropriate credentials to stream" do
|
36
|
-
fake_auth.should_receive(:authenticate)
|
37
|
-
fake_auth.should_receive(:location).and_return("http://example.com")
|
38
|
-
fake_auth.should_receive(:cookies).and_return("some cookie")
|
39
|
-
|
40
|
-
fake_stream.should_receive(:url=).with("http://example.com")
|
41
|
-
fake_stream.should_receive(:headers=)
|
42
|
-
subject.authenticate
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
27
|
describe "#consume" do
|
47
28
|
it "setup the client callback" do
|
48
29
|
fake_stream.should_receive(:on_message)
|
metadata
CHANGED
@@ -1,46 +1,49 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: gnip-stream
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
|
-
authors:
|
6
|
+
authors:
|
8
7
|
- Ryan Weald
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
|
12
|
+
date: 2013-10-31 00:00:00 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &70139514960160 !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :development
|
23
16
|
prerelease: false
|
24
|
-
|
25
|
-
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- &id003
|
20
|
+
- ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
type: :development
|
24
|
+
version_requirements: *id001
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
26
|
name: em-http-request
|
27
|
-
requirement: &70139514958620 !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
29
|
-
requirements:
|
30
|
-
- - ! '>='
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 1.0.0
|
33
|
-
type: :runtime
|
34
27
|
prerelease: false
|
35
|
-
|
36
|
-
|
37
|
-
|
28
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.0.3
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id002
|
35
|
+
description: ""
|
36
|
+
email:
|
38
37
|
- ryan@weald.com
|
39
38
|
executables: []
|
39
|
+
|
40
40
|
extensions: []
|
41
|
+
|
41
42
|
extra_rdoc_files: []
|
42
|
-
|
43
|
+
|
44
|
+
files:
|
43
45
|
- .gitignore
|
46
|
+
- .gitmodules
|
44
47
|
- .pryrc
|
45
48
|
- .rvmrc
|
46
49
|
- .travis.yml
|
@@ -54,7 +57,6 @@ files:
|
|
54
57
|
- lib/gnip-stream/error_reconnect.rb
|
55
58
|
- lib/gnip-stream/facebook_client.rb
|
56
59
|
- lib/gnip-stream/json_stream.rb
|
57
|
-
- lib/gnip-stream/powertrack_authentication.rb
|
58
60
|
- lib/gnip-stream/powertrack_client.rb
|
59
61
|
- lib/gnip-stream/stream.rb
|
60
62
|
- lib/gnip-stream/stream_delegate.rb
|
@@ -64,41 +66,39 @@ files:
|
|
64
66
|
- spec/gnip-stream/error_reconnect_spec.rb
|
65
67
|
- spec/gnip-stream/facebook_client_spec.rb
|
66
68
|
- spec/gnip-stream/json_stream_spec.rb
|
67
|
-
- spec/gnip-stream/powertrack_authentication_spec.rb
|
68
69
|
- spec/gnip-stream/powertrack_client_spec.rb
|
69
70
|
- spec/gnip-stream/stream_spec.rb
|
70
71
|
- spec/gnip-stream/xml_stream_spec.rb
|
71
72
|
- spec/spec_helper.rb
|
72
73
|
homepage: https://github.com/rweald/gnip-stream
|
73
74
|
licenses: []
|
75
|
+
|
76
|
+
metadata: {}
|
77
|
+
|
74
78
|
post_install_message:
|
75
79
|
rdoc_options: []
|
76
|
-
|
80
|
+
|
81
|
+
require_paths:
|
77
82
|
- lib
|
78
|
-
|
79
|
-
|
80
|
-
requirements:
|
81
|
-
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
none: false
|
86
|
-
requirements:
|
87
|
-
- - ! '>='
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
83
|
+
- vendor
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- *id003
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- *id003
|
90
90
|
requirements: []
|
91
|
+
|
91
92
|
rubyforge_project: gnip-stream
|
92
|
-
rubygems_version:
|
93
|
+
rubygems_version: 2.0.3
|
93
94
|
signing_key:
|
94
|
-
specification_version:
|
95
|
-
summary:
|
96
|
-
test_files:
|
95
|
+
specification_version: 4
|
96
|
+
summary: A library to connect and stream data from the GNIP streaming API
|
97
|
+
test_files:
|
97
98
|
- spec/gnip-stream/data_buffer_spec.rb
|
98
99
|
- spec/gnip-stream/error_reconnect_spec.rb
|
99
100
|
- spec/gnip-stream/facebook_client_spec.rb
|
100
101
|
- spec/gnip-stream/json_stream_spec.rb
|
101
|
-
- spec/gnip-stream/powertrack_authentication_spec.rb
|
102
102
|
- spec/gnip-stream/powertrack_client_spec.rb
|
103
103
|
- spec/gnip-stream/stream_spec.rb
|
104
104
|
- spec/gnip-stream/xml_stream_spec.rb
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module GnipStream
|
2
|
-
class PowertrackAuthentication
|
3
|
-
attr_accessor :cookies, :location
|
4
|
-
def initialize(url, username, password)
|
5
|
-
@url = url
|
6
|
-
@username = username
|
7
|
-
@password = password
|
8
|
-
end
|
9
|
-
|
10
|
-
def authenticate
|
11
|
-
EM.run do
|
12
|
-
http = EM::HttpRequest.new(@url).get(
|
13
|
-
:head => {"authorization" => [@username, @password]})
|
14
|
-
http.headers { |head| parse_response_header(head) }
|
15
|
-
http.callback { EM.stop }
|
16
|
-
http.error do
|
17
|
-
raise "Gnip Authentication Failed. Reason was #{http.error}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def parse_response_header(header)
|
23
|
-
@location = header["LOCATION"]
|
24
|
-
@cookies = (header["SET_COOKIE"].first.split(";")[0..2].join(";"))
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'gnip-stream/powertrack_authentication'
|
3
|
-
|
4
|
-
describe GnipStream::PowertrackAuthentication do
|
5
|
-
subject { GnipStream::PowertrackAuthentication.new("http://example.com",
|
6
|
-
"user", "password") }
|
7
|
-
describe "#authenticate" do
|
8
|
-
let(:fake_request) { double("fake request") }
|
9
|
-
it "should make a request to the GNIP API to receive access cookie" do
|
10
|
-
EM::HttpRequest.should_receive(:new).with("http://example.com").and_return(fake_request)
|
11
|
-
fake_request.should_receive(:get) do |args|
|
12
|
-
args[:head].should == {'authorization' => ["user", "password"]}
|
13
|
-
EM.stop
|
14
|
-
double.as_null_object
|
15
|
-
end
|
16
|
-
|
17
|
-
subject.authenticate
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "#parse_response_header" do
|
22
|
-
it "should set the stream url based on 'LOCATION' header" do
|
23
|
-
subject.parse_response_header({"SET_COOKIE" => ["session_token=foobar; domain=.gnip.com; path=/;
|
24
|
-
expires=Wed, 13-Jul-2011 22:10:10 GMT _base_session=hello; path=/; HttpOnly"]})
|
25
|
-
subject.cookies.should == "session_token=foobar; domain=.gnip.com; path=/"
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should set the url that we can stream data from" do
|
29
|
-
subject.parse_response_header("LOCATION" => "http://example.com", "SET_COOKIE" => ["session_token=foobar; domain=.gnip.com; path=/;
|
30
|
-
expires=Wed, 13-Jul-2011 22:10:10 GMT _base_session=hello; path=/; HttpOnly"])
|
31
|
-
subject.location.should == "http://example.com"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|