gazouillis 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5390ff6c5903785608b8b446fbc7e777df9a8cf4
4
+ data.tar.gz: 7c475b61dd31918401adadf3b7e26c5c2b38bedc
5
+ SHA512:
6
+ metadata.gz: 9fc0ea7581c84b5e3b4dccabf16137d4256fc66109a31fccb3ce3c2add3280c3cc8ccbafe00cfdbbe9dc948525aad0e08d624155cd6d62a4cb33685a26ed097b
7
+ data.tar.gz: ecbc0fe02c937870e6c39b4dbf9684cdc0a1b6819e32afa678ab9f6a55efac7f7a312f8f7d4815a025bcf1cb6584abcd6df833b569b3c9b5322350d96c4d4464
data/lib/gazouillis.rb CHANGED
@@ -4,4 +4,5 @@ require 'celluloid/io'
4
4
  require 'http/parser'
5
5
  require 'simple_oauth'
6
6
  require_relative 'gazouillis/stream'
7
+ require_relative 'gazouillis/request'
7
8
  require_relative 'gazouillis/version'
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+ module Gazouillis
3
+ class Request < String
4
+ attr_reader :host, :path, :method, :oauth
5
+ CRLF = "\r\n"
6
+
7
+ def initialize(path, options)
8
+ @host, @path, @method = options[:host], path, options[:method]
9
+ @oauth = options[:oauth]
10
+ super(request)
11
+ end
12
+
13
+ private
14
+
15
+ def request
16
+ [
17
+ "#{method} #{path} HTTP/1.1",
18
+ "Host: #{host}",
19
+ "User-Agent: Gazouillis #{Gazouillis::VERSION}",
20
+ "Authorization: #{oauth_header}",
21
+ CRLF
22
+ ].join(CRLF)
23
+ end
24
+
25
+ def oauth_header
26
+ SimpleOAuth::Header.new method, full_url, {}, oauth
27
+ end
28
+
29
+ def full_url
30
+ "https://#{host}#{path}"
31
+ end
32
+
33
+ end
34
+ end
@@ -4,34 +4,24 @@ module Gazouillis
4
4
  #
5
5
  class Stream
6
6
  include Celluloid::IO
7
- attr_reader :host, :path, :method
7
+ attr_reader :request, :stream, :http_parser
8
8
 
9
9
  def initialize(path, opts)
10
- @options = default_options.merge(opts)
11
- @path = path
12
- @host = opts.fetch(:host, "stream.twitter.com")
13
- @method = opts.fetch(:method, "GET")
14
-
15
- socket = TCPSocket.new "stream.twitter.com", 443
16
- ssl = OpenSSL::SSL::SSLSocket.new(socket.to_io, OpenSSL::SSL::SSLContext.new)
17
- ssl.sync = true
18
- ssl.connect
19
-
20
- @stream = ssl
21
-
10
+ options = default_options.merge(opts)
11
+ @request = Request.new(path, options)
12
+ @stream = set_stream(TCPSocket.new options[:host], options[:port])
22
13
  @http_parser = Http::Parser.new
23
-
24
- @http_parser.on_body = on_message_callback
25
- @http_parser.on_headers_complete = on_headers_complete
14
+ http_parser.on_body = on_message_callback
15
+ http_parser.on_headers_complete = on_headers_complete
26
16
  end
27
17
 
28
18
  def open
29
- @stream.write request
19
+ stream.write request
30
20
  handle_connection
31
21
  end
32
22
 
33
23
  def close
34
- @stream.to_io.close
24
+ stream.to_io.close
35
25
  end
36
26
 
37
27
  def on_message(message)
@@ -40,8 +30,16 @@ module Gazouillis
40
30
 
41
31
  private
42
32
 
33
+ def set_stream(socket)
34
+ OpenSSL::SSL::SSLSocket.new(socket.to_io,
35
+ OpenSSL::SSL::SSLContext.new).tap {|ssl|
36
+ ssl.sync = true
37
+ ssl.connect
38
+ }
39
+ end
40
+
43
41
  def handle_connection
44
- @stream.each_line {|line| @http_parser << line } unless @stream.closed?
42
+ stream.each_line {|line| http_parser << line } unless stream.closed?
45
43
  end
46
44
 
47
45
  def on_message_callback
@@ -52,33 +50,15 @@ module Gazouillis
52
50
 
53
51
  def on_headers_complete
54
52
  Proc.new do
55
- Actor.current.close if @http_parser.status_code != 200
53
+ Actor.current.close if http_parser.status_code != 200
56
54
  end
57
55
  end
58
56
 
59
- # TODO : a real request object, with nice headers.
60
- #
61
- def request
62
- request = "#{method} #{path} HTTP/1.1\r\n"
63
- request << "Host: #{@options[:host]}\r\n"
64
- request << "User-Agent: Gazouillis #{Gazouillis::VERSION}\r\n"
65
- request << "Authorization: #{oauth}\r\n"
66
- request << "\r\n"
67
- request
68
- end
69
-
70
- def oauth
71
- SimpleOAuth::Header.new method, full_url, {}, @options[:oauth]
72
- end
73
-
74
- def full_url
75
- "https://#{host}#{path}"
76
- end
77
-
78
57
  def default_options
79
58
  {
80
59
  host: 'stream.twitter.com',
81
- port: 443
60
+ port: 443,
61
+ method: "GET"
82
62
  }
83
63
  end
84
64
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Gazouillis
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gazouillis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
5
- prerelease:
4
+ version: 0.1.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - chatgris
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-23 00:00:00.000000000 Z
11
+ date: 2013-02-24 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: celluloid-io
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - '>='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - '>='
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: http_parser.rb
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - '>='
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: simple_oauth
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - '>='
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - '>='
60
53
  - !ruby/object:Gem::Version
@@ -69,31 +62,30 @@ files:
69
62
  - LICENSE
70
63
  - README.md
71
64
  - lib/gazouillis.rb
65
+ - lib/gazouillis/request.rb
72
66
  - lib/gazouillis/stream.rb
73
67
  - lib/gazouillis/version.rb
74
68
  homepage: http://chatgris.github.com/gazouillis
75
69
  licenses: []
70
+ metadata: {}
76
71
  post_install_message:
77
72
  rdoc_options: []
78
73
  require_paths:
79
74
  - lib
80
75
  required_ruby_version: !ruby/object:Gem::Requirement
81
- none: false
82
76
  requirements:
83
77
  - - '>='
84
78
  - !ruby/object:Gem::Version
85
79
  version: '0'
86
80
  required_rubygems_version: !ruby/object:Gem::Requirement
87
- none: false
88
81
  requirements:
89
82
  - - '>='
90
83
  - !ruby/object:Gem::Version
91
84
  version: '0'
92
85
  requirements: []
93
86
  rubyforge_project:
94
- rubygems_version: 1.8.25
87
+ rubygems_version: 2.0.0.rc.2
95
88
  signing_key:
96
- specification_version: 3
89
+ specification_version: 4
97
90
  summary: Twitter stream client.
98
91
  test_files: []
99
- has_rdoc: