lib/hyper_resource/modules/http.rb in hyperresource-0.2.2 vs lib/hyper_resource/modules/http.rb in hyperresource-0.2.3

- old
+ new

@@ -20,11 +20,12 @@ post(*args) end ## POSTs the given attributes to this resource's href, and returns ## the response resource. - def post(attrs) + def post(attrs=nil) + attrs || self.attributes self.response = faraday_connection.post do |req| req.body = adapter.serialize(attrs) end finish_up end @@ -65,11 +66,17 @@ ## Returns a raw Faraday connection to this resource's URL, with proper ## headers (including auth). Threadsafe. def faraday_connection(url=nil) url ||= URI.join(self.root, self.href) - key = "faraday_connection_#{url}" + key = Digest::MD5.hexdigest({ + 'faraday_connection' => { + 'url' => url, + 'headers' => self.headers, + 'ba' => self.auth[:basic] + } + }.to_json) return Thread.current[key] if Thread.current[key] fc = Faraday.new(self.faraday_options.merge(:url => url)) fc.headers.merge!('User-Agent' => "HyperResource #{HyperResource::VERSION}") fc.headers.merge!(self.headers || {}) @@ -81,10 +88,10 @@ private def finish_up begin - self.body = self.adapter.deserialize(self.response.body) + self.body = self.adapter.deserialize(self.response.body) unless self.response.body.nil? rescue StandardError => e raise HyperResource::ResponseError.new( "Error when deserializing response body", :response => self.response, :cause => e