Class: EngineyardAPI::Engineyard

Inherits:
Object
  • Object
show all
Defined in:
lib/engineyard-api/engineyard.rb

Overview

Main class returned by EngineyardAPI.new(:key => “key”)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Engineyard

:nodoc

Raises:

  • (ArgumentError)

15
16
17
18
19
20
21
22
23
# File 'lib/engineyard-api/engineyard.rb', line 15

def initialize(options)  #:nodoc
	  @accounts = []
  raise ArgumentError, "API key not specified. #{self.class}.new(:key => '<api_key>')" unless options.has_key? :key
  @options=options
#      @path = "/environments/#{id}"
  @api = EngineyardAPI::EyAPI.new(@options[:key])
  EngineyardAPI.const_set("API", @api)
  reload
end

Instance Attribute Details

#accountsObject

Returns the value of attribute accounts


12
13
14
# File 'lib/engineyard-api/engineyard.rb', line 12

def accounts
  @accounts
end

Instance Method Details

#account_by_id(id) ⇒ Object

Find an account based on name. Returns EngineyardAPI::Account


53
54
55
56
57
# File 'lib/engineyard-api/engineyard.rb', line 53

def (id)
	  ac = @accounts.select { |a| a.id == id }
	  raise "No such account" unless ac.count == 1
	  return ac[0]
end

#account_by_name(name) ⇒ Object

Locate an account by name. Returns EngineyardAPI::Account


60
61
62
63
64
# File 'lib/engineyard-api/engineyard.rb', line 60

def (name)
	  ac = @accounts.select { |a| a.name == name }
	  raise "No such account" unless ac.count == 1
	  return ac[0]
end

#environment_by_id(id) ⇒ Object

Find an environment based on name. Returns EngineyardAPI::Environment


48
49
50
# File 'lib/engineyard-api/engineyard.rb', line 48

def environment_by_id(id)
  return environments.select {|e| e.environment_id == id }.first
end

#environment_by_name(name) ⇒ Object

Find an environment based on name. Returns EngineyardAPI::Environment


43
44
45
# File 'lib/engineyard-api/engineyard.rb', line 43

def environment_by_name(name)
  return environments.select {|e| e.name == name }.first
end

#environmentsObject

Returns array of environments


37
38
39
# File 'lib/engineyard-api/engineyard.rb', line 37

def environments
  return @accounts.map { || .environments }.flatten
end

#reloadObject

Call environment information from API. Information is cached in class until reload is called again. Prevents calling API when not needed.


26
27
28
29
30
31
32
33
34
# File 'lib/engineyard-api/engineyard.rb', line 26

def reload
	  =@api.get("/accounts")['accounts']
  environment_list=@api.get("/environments")['environments']
  .each {|a| @accounts << Account.new(a) }
		environment_list.each {|e|
(e['account']['id']).environments << Environment.new(e['id'],e)  
		}
  return true
end