Class: Aptible::Api
- Inherits:
-
HyperResource
- Object
- HyperResource
- Aptible::Api
show all
- Includes:
- GemConfig::Base
- Defined in:
- lib/aptible/api.rb
Defined Under Namespace
Classes: Account, Adapter, App, Attachment, Configuration, Container, Disk, Image, Operation, Permission, Proxy, Release, Resource, Service, Vhost
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Api
Returns a new instance of Api.
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/aptible/api.rb', line 31
def initialize(options = {})
if options.is_a?(Hash)
self.token = options[:token]
options[:root] ||= config.root_url
options[:namespace] ||= 'Aptible::Api'
options[:headers] ||= { 'Content-Type' => 'application/json' }
options[:headers].merge!(
'Authorization' => "Bearer #{bearer_token}"
) if options[:token]
end
super(options)
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
10
11
12
|
# File 'lib/aptible/api.rb', line 10
def config
@config
end
|
#token ⇒ Object
Returns the value of attribute token.
10
11
12
|
# File 'lib/aptible/api.rb', line 10
def token
@token
end
|
Class Method Details
.adapter ⇒ Object
23
24
25
|
# File 'lib/aptible/api.rb', line 23
def self.adapter
Aptible::Api::Adapter
end
|
.get_data_type_from_response(response) ⇒ Object
18
19
20
21
|
# File 'lib/aptible/api.rb', line 18
def self.get_data_type_from_response(response)
return nil unless response && response.body
adapter.get_data_type_from_object(adapter.deserialize(response.body))
end
|
Instance Method Details
#adapter ⇒ Object
27
28
29
|
# File 'lib/aptible/api.rb', line 27
def adapter
self.class.adapter
end
|
#bearer_token ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/aptible/api.rb', line 54
def bearer_token
case token
when Aptible::Auth::Token then token.access_token
when Fridge::AccessToken then token.to_s
when String then token
end
end
|
#find_by_url(url) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/aptible/api.rb', line 46
def find_by_url(url)
fail "URL must be rooted at #{root}" unless /^#{root}/.match url
resource = dup
resource.href = url.gsub(/^#{root}/, '')
resource.get
end
|