Class: RightScale::API
- Inherits:
-
Object
show all
- Defined in:
- lib/rightscale-api/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/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/api.rb', line 3
def client
@client
end
|
Instance Method Details
#create ⇒ Object
24
25
26
|
# File 'lib/rightscale-api/api.rb', line 24
def create
end
|
#destroy(identifier) ⇒ Object
32
33
34
|
# File 'lib/rightscale-api/api.rb', line 32
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.
40
41
42
43
44
45
46
|
# File 'lib/rightscale-api/api.rb', line 40
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/api.rb', line 12
def index
response = client.get("/#{@resource}.#{@format}")
return response["#{@resource}"]
end
|
#show(identifier) ⇒ Object
17
18
19
20
21
22
|
# File 'lib/rightscale-api/api.rb', line 17
def show(identifier)
response = client.get formatted_uri(identifier)
return response["#{@singular}"] || response
end
|
#update ⇒ Object
28
29
30
|
# File 'lib/rightscale-api/api.rb', line 28
def update
end
|