lib/restly/connection.rb in restly-0.0.1.beta.3 vs lib/restly/connection.rb in restly-0.0.1.beta.4
- old
+ new
@@ -59,15 +59,20 @@
refresh_token: refresh_token,
expires_at: expires_at
}
end
+ def status_string(int)
+ Rack::Utils::HTTP_STATUS_CODES[int.to_i]
+ end
+
alias_method :forced_request, :request
def request(verb, path, opts={}, &block)
- path = [base_path.gsub(/\/?$/, ''), path.gsub(/^\/?/, '')].join('/')
+ path = [base_path.gsub(/\/?$/, ''), path.gsub(/^\/?/, '')].join('/') unless /#{base_path}/.match path
+
if cache && !opts[:force]
request_log("Restly::CacheRequest", path, verb) do
cached_request(verb, path, opts, &block)
end
else
@@ -75,10 +80,12 @@
forced_request(verb, path, opts, &block)
end
end
end
+ private
+
def id_from_path(path)
capture = path.match /(?<id>[0-9])\.\w*$/
capture[:id] if capture
end
@@ -121,11 +128,11 @@
cache_log("Restly::CacheExpire", cache_key, :yellow) { Rails.cache.delete(cache_key) } if response.error
if response.status >= 500
site = URI.parse(client.site)
- formatted_path = ["#{site.scheme}://#{site.host}", "#{site.port}", path].join
+ formatted_path = ["#{site.scheme}://#{site.host}", ":#{site.port}", path].join
raise Restly::Error::ConnectionError, "#{response.status}: #{status_string(response.status)}\nurl: #{formatted_path}"
end
# Return the response
response
@@ -138,12 +145,8 @@
ActiveSupport::Notifications.instrument("request.restly", url: formatted_path, method: verb, name: name, color: color, &block)
end
def cache_log(name, key, color=:light_green, &block)
ActiveSupport::Notifications.instrument("cache.restly", key: key, name: name, color: color, &block)
- end
-
- def status_string(int)
- Rack::Utils::HTTP_STATUS_CODES[int.to_i]
end
end
\ No newline at end of file