Class: OneDriveForBusiness::Folder

Inherits:
Item
  • Object
show all
Extended by:
Util
Includes:
Util
Defined in:
lib/onedrive_for_business/folder.rb

Constant Summary

Constants inherited from Item

Item::FIELDS

Instance Attribute Summary collapse

Attributes inherited from Item

#drive

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

http

Constructor Details

#initialize(drive, fields) ⇒ Folder

Returns a new instance of Folder.



44
45
46
47
48
# File 'lib/onedrive_for_business/folder.rb', line 44

def initialize(drive, fields)
  @child_count = fields['childCount']
  @children = fields['children']
  super
end

Instance Attribute Details

#child_countObject (readonly)

FixNum



50
51
52
# File 'lib/onedrive_for_business/folder.rb', line 50

def child_count
  @child_count
end

#childrenObject (readonly)



51
52
53
# File 'lib/onedrive_for_business/folder.rb', line 51

def children
  @children
end

Class Method Details

.create_with_parent_id!(drive, parent_id, name) ⇒ Object

Returns Folder.

Returns:

  • Folder



13
14
15
16
17
18
# File 'lib/onedrive_for_business/folder.rb', line 13

def self.create_with_parent_id!(drive, parent_id, name)
  url = "#{drive.url}/files/#{parent_id}/children/#{name}"
  resp =
    http(url).put(url, nil, 'authorization' => "Bearer #{drive.access_token}")
  Folder.new(drive, JSON.parse(resp.body))
end

.create_with_path!(drive, path) ⇒ Object

Returns Folder.

Returns:

  • Folder



21
22
23
24
25
26
# File 'lib/onedrive_for_business/folder.rb', line 21

def self.create_with_path!(drive, path)
  url = "#{drive.url}/files/getbypath('#{path}')"
  resp = http(url).put(
    url, nil, 'authorization' => "Bearer #{drive.access_token}")
  Folder.new(drive, JSON.parse(resp.body))
end

.get_by_id(drive, id) ⇒ Object

Returns Folder.

Returns:

  • Folder



29
30
31
32
33
34
# File 'lib/onedrive_for_business/folder.rb', line 29

def self.get_by_id(drive, id)
  url = "#{drive.url}/files/#{id}"
  resp = http(url).get(
    url, 'authorization' => "Bearer #{drive.access_token}")
  Folder.new(drive, JSON.parse(resp.body))
end

.get_by_path(drive, path) ⇒ Object

Returns Folder.

Returns:

  • Folder



37
38
39
40
41
42
# File 'lib/onedrive_for_business/folder.rb', line 37

def self.get_by_path(drive, path)
  url = "#{drive.url}/files/getbypath('#{path}')"
  resp = http(url).get(
    url, 'authorization' => "Bearer #{drive.access_token}")
  Folder.new(drive, JSON.parse(resp.body))
end

Instance Method Details

#contentsObject



53
54
55
# File 'lib/onedrive_for_business/folder.rb', line 53

def contents
  @contents ||= contents!
end

#contents!Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/onedrive_for_business/folder.rb', line 57

def contents!
  url = "#{drive.url}/Files/#{id}/children"
  resp = http(url).get(
    url, 'authorization' => "Bearer #{drive.access_token}")
  JSON.parse(resp.body)['value'].select do |o|
    o['type'] == 'File'
  end.map do |o|
    File.new(drive, o)
  end
end