gazouillis 0.0.0 → 0.0.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.
- data/lib/gazouillis/stream.rb +46 -11
- data/lib/gazouillis/version.rb +1 -1
- data/lib/gazouillis.rb +1 -0
- metadata +34 -14
data/lib/gazouillis/stream.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module Gazouillis
|
3
|
+
# This class concern is to handle stream connections.
|
4
|
+
#
|
3
5
|
class Stream
|
4
6
|
include Celluloid::IO
|
5
|
-
HOST = "stream.twitter.com"
|
6
7
|
|
7
|
-
def initialize(path,
|
8
|
-
@
|
9
|
-
@auth = auth
|
8
|
+
def initialize(path, opts)
|
9
|
+
@options = default_options.merge(opts).merge(path: path)
|
10
10
|
|
11
11
|
socket = TCPSocket.new "stream.twitter.com", 443
|
12
12
|
ssl = OpenSSL::SSL::SSLSocket.new(socket.to_io, OpenSSL::SSL::SSLContext.new)
|
@@ -14,28 +14,63 @@ module Gazouillis
|
|
14
14
|
ssl.connect
|
15
15
|
|
16
16
|
@stream = ssl
|
17
|
+
|
18
|
+
@http_parser = Http::Parser.new
|
19
|
+
|
20
|
+
@http_parser.on_body = on_message_callback
|
21
|
+
@http_parser.on_headers_complete = on_headers_complete
|
17
22
|
end
|
18
23
|
|
19
|
-
def
|
24
|
+
def open
|
20
25
|
@stream.write request
|
26
|
+
handle_connection!
|
27
|
+
end
|
21
28
|
|
22
|
-
|
23
|
-
|
24
|
-
|
29
|
+
def close
|
30
|
+
@stream.to_io.close
|
31
|
+
end
|
32
|
+
|
33
|
+
def on_message(message)
|
34
|
+
# Hook method. To be override.
|
25
35
|
end
|
26
36
|
|
27
37
|
private
|
28
38
|
|
39
|
+
def handle_connection
|
40
|
+
@stream.each_line {|line| @http_parser << line } unless @stream.closed?
|
41
|
+
end
|
42
|
+
|
43
|
+
def on_message_callback
|
44
|
+
Proc.new do |chunk|
|
45
|
+
Actor.current.on_message chunk
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def on_headers_complete
|
50
|
+
Proc.new do
|
51
|
+
Actor.current.close if @http_parser.status_code != 200
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# TODO : a real request object, with nice headers.
|
56
|
+
#
|
29
57
|
def request
|
30
|
-
request = "GET #{@path} HTTP/1.1\r\n"
|
31
|
-
request << "Host: #{
|
58
|
+
request = "GET #{@options[:path]} HTTP/1.1\r\n"
|
59
|
+
request << "Host: #{@options[:host]}\r\n"
|
32
60
|
request << "Authorization: Basic #{basic_auth}\r\n"
|
33
61
|
request << "\r\n"
|
34
62
|
request
|
35
63
|
end
|
36
64
|
|
37
65
|
def basic_auth
|
38
|
-
["#{@auth[:user]}:#{@auth[:passord]}"].pack('m').strip
|
66
|
+
["#{@options[:auth][:user]}:#{@options[:auth][:passord]}"].pack('m').strip
|
67
|
+
end
|
68
|
+
|
69
|
+
def default_options
|
70
|
+
{
|
71
|
+
host: 'stream.twitter.com',
|
72
|
+
port: 443
|
73
|
+
}
|
39
74
|
end
|
40
75
|
end
|
41
76
|
end
|
data/lib/gazouillis/version.rb
CHANGED
data/lib/gazouillis.rb
CHANGED
metadata
CHANGED
@@ -1,27 +1,48 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gazouillis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- chatgris
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: celluloid-io
|
16
|
-
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
17
18
|
requirements:
|
18
19
|
- - ! '>='
|
19
20
|
- !ruby/object:Gem::Version
|
20
21
|
version: '0'
|
21
|
-
|
22
|
-
requirement: *2056
|
22
|
+
type: :runtime
|
23
23
|
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: http_parser.rb
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
24
38
|
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
25
46
|
description: Twitter stream client.
|
26
47
|
email:
|
27
48
|
- jboyer@af83.com
|
@@ -34,27 +55,26 @@ files:
|
|
34
55
|
- lib/gazouillis/version.rb
|
35
56
|
homepage: https://github.com/chatgris/gazouillis
|
36
57
|
licenses: []
|
37
|
-
post_install_message:
|
58
|
+
post_install_message:
|
38
59
|
rdoc_options: []
|
39
60
|
require_paths:
|
40
61
|
- lib
|
41
62
|
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
42
64
|
requirements:
|
43
65
|
- - ! '>='
|
44
66
|
- !ruby/object:Gem::Version
|
45
67
|
version: '0'
|
46
|
-
none: false
|
47
68
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
48
70
|
requirements:
|
49
71
|
- - ! '>='
|
50
72
|
- !ruby/object:Gem::Version
|
51
73
|
version: '0'
|
52
|
-
none: false
|
53
74
|
requirements: []
|
54
|
-
rubyforge_project:
|
55
|
-
rubygems_version: 1.8.
|
56
|
-
signing_key:
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 1.8.24
|
77
|
+
signing_key:
|
57
78
|
specification_version: 3
|
58
79
|
summary: Twitter stream client.
|
59
80
|
test_files: []
|
60
|
-
...
|