class Weeblycloud::CloudResource

A base resource that all other resources inherit from.

Attributes

properties[R]

Public Class Methods

new(data = nil) click to toggle source
# 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

Public Instance Methods

[](prop) click to toggle source

Get a property. Returns nil if the property does not exist.

# File lib/weeblycloud/cloudresource.rb, line 41
def [](prop)
  get_property(prop)
end
get() click to toggle source

Gets the resources with an API call

# File lib/weeblycloud/cloudresource.rb, line 56
def get
  @response = @client.get(@endpoint)
  @properties = @response.json
end
get_property(prop) click to toggle source

Get a property. Returns nil if the property does not exist.

# 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() click to toggle source

Returns the ID for the resource object

# File lib/weeblycloud/cloudresource.rb, line 51
def id
  raise "Method not implemented."
end
to_s() click to toggle source

Returns the properties as a json string

# File lib/weeblycloud/cloudresource.rb, line 46
def to_s
  @properties.to_json
end