Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add optional Grackle::Client.new(:uri_extension=>true) which allows f…

…or accessing endpoints without extensions (useful for non-Twitter)
  • Loading branch information...
commit 72765a93c66e6d8b28e06ef867338b4e26deb89c 1 parent ab6eb98
@jcsalterego jcsalterego authored
Showing with 7 additions and 3 deletions.
  1. +7 −3 lib/grackle/client.rb
View
10 lib/grackle/client.rb
@@ -98,7 +98,7 @@ def params
}
attr_accessor :auth, :handlers, :default_format, :headers, :ssl, :api,
- :transport, :request, :api_hosts, :timeout, :auto_append_ids
+ :transport, :request, :api_hosts, :timeout, :auto_append_ids, :uri_extension
# Arguments (all are optional):
# - :username - twitter username to authenticate with (deprecated in favor of :auth arg)
@@ -111,6 +111,7 @@ def params
# - :auth - Hash of authentication type and credentials. Must have :type key with value one of :basic or :oauth
# - :type=>:basic - Include :username and :password keys
# - :type=>:oauth - Include :consumer_key, :consumer_secret, :token and :token_secret keys
+ # - :uri_extension - true or false to include format in URI (e.g. /test.json). Default is true
def initialize(options={})
self.transport = Transport.new
self.handlers = {:json=>Handlers::JSONHandler.new,:xml=>Handlers::XMLHandler.new,:unknown=>Handlers::StringHandler.new}
@@ -123,6 +124,7 @@ def initialize(options={})
self.timeout = options[:timeout] || 60
self.auto_append_ids = options[:auto_append_ids] == false ? false : true
self.auth = {}
+ self.uri_extension = options[:uri_extension] == false ? false : true
if options.has_key?(:username) || options.has_key?(:password)
#Use basic auth if :username and :password args are passed in
self.auth.merge!({:type=>:basic,:username=>options[:username],:password=>options[:password]})
@@ -218,7 +220,9 @@ def call_with_format(format)
id = request.params.delete(:id)
request << "/#{id}" if id
end
- request << ".#{format}"
+ if uri_extension
+ request << ".#{format}"
+ end
res = send_request
process_response(format,res)
ensure
@@ -288,4 +292,4 @@ def request_with_http_method_block(method,&block)
end
end
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.