Class: RightScale::Base
Class Method Summary
collapse
Instance Method Summary
collapse
#get_element, #has_element?, #method_missing
Constructor Details
#initialize(data) ⇒ Base
Returns a new instance of Base.
14
15
16
17
|
# File 'lib/right_api/rightscale.rb', line 14
def initialize(data)
raise "You must first establish a connection via Base.establish_connection" unless @@connection
@data = data
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class AccessibleFragment
Class Method Details
.all(opts = {}) ⇒ Object
63
64
65
|
# File 'lib/right_api/rightscale.rb', line 63
def self.all(opts={})
find_with_options(opts)
end
|
.class_name ⇒ Object
31
32
33
|
# File 'lib/right_api/rightscale.rb', line 31
def self.class_name
name.split("::").last.underscore
end
|
.establish_connection(user, password, account_id) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/right_api/rightscale.rb', line 44
def self.establish_connection(user, password, account_id)
url = "https://my.rightscale.com/api/acct/#{account_id}"
params = {'server_url' => url, 'username' => user, 'password' => password}
@@connection = HttpServer.new(params, 60)
@@connection.get('/login')
params = {'server_url' => "https://my.rightscale.com"}
@@non_api_connection = HttpServer.new(params, 60)
@@non_api_connection.post('/sessions', 'email' => user, 'password' => password) do |server, response|
cookies = response.response.get_fields('set-cookie')
session_cookie = cookies.detect { |cookie| cookie =~ /_session_id/ }
= session_cookie.split(';').first
server. = server..merge('cookie' => , 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
end
end
|
.find(opts = nil) ⇒ Object
71
72
73
74
75
76
77
78
79
|
# File 'lib/right_api/rightscale.rb', line 71
def self.find(opts=nil)
if opts.nil?
raise "Find requires a hash of options or an id"
elsif opts.is_a?(Hash)
find_with_options(opts)
else
find(:id => opts)
end
end
|
.first(opts = {}) ⇒ Object
67
68
69
|
# File 'lib/right_api/rightscale.rb', line 67
def self.first(opts={})
find_first_with_options(opts)
end
|
.plural_name ⇒ Object
35
36
37
|
# File 'lib/right_api/rightscale.rb', line 35
def self.plural_name
class_name.pluralize
end
|
.xml_name ⇒ Object
39
40
41
|
# File 'lib/right_api/rightscale.rb', line 39
def self.xml_name
class_name.dasherize
end
|
Instance Method Details
#data ⇒ Object
23
24
25
|
# File 'lib/right_api/rightscale.rb', line 23
def data
@data ||= @@connection.get("/#{plural_name}/#{id}")
end
|
#id ⇒ Object
19
20
21
|
# File 'lib/right_api/rightscale.rb', line 19
def id
@id ||= href.split('/').last
end
|
#update_attribute(attribute, value) ⇒ Object
27
28
29
|
# File 'lib/right_api/rightscale.rb', line 27
def update_attribute(attribute, value)
@@connection.put("/#{self.class.plural_name}/#{id}", "#{self.class.class_name}[#{attribute}]" => value)
end
|