Class: StorageRoom::Resource
Overview
The superclass of all the classes that load data from the API
Direct Known Subclasses
Class Method Summary collapse
-
.handle_critical_response_errors(httparty) ⇒ Object
Handle known server errors.
-
.meta_data?(key) ⇒ Boolean
Find out if a key is user-defined or meta-data (begins with @).
Instance Method Summary collapse
-
#loaded? ⇒ Boolean
Has the Resource been loaded from the API?.
-
#reload(url = nil, parameters = {}) ⇒ Object
Reload an object from the API.
Methods included from Plugins
Methods included from Accessors
#[], #as_json, #attributes, #attributes=, #eql?, #hash, #initialize, #inspect, #proxy?, #reset!, #response_data, #response_data=, #set_from_response_data, #to_hash
Class Method Details
.handle_critical_response_errors(httparty) ⇒ Object
Handle known server errors
16 17 18 19 20 21 22 |
# File 'lib/storage_room/resource.rb', line 16 def handle_critical_response_errors(httparty) # :nodoc: case httparty.response.code when '200', '201', '204', '409', '422' then true else raise StorageRoom::RequestFailedError.new("Invalid HTTP Response: #{httparty.response.code}") end end |
.meta_data?(key) ⇒ Boolean
Find out if a key is user-defined or meta-data (begins with @)
25 26 27 |
# File 'lib/storage_room/resource.rb', line 25 def (key) key[0...1] == '@' end |
Instance Method Details
#loaded? ⇒ Boolean
Has the Resource been loaded from the API?
40 41 42 |
# File 'lib/storage_room/resource.rb', line 40 def loaded? self['@url'] ? true : false end |
#reload(url = nil, parameters = {}) ⇒ Object
Reload an object from the API. Optionally pass an URL.
31 32 33 34 35 36 37 |
# File 'lib/storage_room/resource.rb', line 31 def reload(url = nil, parameters = {}) httparty = self.class.get(url || self[:@url], StorageRoom..merge(parameters)) hash = httparty.parsed_response.first[1] reset! set_from_response_data(hash) true end |