Class: OneDriveForBusiness::Folder
Constant Summary
Constants inherited from Item
Instance Attribute Summary collapse
-
#child_count ⇒ Object
readonly
FixNum.
- #children ⇒ Object readonly
Attributes inherited from Item
Class Method Summary collapse
-
.create_with_parent_id!(drive, parent_id, name) ⇒ Object
Folder.
-
.create_with_path!(drive, path) ⇒ Object
Folder.
-
.get_by_id(drive, id) ⇒ Object
Folder.
-
.get_by_path(drive, path) ⇒ Object
Folder.
Instance Method Summary collapse
- #contents ⇒ Object
- #contents! ⇒ Object
-
#initialize(drive, fields) ⇒ Folder
constructor
A new instance of Folder.
Methods included from Util
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_count ⇒ Object (readonly)
FixNum
50 51 52 |
# File 'lib/onedrive_for_business/folder.rb', line 50 def child_count @child_count end |
#children ⇒ Object (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.
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.
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.
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.
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
#contents ⇒ Object
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 |