Class: LMC::Authority

Inherits:
Object
  • Object
show all
Defined in:
lib/lmc/authority.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, account) ⇒ Authority

Returns a new instance of Authority.



7
8
9
10
11
12
# File 'lib/lmc/authority.rb', line 7

def initialize(data, )
  # TODO: Use cloud object from account
  @cloud = Cloud.instance
  apply_data(data)
  @account = 
end

Instance Attribute Details

#accountObject

Returns the value of attribute account.



5
6
7
# File 'lib/lmc/authority.rb', line 5

def 
  @account
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/lmc/authority.rb', line 5

def id
  @id
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/lmc/authority.rb', line 5

def name
  @name
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/lmc/authority.rb', line 5

def type
  @type
end

#visibilityObject

Returns the value of attribute visibility.



5
6
7
# File 'lib/lmc/authority.rb', line 5

def visibility
  @visibility
end

Instance Method Details

#rightsObject



14
15
16
17
18
19
# File 'lib/lmc/authority.rb', line 14

def rights
  # GET /accounts/{accountId}/authorities/{authorityId}/rights
  @cloud. @account
  response = @cloud.get ['cloud-service-auth', 'accounts', @account.id, 'authorities', @id, 'rights']
  response.body.to_s
end

#saveObject

returns itself, allows chaining



22
23
24
25
26
27
28
29
30
31
# File 'lib/lmc/authority.rb', line 22

def save
  response = if @id.nil?
               Cloud.instance.post ['cloud-service-auth', 'accounts', @account.id, 'authorities'], self
             else
               raise 'editing authorities not supported'
               # @cloud.put ["cloud-service-auth", "principals", @id], self
             end
  apply_data(response.body)
  self
end

#to_json(*a) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/lmc/authority.rb', line 33

def to_json(*a)
  {
      'name' => @name,
      'type' => @type,
      'visibility' => @visibility
  }.to_json(*a)
end

#to_sObject



41
42
43
# File 'lib/lmc/authority.rb', line 41

def to_s
  "#{@name} (#{@type}/#{@visibility})"
end