Sha256: e937b38428f99fa59a13a101051fc09ca2ac46291559e125f9046a5b123ec42e
Contents?: true
Size: 1.24 KB
Versions: 1
Compression:
Stored size: 1.24 KB
Contents
require 'weeblycloud/cloudclient/cloudclient' require 'json' module Weeblycloud # A base resource that all other resources inherit from. class CloudResource attr_reader :properties 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 # Get a property. Returns nil if the property does not exist. 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 # Get a property. Returns nil if the property does not exist. def [](prop) get_property(prop) end # Returns the properties as a json string def to_s @properties.to_json end # Returns the ID for the resource object def id raise "Method not implemented." end # Gets the resources with an API call def get @response = @client.get(@endpoint) @properties = @response.json end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
weeblycloud-1.0.0 | lib/weeblycloud/cloudresource.rb |