Browse files

fix params

  • Loading branch information...
1 parent cc6f8a0 commit 688376201ccafe45e2ffe7fd47eba6cafbc258d8 @maccman committed Aug 27, 2011
Showing with 20 additions and 12 deletions.
  1. +20 −12 lib/nestful/request.rb
View
32 lib/nestful/request.rb
@@ -6,20 +6,25 @@ def self.callbacks(type = nil) #:nodoc:
@callbacks[type] ||= []
end
- attr_reader :options, :format, :uri
+ attr_reader :options, :format, :url
attr_accessor :params, :body, :buffer, :method, :headers, :callbacks, :raw, :extension
# Connection options
attr_accessor :proxy, :user, :password, :auth_type, :timeout, :ssl_options
def initialize(url, options = {})
- self.url = url
+ @url = url.to_s
+
@options = options
@options.each do |key, val|
method = "#{key}="
send(method, val) if respond_to?(method)
end
+
self.method ||= :get
+ self.params ||= {}
+ self.headers ||= {}
+ self.body ||= ''
self.format ||= :blank
end
@@ -39,9 +44,16 @@ def connection
conn
end
- def url=(url)
- url = url.to_s
- url = url.match(/^http/) ? url : "http://#{url}"
+ def url=(value)
+ @url = value
+ @uri = nil
+ @url
+ end
+
+ def uri
+ return @uri if @uri
+
+ url = @url.match(/^http/) ? @url : "http://#{@url}"
@uri = URI.parse(url)
@uri.path = "/" if @uri.path.empty?
@@ -51,16 +63,12 @@ def url=(url)
@uri.path += ".#{extension}"
end
- @params = {}
- @headers = {}
- @body = ''
-
@uri.query.split("&").each do |res|
key, value = res.split("=")
@params[key] = value
end if @uri.query
- url
+ @uri
end
def path
@@ -69,7 +77,7 @@ def path
def query_path
query_path = path
- if params.present?
+ if params.any?
query_path += "?"
query_path += params.to_param
end
@@ -99,7 +107,7 @@ def execute
execute
end
- protected
+ protected
def encoded
params.any? ? format.encode(params) : body
end

0 comments on commit 6883762

Please sign in to comment.