em-twitter 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -110,6 +110,7 @@ module EventMachine
110
110
  end
111
111
 
112
112
  def stalled?
113
+ @last_response ||= Response.new
113
114
  @last_response.older_than?(STALL_TIMEOUT)
114
115
  end
115
116
 
@@ -19,15 +19,12 @@ module EventMachine
19
19
  data << "#{request_method} #{request_uri} HTTP/1.1"
20
20
  data << "Host: #{@options[:host]}"
21
21
 
22
- data << 'Accept: */*'
23
-
24
- # TODO: Complete gzip support
25
- # if gzip?
26
- # data << 'Connection: Keep-Alive'
27
- # data << 'Accept-Encoding: deflate'
28
- # else
29
- # data << 'Accept: */*'
30
- # end
22
+ if gzip?
23
+ data << 'Connection: Keep-Alive'
24
+ data << 'Accept-Encoding: deflate, gzip'
25
+ else
26
+ data << 'Accept: */*'
27
+ end
31
28
 
32
29
  data << "User-Agent: #{@options[:user_agent]}" if @options[:user_agent]
33
30
  if put_or_post?
@@ -1,5 +1,5 @@
1
1
  module EventMachine
2
2
  module Twitter
3
- VERSION = "0.1.2" unless defined?(EventMachine::Twitter::VERSION)
3
+ VERSION = "0.1.3" unless defined?(EventMachine::Twitter::VERSION)
4
4
  end
5
5
  end
@@ -92,13 +92,13 @@ describe EM::Twitter::Connection do
92
92
  describe 'stall handling' do
93
93
  before do
94
94
  Mockingbird.setup(test_options) do
95
- wait(100)
95
+ wait(10)
96
96
  end
97
97
  end
98
98
 
99
99
  after { Mockingbird.teardown }
100
100
 
101
- it 'invokes a no-data callback when no data is received' do
101
+ it 'invokes a no-data callback when stalled' do
102
102
  called = false
103
103
  EM.run do
104
104
  client = EM::Twitter::Client.connect(default_options)
@@ -111,6 +111,27 @@ describe EM::Twitter::Connection do
111
111
 
112
112
  called.should be_true
113
113
  end
114
+
115
+ it 'invokes a no-data callback when stalled without a response' do
116
+ called = false
117
+ EM.run do
118
+ client = EM::Twitter::Client.connect(default_options)
119
+ # this is kind of sneaky, using a stub on gracefully_closed?
120
+ # to set a nil response the first time around to mimic a null
121
+ # response object
122
+ client.connection.stub(:gracefully_closed?) do
123
+ resp = client.connection.instance_variable_get(:@last_response)
124
+ client.connection.instance_variable_set(:@last_response, nil) if resp.timestamp.nil?
125
+ false
126
+ end
127
+ client.on_no_data_received do
128
+ called = true
129
+ EM.stop
130
+ end
131
+ end
132
+
133
+ called.should be_true
134
+ end
114
135
  end
115
136
  end
116
137
 
@@ -60,6 +60,20 @@ describe EM::Twitter::Request do
60
60
  end
61
61
  end
62
62
 
63
+ context 'gzip encoding' do
64
+ before do
65
+ @request = EM::Twitter::Request.new(default_options.merge(:encoding => 'gzip'))
66
+ end
67
+
68
+ it 'sets a keep-alive header' do
69
+ @request.to_s.should include('Connection: Keep-Alive')
70
+ end
71
+
72
+ it 'sets the accept-enconding header' do
73
+ @request.to_s.should include('Accept-Encoding: deflate, gzip')
74
+ end
75
+ end
76
+
63
77
  it 'adds a POST body' do
64
78
  @request = EM::Twitter::Request.new(default_options)
65
79
  @request.to_s.should include('track=nfl')
@@ -75,6 +89,11 @@ describe EM::Twitter::Request do
75
89
  @request.to_s.should include('User-Agent: EM::Twitter Test Suite')
76
90
  end
77
91
 
92
+ it 'adds an accept header' do
93
+ @request = EM::Twitter::Request.new(default_options)
94
+ @request.to_s.should include('Accept: */*')
95
+ end
96
+
78
97
  it 'adds custom headers' do
79
98
  @request = EM::Twitter::Request.new(default_options.merge(:headers => { 'foo' => 'bar'}))
80
99
  @request.to_s.should include('foo: bar')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-twitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-23 00:00:00.000000000Z
12
+ date: 2012-06-09 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
16
- requirement: &70315157830960 !ruby/object:Gem::Requirement
16
+ requirement: &70145432188720 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.0.beta.4
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70315157830960
24
+ version_requirements: *70145432188720
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: http_parser.rb
27
- requirement: &70315157830160 !ruby/object:Gem::Requirement
27
+ requirement: &70145432188220 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0.5'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70315157830160
35
+ version_requirements: *70145432188220
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: simple_oauth
38
- requirement: &70315157829460 !ruby/object:Gem::Requirement
38
+ requirement: &70145432187760 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0.1'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70315157829460
46
+ version_requirements: *70145432187760
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &70315157828960 !ruby/object:Gem::Requirement
49
+ requirement: &70145432187380 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70315157828960
57
+ version_requirements: *70145432187380
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rdiscount
60
- requirement: &70315157828420 !ruby/object:Gem::Requirement
60
+ requirement: &70145432186920 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70315157828420
68
+ version_requirements: *70145432186920
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
- requirement: &70315157827960 !ruby/object:Gem::Requirement
71
+ requirement: &70145432186500 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70315157827960
79
+ version_requirements: *70145432186500
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: simplecov
82
- requirement: &70315157827220 !ruby/object:Gem::Requirement
82
+ requirement: &70145432186080 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70315157827220
90
+ version_requirements: *70145432186080
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: yard
93
- requirement: &70315157826560 !ruby/object:Gem::Requirement
93
+ requirement: &70145432178720 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70315157826560
101
+ version_requirements: *70145432178720
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: mockingbird
104
- requirement: &70315157825840 !ruby/object:Gem::Requirement
104
+ requirement: &70145432177960 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: 0.1.1
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70315157825840
112
+ version_requirements: *70145432177960
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: guard-rspec
115
- requirement: &70315157825120 !ruby/object:Gem::Requirement
115
+ requirement: &70145432177460 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,7 +120,7 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *70315157825120
123
+ version_requirements: *70145432177460
124
124
  description: Twitter Streaming API client for EventMachine
125
125
  email: steve.agalloco@gmail.com
126
126
  executables: []