Class: StorageRoom::Resource
- Inherits:
-
Object
- Object
- StorageRoom::Resource
- Extended by:
- Plugins
- Includes:
- HTTParty, Accessors
- Defined in:
- lib/storage_room/resource.rb
Overview
The superclass of all the classes that load data from the API
Direct Known Subclasses
Class Method Summary (collapse)
-
+ (Object) handle_critical_response_errors(httparty)
Handle known server errors.
-
+ (Boolean) meta_data?(key)
Find out if a key is user-defined or meta-data (begins with @).
Instance Method Summary (collapse)
-
- (Boolean) loaded?
Has the Resource been loaded from the API?.
-
- (Object) reload(url = nil, parameters = {})
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
+ (Object) handle_critical_response_errors(httparty)
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 |
+ (Boolean) meta_data?(key)
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
- (Boolean) loaded?
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 |
- (Object) reload(url = nil, parameters = {})
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 |