Class: WebbyNode::Webby

Inherits:
APIObject show all
Defined in:
lib/webbynode-api/data.rb

Overview

Represents an individual webby with status, reboot/shutdown/start functionality via method_missing

Since:

  • 0.0.1

Version:

  • 0.1.0

Instance Attribute Summary collapse

Attributes inherited from APIObject

#data, #email, #token

Instance Method Summary collapse

Methods inherited from APIObject

#auth_get, #auth_post, auth_post

Constructor Details

#initialize(options = {}) ⇒ Webby

Fetches an individual Webby’s data.

Examples:

Fetch data for a Webby named “webby1”

@webby = WebbyNode::Webby.new(:email => email, :token => token, "webby1")

Options Hash (options):

  • :email (String)

    E-mail address used for API access

  • :token (String)

    API token used for API access

  • :hostname (String)

    Hostname used to look up an individual Webby. When absent or nil, the newly instantiated object instead represents an Array of Webbies.

Raises:

  • (ArgumentError)

Since:

  • 0.0.1



39
40
41
42
43
# File 'lib/webbynode-api/data.rb', line 39

def initialize(options = {})
  raise ArgumentError, ":hostname is a required argument" unless options[:hostname]
  super(options)
  @hostname = options[:hostname]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object

Provides status, start/shutdown/reboot functionality for an individual Webby.

Since:

  • 0.0.1



47
48
49
50
51
52
53
54
55
# File 'lib/webbynode-api/data.rb', line 47

def method_missing(method)
  if method.to_s == "status"
    return auth_get("/api/xml/webby/#{@hostname}/status")["hash"]["status"]
  elsif %w(start shutdown reboot).include? method.to_s
    return auth_get("/api/xml/webby/#{@hostname}/#{method.to_s}")["hash"]["job_id"]
  else
    raise ArgumentError, "No such action possible on a Webby."
  end
end

Instance Attribute Details

#hostnameObject

Since:

  • 0.0.1



28
29
30
# File 'lib/webbynode-api/data.rb', line 28

def hostname
  @hostname
end