Class: RightScale::API
- Inherits:
-
Object
show all
- Defined in:
- lib/rightscale/api.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(client, options = {}) ⇒ API
Returns a new instance of API.
5
6
7
8
9
10
|
# File 'lib/rightscale/api.rb', line 5
def initialize(client, options = {})
@client = client
@resource = options[:resource] || self.class.name.split('::').last.downcase
@singular = @resource.chop
@format = 'xml'
end
|
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
3
4
5
|
# File 'lib/rightscale/api.rb', line 3
def client
@client
end
|
Instance Method Details
#create ⇒ Object
23
24
25
|
# File 'lib/rightscale/api.rb', line 23
def create
end
|
#destroy(identifier) ⇒ Object
31
32
33
|
# File 'lib/rightscale/api.rb', line 31
def destroy(identifier)
response = client.delete("/#{@resource}/#{identifier}")
end
|
As discussed in more detail in the RightScale API Overview Guide, every major resource exported by the RightScale API will always have an href field that corresponds to the URL of the resource listed.
39
40
41
42
43
44
45
|
# File 'lib/rightscale/api.rb', line 39
def formatted_uri(identifier)
if identifier.is_a?(String)
identifier.gsub(client.class.base_uri, '')
else
"/#{@resource}/#{identifier}.#{@format}"
end
end
|
#index ⇒ Object
12
13
14
15
|
# File 'lib/rightscale/api.rb', line 12
def index
response = client.get("/#{@resource}.#{@format}")
return response["#{@resource}"]
end
|
#show(identifier) ⇒ Object
17
18
19
20
21
|
# File 'lib/rightscale/api.rb', line 17
def show(identifier)
puts formatted_uri(identifier)
response = client.get formatted_uri(identifier)
return response["#{@singular}"]
end
|
#update ⇒ Object
27
28
29
|
# File 'lib/rightscale/api.rb', line 27
def update
end
|