Class: Fog::Scaleway::Account::Real
- Inherits:
-
Object
- Object
- Fog::Scaleway::Account::Real
show all
- Includes:
- RequestHelper
- Defined in:
- lib/fog/scaleway/account.rb,
lib/fog/scaleway/requests/account/get_user.rb,
lib/fog/scaleway/requests/account/get_token.rb,
lib/fog/scaleway/requests/account/list_tokens.rb,
lib/fog/scaleway/requests/account/update_user.rb,
lib/fog/scaleway/requests/account/create_token.rb,
lib/fog/scaleway/requests/account/delete_token.rb,
lib/fog/scaleway/requests/account/update_token.rb,
lib/fog/scaleway/requests/account/get_organization.rb,
lib/fog/scaleway/requests/account/list_organizations.rb,
lib/fog/scaleway/requests/account/get_token_permissions.rb,
lib/fog/scaleway/requests/account/get_organization_quotas.rb
Instance Method Summary
collapse
#create, #delete, #get, #update
Constructor Details
#initialize(options) ⇒ Real
Returns a new instance of Real.
49
50
51
52
53
|
# File 'lib/fog/scaleway/account.rb', line 49
def initialize(options)
@token = options[:scaleway_token]
@email = options[:scaleway_email]
@connection_options = options[:connection_options] || {}
end
|
Instance Method Details
#create_token(options = {}) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/fog/scaleway/requests/account/create_token.rb', line 5
def create_token(options = {})
if @email.nil?
raise ArgumentError, 'email is required to create a token'
end
body = {
email: @email
}
body.merge!(options)
create('/tokens', body)
end
|
#delete_token(token_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/account/delete_token.rb', line 5
def delete_token(token_id)
delete("/tokens/#{token_id}")
end
|
#get_organization(organization_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/account/get_organization.rb', line 5
def get_organization(organization_id)
get("/organizations/#{organization_id}")
end
|
#get_organization_quotas(organization_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/account/get_organization_quotas.rb', line 5
def get_organization_quotas(organization_id)
get("/organizations/#{organization_id}/quotas")
end
|
#get_token(token_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/account/get_token.rb', line 5
def get_token(token_id)
get("/tokens/#{token_id}")
end
|
#get_token_permissions(token_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/account/get_token_permissions.rb', line 5
def get_token_permissions(token_id)
get("/tokens/#{token_id}/permissions")
end
|
#get_user(user_id) ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/account/get_user.rb', line 5
def get_user(user_id)
get("/users/#{user_id}")
end
|
#list_organizations ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/account/list_organizations.rb', line 5
def list_organizations
get('/organizations')
end
|
#list_tokens ⇒ Object
5
6
7
|
# File 'lib/fog/scaleway/requests/account/list_tokens.rb', line 5
def list_tokens
get('/tokens')
end
|
#request(params) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/fog/scaleway/account.rb', line 55
def request(params)
client.request(params)
rescue Excon::Errors::HTTPStatusError => error
decoded = Fog::Scaleway::Errors.decode_error(error)
raise if decoded.nil?
type = decoded[:type]
message = decoded[:message]
raise case type
when 'invalid_request_error', 'invalid_auth', 'unknown_resource', 'authorization_required'
Fog::Scaleway::Account.const_get(camelize(type)).slurp(error, message)
when 'api_error'
Fog::Scaleway::Account::APIError.slurp(error, message)
else
Fog::Scaleway::Account::Error.slurp(error, message)
end
end
|
#update_token(token_id, options = {}) ⇒ Object
5
6
7
8
9
10
|
# File 'lib/fog/scaleway/requests/account/update_token.rb', line 5
def update_token(token_id, options = {})
request(method: :patch,
path: "/tokens/#{token_id}",
body: options,
expects: [200])
end
|
#update_user(user_id, options = {}) ⇒ Object
5
6
7
8
9
10
|
# File 'lib/fog/scaleway/requests/account/update_user.rb', line 5
def update_user(user_id, options = {})
request(method: :patch,
path: "/users/#{user_id}",
body: options,
expects: [200])
end
|