module Served::Resource::Requestable
Constants
- HEADERS
Public Instance Methods
destroy(params = {})
click to toggle source
Destroys the record on the service. Acts on status code If code is a 204 (no content) it will simply return true otherwise it will parse the response and reloads the instance
@return [Boolean|self] Returns true or instance
# File lib/served/resource/requestable.rb, line 159 def destroy(params = {}) result = delete(params) return result if result.is_a?(TrueClass) reload_with_attributes(result) end
reload(params = {})
click to toggle source
Reloads the resource using attributes from the service
@return [self] self
# File lib/served/resource/requestable.rb, line 149 def reload(params = {}) reload_with_attributes(get(params)) self end
save()
click to toggle source
Saves the record to the service. Will call POST if the record does not have an id, otherwise will call PUT to update the record
@return [Boolean] returns true or false depending on save success
# File lib/served/resource/requestable.rb, line 142 def save id ? reload_with_attributes(put) : reload_with_attributes(post) end
Private Instance Methods
client()
click to toggle source
# File lib/served/resource/requestable.rb, line 187 def client self.class.client end
delete(params = {})
click to toggle source
# File lib/served/resource/requestable.rb, line 180 def delete(params = {}) response = client.delete(resource_name, id, params) return true if response.code == 204 handle_response(response) end
get(params = {})
click to toggle source
# File lib/served/resource/requestable.rb, line 168 def get(params = {}) self.class.get(id, params) end
handle_response(response)
click to toggle source
# File lib/served/resource/requestable.rb, line 191 def handle_response(response) self.class.handle_response(response) end
post(params = {})
click to toggle source
# File lib/served/resource/requestable.rb, line 176 def post(params = {}) handle_response(client.post(resource_name, dump, params)) end
put(params = {})
click to toggle source
# File lib/served/resource/requestable.rb, line 172 def put(params = {}) handle_response(client.put(resource_name, id, dump, params)) end