lib/restful_resource/base.rb in restful_resource-0.8.8 vs lib/restful_resource/base.rb in restful_resource-0.8.9
- old
+ new
@@ -1,15 +1,15 @@
module RestfulResource
class Base < OpenObject
extend RestfulResource::Associations
def self.http=(http)
- @@http = http
+ @http = http
end
def self.http
- @@http ||= RestfulResource::HttpClient.new(authorization: superclass.base_authorization)
+ @http ||= RestfulResource::HttpClient.new(authorization: superclass.base_authorization)
end
def self.http_authorization(user, password)
@base_authorization = RestfulResource::Authorization.http_authorization(user, password)
end
@@ -21,28 +21,28 @@
def self.resource_path(url)
@resource_path = url
end
def self.find(id, params={})
- response = http.get(member_url(id, params))
+ response = superclass.http.get(member_url(id, params))
self.new(parse_json(response.body))
end
def self.where(params={})
- response = http.get(collection_url(params))
+ response = superclass.http.get(collection_url(params))
self.paginate_response(response)
end
def self.get(params={})
- response = http.get(collection_url(params))
+ response = superclass.http.get(collection_url(params))
RestfulResource::OpenObject.new(parse_json(response.body))
end
def self.put(id, data: {}, **params)
url = member_url(id, params)
- response = http.put(url, data: data)
+ response = superclass.http.put(url, data: data)
self.new(parse_json(response.body))
end
def self.all
self.where
@@ -62,9 +62,11 @@
@inner_object.send(:table).as_json(options)
end
protected
def self.base_url
+ raise BaseUrlMissing.new if @base_url.nil?
+
@base_url
end
def self.base_authorization
@base_authorization