Class: Cloudkick::Nodes

Inherits:
Base
  • Object
show all
Defined in:
lib/cloudkick/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#access_token, #consumer

Constructor Details

#initialize(query = nil) ⇒ Nodes

Returns a new instance of Nodes.



47
48
49
50
# File 'lib/cloudkick/node.rb', line 47

def initialize(query=nil)
  @query = query
  @nodes = get
end

Instance Attribute Details

#nodesObject (readonly)

Returns the value of attribute nodes.



45
46
47
# File 'lib/cloudkick/node.rb', line 45

def nodes
  @nodes
end

#queryObject (readonly)

Returns the value of attribute query.



45
46
47
# File 'lib/cloudkick/node.rb', line 45

def query
  @query
end

Instance Method Details

#eachObject



52
53
54
# File 'lib/cloudkick/node.rb', line 52

def each
  @nodes.each { |node| yield node }
end

#getObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/cloudkick/node.rb', line 56

def get
  if @query
    escaped = URI.escape(@query)
    resp, data = access_token.get("/1.0/query/nodes?query=#{escaped}")
  else
    resp, data = access_token.get("/1.0/query/nodes")        
  end

  hash = Crack::JSON.parse(data)
  nodes = hash.map do |node|
    Node.new(node['agent_state'], node['color'], node['id'],
             node['ipaddress'], node['name'], node['provider_id'],
             node['provider_name'], node['status'], node['tags'])
  end
end