Class: Folder

Inherits:
Object
  • Object
show all
Defined in:
lib/models/folder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, id: nil, accounts: []) ⇒ Folder

Returns a new instance of Folder.



6
7
8
9
10
# File 'lib/models/folder.rb', line 6

def initialize(name: nil, id: nil, accounts: [])
  @name = name
  @id = id
  @accounts = accounts
end

Instance Attribute Details

#accountsObject (readonly)

Returns the value of attribute accounts.



4
5
6
# File 'lib/models/folder.rb', line 4

def accounts
  @accounts
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/models/folder.rb', line 4

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/models/folder.rb', line 4

def name
  @name
end

Class Method Details

.find(id) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/models/folder.rb', line 13

def find(id)
  json = JSON.parse(CryptopusAdapter.new.get("folders/#{id}"),
                    symbolize_names: true)
  included = json[:included] || []
  name = json[:data][:attributes][:name]
  accounts = included.map do |record|
    Account.from_json(record.to_json) if %w[account_ose_secrets
                                            account_credentials].include? record[:type]
  end.compact
  Folder.new(id: id, name: name, accounts: accounts)
end