tweedle 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -57,14 +57,7 @@ module Tweedle
57
57
  uri = build_uri(uri, params)
58
58
  http = build_http(uri)
59
59
  request = build_get_request(uri, http, params)
60
-
61
- begin
62
- http.request(request) { |response| handle_response(response, &block) }
63
- rescue *[Timeout::Error, Errno::ECONNRESET, EOFError]
64
- retry # reconnect
65
- ensure
66
- http.finish
67
- end
60
+ issue_request(http, request, &block)
68
61
  end
69
62
 
70
63
  # Internal: Sends a POST request to the given stream.
@@ -88,7 +81,22 @@ module Tweedle
88
81
  uri = build_uri(uri, params)
89
82
  http = build_http(uri)
90
83
  request = build_post_request(uri, http, post_data, params)
84
+ issue_request(http, request, &block)
85
+ end
86
+
87
+ private
91
88
 
89
+ # Private: Issue the given http request, handles the response and
90
+ # reconnects if necessary. Yields each response chunk to the
91
+ # passed block.
92
+ #
93
+ # http - The Net::HTTP instance to use.
94
+ # request - The request object to be used.
95
+ #
96
+ # Returns nothing.
97
+ # Raises Tweedle::ConnectionError if the server response is not an
98
+ # Net::HTTPSuccess.
99
+ def issue_request(http, request, &block)
92
100
  begin
93
101
  http.request(request) { |response| handle_response(response, &block) }
94
102
  rescue *[Timeout::Error, Errno::ECONNRESET, EOFError]
@@ -98,8 +106,6 @@ module Tweedle
98
106
  end
99
107
  end
100
108
 
101
- private
102
-
103
109
  # Private: Reads the streaming body of a given HTTP response and
104
110
  # yields a parsed JSON object to the given block for each received chunk.
105
111
  #
@@ -205,7 +211,7 @@ module Tweedle
205
211
  # Examples
206
212
  #
207
213
  # uri = URI.parse("http://www.google.com/")
208
- # build_post_request(uri, "follow=12",build_http(uri))
214
+ # build_post_request(uri, "follow=12", build_http(uri))
209
215
  # # => Net::HTTP::Post
210
216
  #
211
217
  # Returns a Net::HTTP::Post instance.
@@ -213,7 +219,7 @@ module Tweedle
213
219
  Net::HTTP::Post.new(uri.request_uri).tap do |request|
214
220
  request["content-type"] = "application/x-www-form-urlencoded"
215
221
  request.body = encode_params(post_data)
216
- request.oauth!(http, consumer, access_token)
222
+ request.oauth!(http, consumer, access_token, scheme: 'body')
217
223
  end
218
224
  end
219
225
 
@@ -265,4 +271,3 @@ module Tweedle
265
271
  end
266
272
  end
267
273
  end
268
-
@@ -1,4 +1,4 @@
1
1
  module Tweedle
2
2
  # Public: The current Tweedle version.
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
data/test/test_client.rb CHANGED
@@ -76,17 +76,35 @@ class TestClient < MiniTest::Unit::TestCase
76
76
  Tweedle.new.post(@uri, foo: "bar") do |body|
77
77
  assert_equal ["post"], body
78
78
  end
79
- assert_equal "foo=bar", FakeWeb.last_request.body
79
+
80
+ assert_includes FakeWeb.last_request.body.downcase,
81
+ "foo=bar".downcase
82
+ assert_includes FakeWeb.last_request.body.downcase,
83
+ "oauth_consumer_key=abc".downcase
84
+ assert_includes FakeWeb.last_request.body.downcase,
85
+ "oauth_token=ghi".downcase
80
86
 
81
87
  Tweedle.new.post(@uri, foo: ["bar", "baz"]) do |body|
82
88
  assert_equal ["post"], body
83
89
  end
84
- assert_equal "foo=bar,baz", FakeWeb.last_request.body
90
+
91
+ assert_includes FakeWeb.last_request.body.downcase,
92
+ "foo=bar%2Cbaz".downcase
93
+ assert_includes FakeWeb.last_request.body.downcase,
94
+ "oauth_consumer_key=abc".downcase
95
+ assert_includes FakeWeb.last_request.body.downcase,
96
+ "oauth_token=ghi".downcase
85
97
 
86
98
  Tweedle.new.post(@uri, foo: "bar", baz: 42) do |body|
87
99
  assert_equal ["post"], body
88
100
  end
89
- assert_equal "foo=bar&baz=42", FakeWeb.last_request.body
101
+
102
+ assert_includes FakeWeb.last_request.body.downcase,
103
+ "foo=bar&baz=42".downcase
104
+ assert_includes FakeWeb.last_request.body.downcase,
105
+ "oauth_consumer_key=abc".downcase
106
+ assert_includes FakeWeb.last_request.body.downcase,
107
+ "oauth_token=ghi".downcase
90
108
  end
91
109
 
92
110
  def test_get_with_params
