grackle 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.1.9 (2010-2-28)
2
+ * Added support for a boolean option called auto_append_ids that controls whether parameters named "id" are automatically appended to the URL or used as request parameters. It's true by default so there's no change to existing behavior unless you explicitly set it to false.
3
+ * Updated the README with changes describing how to use custom handlers (thanks akahn!)
4
+
1
5
  == 0.1.8 (2010-2-2)
2
6
  * Added proxy support to Grackle::Transport via proxy attribute. Can specify a Proc that returns a Net::HTTP subclass or a Net::HTTP subclass directly. Typically this will be from Net::HTTP.Proxy.
3
7
 
data/README.rdoc CHANGED
@@ -140,12 +140,21 @@ returned by Twitter. It's a good idea to wrap your API calls with rescue clauses
140
140
  If there is an unexpected connection error or Twitter returns data in the wrong format (which it can do), you'll still get a TwitterError.
141
141
 
142
142
  ===Formats
143
- Twitter allows you to request data in particular formats. Grackle automatically parses JSON and XML formatted responses
144
- and returns an OpenStruct. If you specify a format that Grackle doesn't parse for you, you'll receive a string containing
145
- the raw response body. The Grackle::Client has a default_format you can specify. By default, the default_format is :json.
146
- If you don't include a named format in your method chain as described above, but use a "?" or "!" then the
143
+ Twitter allows you to request data in particular formats. Grackle automatically
144
+ parses JSON and XML formatted responses and returns an OpenStruct. The
145
+ Grackle::Client has a default_format you can specify. By default, the
146
+ default_format is :json. If you don't include a named format in your method
147
+ chain as described above, but use a "?" or "!" then the
147
148
  Grackle::Client.default_format is used.
148
149
 
150
+ If you specify a format that Grackle doesn't parse for you, you'll receive a
151
+ string containing the raw response body. If you want to receive the raw
152
+ response body even for XML or JSON formatted responses, tell the Grackle client
153
+ to use the +StringHandler+ handler. For example, the following code sets the
154
+ Grackle client to return JSON instead of an OpenStruct:
155
+
156
+ client = Grackle::Client.new(:handlers=>{:json=>Grackle::Handlers::StringHandler.new })
157
+
149
158
  ===Odds and Ends
150
159
  If you need to append something to the request path that isn't a valid ruby method, e.g.
151
160
  /1user/lists.json #1user isn't a valid Ruby method
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.8"
5
+ s.version = "0.1.9"
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{2010-2-2}
9
+ s.date = %q{2010-2-28}
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.8'
4
+ VERSION = '0.1.9'
5
5
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
6
6
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
7
7
  # :startdoc:
@@ -98,7 +98,8 @@ module Grackle
98
98
  :authorize_path=>'/oauth/authorize'
99
99
  }
100
100
 
101
- attr_accessor :auth, :handlers, :default_format, :headers, :ssl, :api, :transport, :request, :api_hosts, :timeout
101
+ attr_accessor :auth, :handlers, :default_format, :headers, :ssl, :api,
102
+ :transport, :request, :api_hosts, :timeout, :auto_append_ids
102
103
 
103
104
  # Arguments (all are optional):
104
105
  # - :username - twitter username to authenticate with (deprecated in favor of :auth arg)
@@ -121,6 +122,7 @@ module Grackle
121
122
  self.api = options[:api] || :rest
122
123
  self.api_hosts = TWITTER_API_HOSTS.clone
123
124
  self.timeout = options[:timeout] || 60
125
+ self.auto_append_ids = options[:auto_append_ids] == false ? false : true
124
126
  self.auth = {}
125
127
  if options.has_key?(:username) || options.has_key?(:password)
126
128
  #Use basic auth if :username and :password args are passed in
@@ -213,8 +215,10 @@ module Grackle
213
215
 
214
216
  protected
215
217
  def call_with_format(format)
216
- id = request.params.delete(:id)
217
- request << "/#{id}" if id
218
+ if auto_append_ids
219
+ id = request.params.delete(:id)
220
+ request << "/#{id}" if id
221
+ end
218
222
  request << ".#{format}"
219
223
  res = send_request
220
224
  process_response(format,res)
data/test/test_client.rb CHANGED
@@ -293,6 +293,25 @@ class TestClient < Test::Unit::TestCase
293
293
  assert_equal(false,MockProxy.started,"Proxy should not have been called")
294
294
  end
295
295
 
296
+ def test_auto_append_ids_is_honored
297
+ client = new_client(200,'{"id":12345,"screen_name":"test_user"}')
298
+ client.users.show.json? :id=>12345
299
+ assert_equal('/users/show/12345.json',client.transport.url.path,"Id should be appended by default")
300
+ client.auto_append_ids = false
301
+ client.users.show.json? :id=>12345
302
+ assert_equal('/users/show.json',client.transport.url.path,"Id should not be appended")
303
+ assert_equal(12345,client.transport.options[:params][:id], "Id should be treated as a parameter")
304
+ assert_equal("id=#{12345}",Net::HTTP.request.path.split(/\?/)[1],"id should be part of the query string")
305
+ end
306
+
307
+ def test_auto_append_ids_can_be_set_in_constructor
308
+ client = new_client(200,'{"id":12345,"screen_name":"test_user"}',:auto_append_ids=>false)
309
+ client.users.show.json? :id=>12345
310
+ assert_equal('/users/show.json',client.transport.url.path,"Id should not be appended")
311
+ assert_equal(12345,client.transport.options[:params][:id], "Id should be treated as a parameter")
312
+ assert_equal("id=#{12345}",Net::HTTP.request.path.split(/\?/)[1],"id should be part of the query string")
313
+ end
314
+
296
315
  private
297
316
  def with_http_responder(responder)
298
317
  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.8
4
+ version: 0.1.9
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: 2010-02-02 00:00:00 -06:00
12
+ date: 2010-02-28 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency