Class: Weeblycloud::CloudResource
- Inherits:
-
Object
- Object
- Weeblycloud::CloudResource
- Defined in:
- lib/weeblycloud/cloudresource.rb
Overview
A base resource that all other resources inherit from.
Direct Known Subclasses
Account, Blog, BlogPost, Form, FormEntry, Group, Member, Page, Plan, Site, Theme, User
Instance Attribute Summary collapse
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Instance Method Summary collapse
-
#[](prop) ⇒ Object
Get a property.
-
#get ⇒ Object
Gets the resources with an API call.
-
#get_property(prop) ⇒ Object
Get a property.
-
#id ⇒ Object
Returns the ID for the resource object.
-
#initialize(data = nil) ⇒ CloudResource
constructor
A new instance of CloudResource.
-
#to_s ⇒ Object
Returns the properties as a json string.
Constructor Details
#initialize(data = nil) ⇒ CloudResource
Returns a new instance of CloudResource.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/weeblycloud/cloudresource.rb', line 10 def initialize(data = nil) @client = CloudClient.new @properties = {} @changed = {} # If data isn't provided, make an API call to get it if data @properties = data @got = true else get() @got = true end end |
Instance Attribute Details
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
8 9 10 |
# File 'lib/weeblycloud/cloudresource.rb', line 8 def properties @properties end |
Instance Method Details
#[](prop) ⇒ Object
Get a property. Returns nil if the property does not exist.
41 42 43 |
# File 'lib/weeblycloud/cloudresource.rb', line 41 def [](prop) get_property(prop) end |
#get ⇒ Object
Gets the resources with an API call
56 57 58 59 |
# File 'lib/weeblycloud/cloudresource.rb', line 56 def get @response = @client.get(@endpoint) @properties = @response.json end |
#get_property(prop) ⇒ Object
Get a property. Returns nil if the property does not exist.
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/weeblycloud/cloudresource.rb', line 26 def get_property(prop) begin return @properties.fetch(prop) raise KeyError if @got return nil else get() @got = true return get_property(prop) end end end |
#id ⇒ Object
Returns the ID for the resource object
51 52 53 |
# File 'lib/weeblycloud/cloudresource.rb', line 51 def id raise "Method not implemented." end |
#to_s ⇒ Object
Returns the properties as a json string
46 47 48 |
# File 'lib/weeblycloud/cloudresource.rb', line 46 def to_s @properties.to_json end |