@@ -108,17 +126,39 @@ class TestClient < MiniTest::Unit::TestCase
108
126
  Tweedle.new.post(@uri, { foo: "bar" }, { bar: "baz" }) do |body|
109
127
  assert_equal ["post bar=baz"], body
110
128
  end
111
- assert_equal "foo=bar", FakeWeb.last_request.body
129
+
130
+ assert_includes FakeWeb.last_request.body.downcase,
131
+ "foo=bar".downcase
132
+ assert_includes FakeWeb.last_request.body.downcase,
133
+ "oauth_consumer_key=abc".downcase
134
+ assert_includes FakeWeb.last_request.body.downcase,
135
+ "oauth_token=ghi".downcase
112
136
 
113
137
  Tweedle.new.post(@uri, { foo: "bar" }, { bar: ["baz", 42] }) do |body|
114
138
  assert_equal ["post bar=baz,42"], body
115
139
  end
116
- assert_equal "foo=bar", FakeWeb.last_request.body
140
+
141
+ assert_includes FakeWeb.last_request.body.downcase,
142
+ "foo=bar".downcase
143
+ assert_includes FakeWeb.last_request.body.downcase,
144
+ "bar=baz%2C42&bar=baz".downcase
145
+ assert_includes FakeWeb.last_request.body.downcase,
146
+ "oauth_consumer_key=abc".downcase
147
+ assert_includes FakeWeb.last_request.body.downcase,
148
+ "oauth_token=ghi".downcase
117
149
 
118
150
  Tweedle.new.post(@uri, { foo: "bar" }, { bar: "baz", ok: 42 }) do |body|
119
151
  assert_equal ["post bar=baz&ok=42"], body
120
152
  end
121
- assert_equal "foo=bar", FakeWeb.last_request.body
153
+
154
+ assert_includes FakeWeb.last_request.body.downcase,
155
+ "foo=bar".downcase
156
+ assert_includes FakeWeb.last_request.body.downcase,
157
+ "bar=baz&bar=baz&ok=42&ok=42".downcase
158
+ assert_includes FakeWeb.last_request.body.downcase,
159
+ "oauth_consumer_key=abc".downcase
160
+ assert_includes FakeWeb.last_request.body.downcase,
161
+ "oauth_token=ghi".downcase
122
162
  end
123
163
 
124
164
  def test_get_with_invalid_response
@@ -47,8 +47,8 @@ class TestStatuses < MiniTest::Unit::TestCase
47
47
  assert_equal ["post"], body
48
48
  end
49
49
 
50
- assert_equal "locations=-122.75,36.8,-121.75,37.8&track=ruby,tweedle",
51
- FakeWeb.last_request.body
50
+ assert_includes FakeWeb.last_request.body.downcase,
51
+ "locations=-122.75%2C36.8%2C-121.75%2C37.8&track=ruby%2Ctweedle".downcase
52
52
  end
53
53
 
54
54
  def test_filter_with_params
@@ -61,8 +61,8 @@ class TestStatuses < MiniTest::Unit::TestCase
61
61
  assert_equal ["post with params"], body
62
62
  end
63
63
 
64
- assert_equal "locations=-122.75,36.8,-121.75,37.8&track=ruby,tweedle",
65
- FakeWeb.last_request.body
64
+ assert_includes FakeWeb.last_request.body.downcase,
65
+ "locations=-122.75%2C36.8%2C-121.75%2C37.8&track=ruby%2Ctweedle".downcase
66
66
  end
67
67
 
68
68
  def test_firehose
data/tweedle.gemspec CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Tweedle::VERSION
17
17
 
18
- gem.add_dependency "multi_json", "~> 1.3.2"
19
- gem.add_dependency "oauth", "~> 0.4.6"
20
- gem.add_dependency "jruby-openssl", "~> 0.7.6.1" if RUBY_PLATFORM =~ /java/
18
+ gem.add_dependency "multi_json", "~> 1.3.6"
19
+ gem.add_dependency "oauth", "~> 0.4.7"
20
+ gem.add_dependency "jruby-openssl", "~> 0.7.7" if RUBY_PLATFORM =~ /java/
21
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tweedle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-27 00:00:00.000000000 Z
12
+ date: 2012-10-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 1.3.2
21
+ version: 1.3.6
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 1.3.2
29
+ version: 1.3.6
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: oauth
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 0.4.6
37
+ version: 0.4.7
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 0.4.6
45
+ version: 0.4.7
46
46
  description: Lightweight wrapper for the Twitter Streaming API
47
47
  email:
48
48
  - tob@tobiassvensson.co.uk
@@ -81,18 +81,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
81
  - - ! '>='
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
- segments:
85
- - 0
86
- hash: 53159501431260921
87
84
  required_rubygems_version: !ruby/object:Gem::Requirement
88
85
  none: false
89
86
  requirements:
90
87
  - - ! '>='
91
88
  - !ruby/object:Gem::Version
92
89
  version: '0'
93
- segments:
94
- - 0
95
- hash: 53159501431260921
96
90
  requirements: []
97
91
  rubyforge_project:
98
92
  rubygems_version: 1.8.23