Class: Box::Item

Inherits:
Object
  • Object
show all
Extended by:
Forwardable, Memoist
Defined in:
lib/box/item.rb

Direct Known Subclasses

File, Folder

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Item

Returns a new instance of Item.



13
14
15
16
17
18
19
20
# File 'lib/box/item.rb', line 13

def initialize(*args)
  if args.size == 1
    @client, @metadata = Box.client, Hashie::Mash.new(args[0])
  else
    @client, @metadata = args[0], Hashie::Mash.new(args[1])
  end

end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



5
6
7
# File 'lib/box/item.rb', line 5

def client
  @client
end

#metadataObject

Returns the value of attribute metadata.



5
6
7
# File 'lib/box/item.rb', line 5

def 
  @metadata
end

Class Method Details

.find(id, client = Box.client) ⇒ Object



30
31
32
33
34
35
# File 'lib/box/item.rb', line 30

def self.find(id, client = Box.client)
  response = client.get("#{type.pluralize}/#{id}")
  self.new(client, response.body)
rescue Box::ResourceNotFound => e
  nil
end

.typeObject



9
10
11
# File 'lib/box/item.rb', line 9

def self.type
  self.name.demodulize.downcase
end

Instance Method Details

#file?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/box/item.rb', line 26

def file?
  type == 'file'
end

#folder?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/box/item.rb', line 22

def folder?
  type == 'folder'
end