grackle 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.1.7 (2009-12-13)
2
+ * Fixed a bug in Ruby 1.9 where the client was incorrectly handling request method parameters
3
+ * Fixed a bug in the _ method that wasn't correctly appending numeric path elements
4
+ * Provided a way to specify SSL Certificate Authority certs for correct SSL validation
5
+ * The only thing that doesn't work in 1.9 in this version is OAuth because that gem is not up to date
6
+
1
7
  == 0.1.6 (2009-10-29)
2
8
  * Added support for HTTP methods beside GET and POST using block syntax
3
9
  * Added method for appending to the request path something that's not a valid ruby method
data/README.rdoc CHANGED
@@ -1,7 +1,7 @@
1
1
  =grackle
2
2
  by Hayes Davis
3
3
  - http://twitter.com/hayesdavis
4
- - hayes [at] appozite.com
4
+ - hayes [at] appozite [dot] com
5
5
  - http://cheaptweet.com
6
6
  - http://www.appozite.com
7
7
  - http://hayesdavis.net
@@ -19,6 +19,13 @@ will potentially require, however, some modifications to your code that uses Gra
19
19
 
20
20
  Grackle supports both OAuth and HTTP basic authentication.
21
21
 
22
+ === Support and Announcements
23
+ The preferred forum for questions and discussions is the Google group at http://groups.google.com/group/gracklerb.
24
+ You can email me directly or @reply me on Twitter, but the group is better since the questions and responses
25
+ will be available to everyone. I'll also make announcements there. There are some examples on the wiki at
26
+ http://wiki.github.com/hayesdavis/grackle. If you prefer your information in 140 characters, follow
27
+ @gracklerb[http://twitter.com/gracklerb].
28
+
22
29
  ==USING GRACKLE
23
30
 
24
31
  Before you do anything else, you'll need to
@@ -145,14 +152,23 @@ If you need to append something to the request path that isn't a valid ruby meth
145
152
  you can use the Grackle::Client#_ method like so:
146
153
  client._('1user').lists.json
147
154
 
148
- == REQUIREMENTS:
155
+ == REQUIREMENTS
149
156
 
150
157
  You'll need the following gems to use all features of Grackle:
151
158
  - json
152
159
  - oauth
153
160
  - mime-types
154
161
 
155
- == INSTALL:
162
+ === Ruby Version Support
163
+ Grackle works just fine on Ruby 1.8.x. It is also known to work on 1.9.1 with
164
+ the exception of OAuth. The OAuth gem used by Grackle has not been updated fully
165
+ to support 1.9. Please see this thread[http://groups.google.com/group/oauth-ruby/browse_thread/thread/d0851a907878cd22]
166
+ for more information.
167
+
168
+ Once the OAuth gem has been updated, Grackle will work fully on 1.9. If you
169
+ aren't using OAuth it should be fine for use on 1.9 as is.
170
+
171
+ == INSTALL
156
172
  The grackle gem is now hosted at http://gemcutter.org. If you've already setup gemcutter
157
173
  in your sources, you can do the following:
158
174
  sudo gem install grackle
@@ -165,7 +181,7 @@ They will likely tell you to do the following:
165
181
  Once you've done that you can do:
166
182
  sudo gem install grackle
167
183
 
168
- == LICENSE:
184
+ == LICENSE
169
185
 
170
186
  (The MIT License)
171
187
 
data/grackle.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{grackle}
5
- s.version = "0.1.6"
5
+ s.version = "0.1.7"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Hayes Davis"]
9
- s.date = %q{2009-10-29}
9
+ s.date = %q{2009-12-13}
10
10
  s.description = %q{Grackle is a lightweight library for the Twitter REST and Search API.}
11
11
  s.email = %q{hayes@appozite.com}
12
12
  s.files = ["CHANGELOG.rdoc", "README.rdoc", "grackle.gemspec", "lib/grackle.rb", "lib/grackle/client.rb", "lib/grackle/handlers.rb", "lib/grackle/transport.rb", "lib/grackle/utils.rb", "test/test_grackle.rb", "test/test_helper.rb", "test/test_client.rb", "test/test_handlers.rb"]
data/lib/grackle.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Grackle
2
2
 
3
3
  # :stopdoc:
4
- VERSION = '0.1.6'
4
+ VERSION = '0.1.7'
5
5
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
6
6
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
7
7
  # :startdoc:
@@ -185,9 +185,9 @@ module Grackle
185
185
  end
186
186
 
187
187
  def append(name,*args)
188
- name = name.to_sym
188
+ name = name.to_s.to_sym
189
189
  #The args will be a hash, store them if they're specified
190
- self.request.params = *args
190
+ self.request.params = args.first
191
191
  #If method is a format name, execute using that format
192
192
  if format_invocation?(name)
193
193
  return call_with_format(name)
@@ -18,6 +18,10 @@ module Grackle
18
18
  CRLF = "\r\n"
19
19
  DEFAULT_REDIRECT_LIMIT = 5
20
20
 
21
+ class << self
22
+ attr_accessor :ca_cert_file
23
+ end
24
+
21
25
  def req_class(method)
22
26
  Net::HTTP.const_get(method.to_s.capitalize)
23
27
  end
@@ -44,6 +48,9 @@ module Grackle
44
48
  def execute_request(method,url,options={})
45
49
  conn = Net::HTTP.new(url.host, url.port)
46
50
  conn.use_ssl = (url.scheme == 'https')
51
+ if conn.use_ssl?
52
+ configure_ssl(conn)
53
+ end
47
54
  conn.start do |http|
48
55
  req = req_class(method).new(url.request_uri)
49
56
  http.read_timeout = options[:timeout]
@@ -166,31 +173,56 @@ module Grackle
166
173
  consumer.sign!(req,access_token)
167
174
  end
168
175
 
169
- private
170
- def oauth_site(conn,req)
171
- site = "#{(conn.use_ssl? ? "https" : "http")}://#{conn.address}"
172
- if (conn.use_ssl? && conn.port != 443) || (!conn.use_ssl? && conn.port != 80)
173
- site << ":#{conn.port}"
174
- end
175
- site
176
- end
177
-
178
- def dump_request(req)
179
- puts "Sending Request"
180
- puts"#{req.method} #{req.path}"
181
- dump_headers(req)
176
+ def oauth_site(conn,req)
177
+ site = "#{(conn.use_ssl? ? "https" : "http")}://#{conn.address}"
178
+ if (conn.use_ssl? && conn.port != 443) || (!conn.use_ssl? && conn.port != 80)
179
+ site << ":#{conn.port}"
182
180
  end
181
+ site
182
+ end
183
183
 
184
- def dump_response(res)
185
- puts "Received Response"
186
- dump_headers(res)
187
- puts res.body
184
+ def dump_request(req)
185
+ puts "Sending Request"
186
+ puts"#{req.method} #{req.path}"
187
+ dump_headers(req)
188
+ end
189
+
190
+ def dump_response(res)
191
+ puts "Received Response"
192
+ dump_headers(res)
193
+ puts res.body
194
+ end
195
+
196
+ def dump_headers(msg)
197
+ msg.each_header do |key, value|
198
+ puts "\t#{key}=#{value}"
188
199
  end
189
-
190
- def dump_headers(msg)
191
- msg.each_header do |key, value|
192
- puts "\t#{key}=#{value}"
200
+ end
201
+
202
+ def configure_ssl(conn)
203
+ if self.class.ca_cert_file
204
+ conn.verify_mode = OpenSSL::SSL::VERIFY_PEER
205
+ conn.ca_file = self.class.ca_cert_file
206
+ else
207
+ # Turn off SSL verification which gets rid of warning in 1.8.x and
208
+ # an error in 1.9.x.
209
+ conn.verify_mode = OpenSSL::SSL::VERIFY_NONE
210
+ unless @ssl_warning_shown
211
+ puts <<-EOS
212
+ Warning: SSL Verification is not being performed. While your communication is
213
+ being encrypted, the identity of the other party is not being confirmed nor the
214
+ SSL certificate verified. It's recommended that you specify a file containing
215
+ root SSL certificates like so:
216
+
217
+ Grackle::Transport.ca_cert_file = "path/to/cacerts.pem"
218
+
219
+ You can download this kind of file from the maintainers of cURL:
220
+ http://curl.haxx.se/ca/cacert.pem
221
+
222
+ EOS
223
+ @ssl_warning_shown = true
193
224
  end
194
225
  end
226
+ end
195
227
  end
196
228
  end
data/test/test_client.rb CHANGED
@@ -7,6 +7,10 @@ class TestClient < Test::Unit::TestCase
7
7
  class << self
8
8
  attr_accessor :response, :request, :last_instance, :responder
9
9
  end
10
+
11
+ def connect
12
+ # This needs to be overridden so SSL requests can be mocked
13
+ end
10
14
 
11
15
  def request(req)
12
16
  self.class.last_instance = self
@@ -129,6 +133,14 @@ class TestClient < Test::Unit::TestCase
129
133
  assert(Net::HTTP.last_instance.use_ssl?,'Net::HTTP instance should be set to use SSL')
130
134
  end
131
135
 
136
+ def test_ssl_with_ca_cert_file
137
+ MockTransport.ca_cert_file = "some_ca_certs.pem"
138
+ client = new_client(200,'[{"id":1,"text":"test 1"}]',:ssl=>true)
139
+ client.statuses.public_timeline?
140
+ assert_equal(OpenSSL::SSL::VERIFY_PEER,Net::HTTP.last_instance.verify_mode,'Net::HTTP instance should use OpenSSL::SSL::VERIFY_PEER mode')
141
+ assert_equal(MockTransport.ca_cert_file,Net::HTTP.last_instance.ca_file,'Net::HTTP instance should have cert file set')
142
+ end
143
+
132
144
  def test_default_format
133
145
  client = new_client(200,'[{"id":1,"text":"test 1"}]',:default_format=>:json)
134
146
  client.statuses.public_timeline?
@@ -235,6 +247,17 @@ class TestClient < Test::Unit::TestCase
235
247
  assert_equal(:post,client.transport.method, ":__method=>:post should override block setting and method suffix")
236
248
  end
237
249
 
250
+ def test_underscore_method_works_with_numbers
251
+ client = new_client(200,'{"id":12345,"screen_name":"test_user"}')
252
+ value = client.users.show._(12345).json?
253
+ assert_equal(:get,client.transport.method)
254
+ assert_equal('http',client.transport.url.scheme)
255
+ assert(!Net::HTTP.last_instance.use_ssl?,'Net::HTTP instance should not be set to use SSL')
256
+ assert_equal('twitter.com',client.transport.url.host)
257
+ assert_equal('/users/show/12345.json',client.transport.url.path)
258
+ assert_equal(12345,value.id)
259
+ end
260
+
238
261
  private
239
262
  def with_http_responder(responder)
240
263
  Net::HTTP.responder = responder
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grackle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hayes Davis
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-29 00:00:00 -05:00
12
+ date: 2009-12-13 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency