microslop_one_drive 2.2.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +72 -6
- data/lib/microslop_one_drive/batch/batch_response.rb +15 -0
- data/lib/microslop_one_drive/batch/response.rb +18 -0
- data/lib/microslop_one_drive/client.rb +14 -154
- data/lib/microslop_one_drive/deserializers/drive_deserializer.rb +57 -0
- data/lib/microslop_one_drive/deserializers/drive_item_deserializer.rb +67 -0
- data/lib/microslop_one_drive/deserializers/parent_reference_deserializer.rb +20 -0
- data/lib/microslop_one_drive/deserializers/quota_deserializer.rb +24 -0
- data/lib/microslop_one_drive/deserializers/shared_with_me_item_deserializer.rb +48 -0
- data/lib/microslop_one_drive/deserializers/user_deserializer.rb +29 -0
- data/lib/microslop_one_drive/drive.rb +40 -10
- data/lib/microslop_one_drive/drive_item.rb +61 -63
- data/lib/microslop_one_drive/endpoints/all_drives.rb +17 -0
- data/lib/microslop_one_drive/endpoints/batch.rb +37 -0
- data/lib/microslop_one_drive/endpoints/batch_permissions.rb +42 -0
- data/lib/microslop_one_drive/endpoints/delta.rb +19 -0
- data/lib/microslop_one_drive/endpoints/drive.rb +27 -0
- data/lib/microslop_one_drive/endpoints/drive_exists.rb +15 -0
- data/lib/microslop_one_drive/endpoints/drive_item.rb +20 -0
- data/lib/microslop_one_drive/endpoints/drive_item_exists.rb +22 -0
- data/lib/microslop_one_drive/endpoints/me.rb +14 -0
- data/lib/microslop_one_drive/endpoints/permissions.rb +36 -0
- data/lib/microslop_one_drive/endpoints/shared_with_me.rb +14 -0
- data/lib/microslop_one_drive/endpoints/supports_sites.rb +27 -0
- data/lib/microslop_one_drive/file.rb +13 -0
- data/lib/microslop_one_drive/folder.rb +13 -0
- data/lib/microslop_one_drive/list_responses/drive_item_list.rb +21 -0
- data/lib/microslop_one_drive/list_responses/drive_list.rb +15 -0
- data/lib/microslop_one_drive/list_responses/list_response.rb +21 -0
- data/lib/microslop_one_drive/list_responses/permission_list.rb +27 -0
- data/lib/microslop_one_drive/list_responses/shared_with_me_list.rb +15 -0
- data/lib/microslop_one_drive/parent_reference.rb +14 -0
- data/lib/microslop_one_drive/permission_set.rb +13 -15
- data/lib/microslop_one_drive/quota.rb +14 -0
- data/lib/microslop_one_drive/root_folder.rb +13 -0
- data/lib/microslop_one_drive/shared_with_me_item.rb +44 -0
- data/lib/microslop_one_drive/user.rb +33 -5
- data/lib/microslop_one_drive/utils.rb +10 -0
- data/lib/microslop_one_drive/version.rb +1 -1
- data/lib/microslop_one_drive.rb +47 -8
- metadata +37 -67
- data/lib/microslop_one_drive/batch_response.rb +0 -13
- data/lib/microslop_one_drive/drive_item_list.rb +0 -32
- data/lib/microslop_one_drive/drive_list.rb +0 -13
- data/lib/microslop_one_drive/list_response.rb +0 -21
- data/lib/microslop_one_drive/permission_list.rb +0 -29
- data/lib/microslop_one_drive/response.rb +0 -16
|
@@ -4,53 +4,70 @@ module MicroslopOneDrive
|
|
|
4
4
|
|
|
5
5
|
attr_reader :id,
|
|
6
6
|
:name,
|
|
7
|
-
:
|
|
8
|
-
:
|
|
9
|
-
:url,
|
|
7
|
+
:download_url,
|
|
8
|
+
:web_url,
|
|
10
9
|
:size,
|
|
10
|
+
:created_date_time,
|
|
11
|
+
:last_modified_date_time,
|
|
12
|
+
:e_tag,
|
|
13
|
+
:c_tag,
|
|
11
14
|
:file_or_folder,
|
|
12
|
-
:parent_id,
|
|
13
15
|
:mime_type,
|
|
14
|
-
:
|
|
15
|
-
:
|
|
16
|
-
:
|
|
17
|
-
:full_path
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
@
|
|
39
|
-
|
|
40
|
-
@
|
|
16
|
+
:parent_reference,
|
|
17
|
+
:is_deleted,
|
|
18
|
+
:is_shared,
|
|
19
|
+
:full_path,
|
|
20
|
+
:path
|
|
21
|
+
|
|
22
|
+
def initialize(
|
|
23
|
+
id:,
|
|
24
|
+
name:,
|
|
25
|
+
download_url:,
|
|
26
|
+
web_url:,
|
|
27
|
+
size:,
|
|
28
|
+
created_date_time:,
|
|
29
|
+
last_modified_date_time:,
|
|
30
|
+
e_tag:,
|
|
31
|
+
c_tag:,
|
|
32
|
+
file_or_folder:,
|
|
33
|
+
mime_type:,
|
|
34
|
+
parent_reference:,
|
|
35
|
+
is_deleted:,
|
|
36
|
+
is_shared:
|
|
37
|
+
)
|
|
38
|
+
@id = id
|
|
39
|
+
@name = name
|
|
40
|
+
@download_url = download_url
|
|
41
|
+
@web_url = web_url
|
|
42
|
+
@size = size
|
|
43
|
+
@created_date_time = created_date_time
|
|
44
|
+
@last_modified_date_time = last_modified_date_time
|
|
45
|
+
@e_tag = e_tag
|
|
46
|
+
@c_tag = c_tag
|
|
47
|
+
@file_or_folder = file_or_folder
|
|
48
|
+
@mime_type = mime_type
|
|
49
|
+
@parent_reference = parent_reference
|
|
50
|
+
@is_deleted = is_deleted
|
|
51
|
+
@is_shared = is_shared
|
|
52
|
+
|
|
53
|
+
@full_path = build_full_path
|
|
54
|
+
@path = build_path(@full_path)
|
|
55
|
+
end
|
|
41
56
|
|
|
42
|
-
|
|
57
|
+
def created_at
|
|
58
|
+
@created_date_time
|
|
59
|
+
end
|
|
43
60
|
|
|
44
|
-
|
|
45
|
-
@
|
|
61
|
+
def updated_at
|
|
62
|
+
@last_modified_date_time
|
|
46
63
|
end
|
|
47
64
|
|
|
48
65
|
def deleted?
|
|
49
|
-
@
|
|
66
|
+
@is_deleted
|
|
50
67
|
end
|
|
51
68
|
|
|
52
69
|
def shared?
|
|
53
|
-
@
|
|
70
|
+
@is_shared
|
|
54
71
|
end
|
|
55
72
|
|
|
56
73
|
def file?
|
|
@@ -61,39 +78,20 @@ module MicroslopOneDrive
|
|
|
61
78
|
@file_or_folder == :folder
|
|
62
79
|
end
|
|
63
80
|
|
|
64
|
-
def
|
|
65
|
-
|
|
66
|
-
@parent.remove_child(self)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
@parent = parent
|
|
70
|
-
@parent.add_child(self)
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def is_root?
|
|
74
|
-
@item_hash.key?("root")
|
|
81
|
+
def root?
|
|
82
|
+
false
|
|
75
83
|
end
|
|
76
84
|
|
|
77
|
-
|
|
85
|
+
def build_full_path
|
|
86
|
+
return nil if parent_reference&.path.nil? || name.nil?
|
|
78
87
|
|
|
79
|
-
|
|
80
|
-
@children << child
|
|
88
|
+
::File.join(parent_reference.path, name)
|
|
81
89
|
end
|
|
82
90
|
|
|
83
|
-
def
|
|
84
|
-
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
private
|
|
88
|
-
|
|
89
|
-
def build_path
|
|
90
|
-
return "root:" if is_root?
|
|
91
|
-
|
|
92
|
-
full_parent_path = @item_hash.dig("parentReference", "path")
|
|
93
|
-
return nil if full_parent_path.nil?
|
|
91
|
+
def build_path(full_path)
|
|
92
|
+
return "" if full_path.nil?
|
|
94
93
|
|
|
95
|
-
|
|
96
|
-
full_path_with_name.sub(/\A.*root:\//, "root:/")
|
|
94
|
+
full_path.gsub(%r{\A/?drive/root:/?}, "").chomp("/")
|
|
97
95
|
end
|
|
98
96
|
end
|
|
99
97
|
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
module Endpoints
|
|
3
|
+
module AllDrives
|
|
4
|
+
# Gets ALL Drives the current user has access to.
|
|
5
|
+
#
|
|
6
|
+
# NOTE: This will include some internal Microsoft drives that aren't real drives, such as AI, Face scans, and other
|
|
7
|
+
# shitty things.
|
|
8
|
+
#
|
|
9
|
+
# @return [MicroslopOneDrive::DriveList]
|
|
10
|
+
def all_drives
|
|
11
|
+
response = get(path: "me/drives", query: {})
|
|
12
|
+
handle_error(response) unless response.success?
|
|
13
|
+
MicroslopOneDrive::ListResponses::DriveList.new(response.parsed_response)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
module Endpoints
|
|
3
|
+
module Batch
|
|
4
|
+
BATCH_REQUEST_LIMIT = 20 # This is set by Microsoft
|
|
5
|
+
|
|
6
|
+
# Makes a batch request to the Microsoft Graph API.
|
|
7
|
+
#
|
|
8
|
+
# @param requests [Array<Hash>] The requests to make. Each request should be a hash with the following keys:
|
|
9
|
+
# - id: The ID of the request.
|
|
10
|
+
# - method: The HTTP method to use for the request.
|
|
11
|
+
# - url: The URL to make the request to.
|
|
12
|
+
#
|
|
13
|
+
# Note: Microsoft allows a maximum of 20 requests per batch. If you pass more than 20 requests, the client will
|
|
14
|
+
# make multiple batch requests to Microsoft. This might make this a slow method.
|
|
15
|
+
#
|
|
16
|
+
# @return [MicroslopOneDrive::BatchResponse]
|
|
17
|
+
def batch(requests:)
|
|
18
|
+
batch_response = MicroslopOneDrive::Batch::BatchResponse.new
|
|
19
|
+
|
|
20
|
+
# No requests, so simply return an empty batch response:
|
|
21
|
+
return batch_response if requests.empty?
|
|
22
|
+
|
|
23
|
+
batches = requests.each_slice(BATCH_REQUEST_LIMIT).to_a
|
|
24
|
+
batches.each do
|
|
25
|
+
response = post(path: "$batch", body: {requests: it}.to_json)
|
|
26
|
+
handle_error(response) unless response.success?
|
|
27
|
+
new_responses = response.parsed_response.fetch("responses", [])
|
|
28
|
+
new_responses.each do
|
|
29
|
+
batch_response.add_response(MicroslopOneDrive::Batch::Response.new(it))
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
batch_response
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
module Endpoints
|
|
3
|
+
module BatchPermissions
|
|
4
|
+
# Gets the permissions for multiple Drive Items.
|
|
5
|
+
#
|
|
6
|
+
# Uses the batch Microsoft Graph API to make multiple API calls in batches of 20 (the max Microsoft allows on their
|
|
7
|
+
# batch endpoint).
|
|
8
|
+
#
|
|
9
|
+
# See: https://learn.microsoft.com/en-us/graph/json-batching
|
|
10
|
+
#
|
|
11
|
+
# @param drive_id [String, nil] The ID of the Drive to get the permissions of. If not provided, the current User's
|
|
12
|
+
# default Drive will be used.
|
|
13
|
+
# @param item_ids [Array<String>] The IDs of the Drive Items to get the permissions of.
|
|
14
|
+
#
|
|
15
|
+
# @return [Array<MicroslopOneDrive::Permission>]
|
|
16
|
+
def batch_permissions(item_ids:, drive_id: nil)
|
|
17
|
+
requests = build_batch_permissions_requests(item_ids: item_ids, drive_id: drive_id)
|
|
18
|
+
batch_response = batch(requests: requests)
|
|
19
|
+
successful_responses = batch_response.responses.select(&:success?)
|
|
20
|
+
|
|
21
|
+
permission_lists = successful_responses.map do
|
|
22
|
+
MicroslopOneDrive::ListResponses::PermissionList.new(
|
|
23
|
+
drive_item_id: it.id,
|
|
24
|
+
parsed_response: it.body
|
|
25
|
+
)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
permission_lists.flat_map(&:permissions)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def build_batch_permissions_requests(item_ids:, drive_id: nil)
|
|
34
|
+
if drive_id.nil?
|
|
35
|
+
item_ids.map { {id: it, method: "GET", url: "/me/drive/items/#{it}/permissions"} }
|
|
36
|
+
else
|
|
37
|
+
item_ids.map { {id: it, method: "GET", url: "/me/drives/#{drive_id}/items/#{it}/permissions"} }
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
module Endpoints
|
|
3
|
+
module Delta
|
|
4
|
+
# Gets a delta of changes in a Drive.
|
|
5
|
+
#
|
|
6
|
+
# @param drive_id [String, nil] The ID of the Drive to get the delta of. If not provided, the current User's default
|
|
7
|
+
# Drive will be used.
|
|
8
|
+
# @param token [String, nil] The token to use for the delta. If not provided, the initial delta will be returned.
|
|
9
|
+
#
|
|
10
|
+
# @return [MicroslopOneDrive::DriveItemList]
|
|
11
|
+
def delta(drive_id: nil, token: nil)
|
|
12
|
+
url = drive_id.nil? ? "me/drive/root/delta" : "me/drives/#{drive_id}/root/delta"
|
|
13
|
+
response = get(path: url, query: {token: token})
|
|
14
|
+
handle_error(response) unless response.success?
|
|
15
|
+
MicroslopOneDrive::ListResponses::DriveItemList.new(response.parsed_response)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
module Endpoints
|
|
3
|
+
module Drive
|
|
4
|
+
# Gets a Drive.
|
|
5
|
+
#
|
|
6
|
+
# If no drive_id is provided, the current User's default Drive will be returned, else, the specific Drive identified
|
|
7
|
+
# by the drive_id will be returned.
|
|
8
|
+
#
|
|
9
|
+
# From the docs:
|
|
10
|
+
#
|
|
11
|
+
# > Most users will only have a single Drive resource.
|
|
12
|
+
# > Groups and Sites may have multiple Drive resources available.
|
|
13
|
+
#
|
|
14
|
+
# @param drive_id [String, nil] The ID of the Drive to get. If not provided, the current User's default Drive will
|
|
15
|
+
# be returned.
|
|
16
|
+
#
|
|
17
|
+
# @return [MicroslopOneDrive::Drive]
|
|
18
|
+
def drive(drive_id: nil)
|
|
19
|
+
url = drive_id.nil? ? "me/drive" : "me/drives/#{drive_id}"
|
|
20
|
+
response = get(path: url, query: {})
|
|
21
|
+
|
|
22
|
+
handle_error(response) unless response.success?
|
|
23
|
+
MicroslopOneDrive::Deserializers::DriveDeserializer.create_from_hash(response.parsed_response)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
module Endpoints
|
|
3
|
+
module DriveExists
|
|
4
|
+
# Asks if a Drive exists by its ID.
|
|
5
|
+
#
|
|
6
|
+
# @param drive_id [String] The ID of the Drive to check.
|
|
7
|
+
#
|
|
8
|
+
# @return [Boolean]
|
|
9
|
+
def drive_exists?(drive_id:)
|
|
10
|
+
response = get(path: "me/drives/#{drive_id}", query: {})
|
|
11
|
+
response.success?
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
module Endpoints
|
|
3
|
+
module DriveItem
|
|
4
|
+
# Gets a specific DriveItem (folder or file)
|
|
5
|
+
#
|
|
6
|
+
# @param drive_id [String, nil] The ID of the Drive to get the Drive Item from. If not provided, the current User's
|
|
7
|
+
# default Drive will be used.
|
|
8
|
+
# @param item_id [String] The ID of the Drive Item to get.
|
|
9
|
+
#
|
|
10
|
+
# @return [MicroslopOneDrive::DriveItem]
|
|
11
|
+
def drive_item(item_id:, drive_id: nil)
|
|
12
|
+
url = drive_id.nil? ? "me/drive/items/#{item_id}" : "me/drives/#{drive_id}/items/#{item_id}"
|
|
13
|
+
response = get(path: url, query: {})
|
|
14
|
+
|
|
15
|
+
handle_error(response) unless response.success?
|
|
16
|
+
MicroslopOneDrive::Deserializers::DriveItemDeserializer.create_from_hash(response.parsed_response)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
module Endpoints
|
|
3
|
+
module DriveItemExists
|
|
4
|
+
# Asks if a DriveItem (folder or file) exists by its ID.
|
|
5
|
+
#
|
|
6
|
+
# @param drive_id [String, nil] The ID of the Drive to check the Drive Item in. If not provided, the current User's
|
|
7
|
+
# default Drive will be used.
|
|
8
|
+
# @param item_id [String] The ID of the Drive Item to check.
|
|
9
|
+
#
|
|
10
|
+
# @return [Boolean]
|
|
11
|
+
def drive_item_exists?(item_id:, drive_id: nil)
|
|
12
|
+
url = drive_id.nil? ? "me/drive/items/#{item_id}" : "me/drives/#{drive_id}/items/#{item_id}"
|
|
13
|
+
response = get(path: url, query: {})
|
|
14
|
+
|
|
15
|
+
return false if response.code == 404
|
|
16
|
+
return true if response.success?
|
|
17
|
+
|
|
18
|
+
handle_error(response)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
module Endpoints
|
|
3
|
+
module Me
|
|
4
|
+
# Gets the current user
|
|
5
|
+
#
|
|
6
|
+
# @return [MicroslopOneDrive::User]
|
|
7
|
+
def me
|
|
8
|
+
response = get(path: "me", query: {})
|
|
9
|
+
handle_error(response) unless response.success?
|
|
10
|
+
MicroslopOneDrive::Deserializers::UserDeserializer.create_from_hash(response.parsed_response)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
module Endpoints
|
|
3
|
+
module Permissions
|
|
4
|
+
# Gets the permissions for a DriveItem (folder or file) in a Drive.
|
|
5
|
+
#
|
|
6
|
+
# @param drive_id [String, nil] The ID of the Drive to get the permissions of. If not provided, the current User's
|
|
7
|
+
# default Drive will be used.
|
|
8
|
+
# @param item_id [String] The ID of the Drive Item to get the permissions of.
|
|
9
|
+
#
|
|
10
|
+
# @return [MicroslopOneDrive::PermissionList]
|
|
11
|
+
def permissions(item_id:, drive_id: nil)
|
|
12
|
+
url = if drive_id.nil?
|
|
13
|
+
"me/drive/items/#{item_id}/permissions"
|
|
14
|
+
else
|
|
15
|
+
"me/drives/#{drive_id}/items/#{item_id}/permissions"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
response = get(path: url, query: {})
|
|
19
|
+
|
|
20
|
+
if response.code == 404
|
|
21
|
+
return MicroslopOneDrive::ListResponses::PermissionList.new(
|
|
22
|
+
drive_item_id: item_id,
|
|
23
|
+
parsed_response: {"value" => []}
|
|
24
|
+
)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
handle_error(response) unless response.success?
|
|
28
|
+
|
|
29
|
+
MicroslopOneDrive::ListResponses::PermissionList.new(
|
|
30
|
+
drive_item_id: item_id,
|
|
31
|
+
parsed_response: response.parsed_response
|
|
32
|
+
)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
module Endpoints
|
|
3
|
+
module SharedWithMe
|
|
4
|
+
# Gets the Drive Items shared with the current user.
|
|
5
|
+
#
|
|
6
|
+
# @return [MicroslopOneDrive::SharedWithMeList]
|
|
7
|
+
def shared_with_me
|
|
8
|
+
response = get(path: "me/drive/sharedWithMe")
|
|
9
|
+
handle_error(response) unless response.success?
|
|
10
|
+
MicroslopOneDrive::ListResponses::SharedWithMeList.new(response.parsed_response)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
module Endpoints
|
|
3
|
+
module SupportsSites
|
|
4
|
+
# Asks if the user's account supports SharePoint.
|
|
5
|
+
#
|
|
6
|
+
# Does this by checking if the user's account has a root SharePoint Site.
|
|
7
|
+
#
|
|
8
|
+
# @return [Boolean]
|
|
9
|
+
def supports_sites?
|
|
10
|
+
response = get(path: "me/sites/root", query: {})
|
|
11
|
+
|
|
12
|
+
return true if response.success?
|
|
13
|
+
return false if response_indicates_no_sites?(response)
|
|
14
|
+
|
|
15
|
+
handle_error(response)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def response_indicates_no_sites?(response)
|
|
21
|
+
response.bad_request? &&
|
|
22
|
+
response.parsed_response.dig("error", "code") == "BadRequest" &&
|
|
23
|
+
response.parsed_response.dig("error", "message").match?(/This API is not supported for MSA accounts/i)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
module ListResponses
|
|
3
|
+
class DriveItemList < ListResponse
|
|
4
|
+
attr_reader :items
|
|
5
|
+
|
|
6
|
+
def initialize(parsed_response)
|
|
7
|
+
super
|
|
8
|
+
|
|
9
|
+
@items = build_items(parsed_response)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
def build_items(parsed_response)
|
|
15
|
+
parsed_response.fetch("value", []).map do
|
|
16
|
+
MicroslopOneDrive::Deserializers::DriveItemDeserializer.create_from_hash(it)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
module ListResponses
|
|
3
|
+
class DriveList < ListResponse
|
|
4
|
+
attr_reader :drives
|
|
5
|
+
|
|
6
|
+
def initialize(response_hash)
|
|
7
|
+
super
|
|
8
|
+
|
|
9
|
+
@drives = response_hash.fetch("value", []).map do
|
|
10
|
+
MicroslopOneDrive::Deserializers::DriveDeserializer.create_from_hash(it)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
module ListResponses
|
|
3
|
+
class ListResponse
|
|
4
|
+
attr_reader :next_link, :next_token, :delta_link, :delta_token, :context
|
|
5
|
+
|
|
6
|
+
def initialize(response_hash)
|
|
7
|
+
@context = response_hash.fetch("@odata.context", nil)
|
|
8
|
+
|
|
9
|
+
@next_link = response_hash.fetch("@odata.nextLink", nil)
|
|
10
|
+
@next_token = @next_link.split("?token=").last if @next_link && !@next_link.empty?
|
|
11
|
+
|
|
12
|
+
@delta_link = response_hash.fetch("@odata.deltaLink", nil)
|
|
13
|
+
@delta_token = @delta_link.split("?token=").last if @delta_link && !@delta_link.empty?
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def next_page?
|
|
17
|
+
!next_link.nil?
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
module ListResponses
|
|
3
|
+
class PermissionList < ListResponse
|
|
4
|
+
attr_reader :permissions
|
|
5
|
+
|
|
6
|
+
def initialize(drive_item_id:, parsed_response:)
|
|
7
|
+
super(parsed_response)
|
|
8
|
+
|
|
9
|
+
@permissions = build_permissions(drive_item_id, parsed_response)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
def build_permissions(drive_item_id, parsed_response)
|
|
15
|
+
permission_sets = parsed_response.fetch("value", []).map do
|
|
16
|
+
MicroslopOneDrive::PermissionSet.new(drive_item_id: drive_item_id, parsed_response: it)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# At this stage, the permissions could contain multiple Audiences for the same Permission.
|
|
20
|
+
# This is because OneDrive can return multiple permissions for the same thing.
|
|
21
|
+
# For example, a file shared with one person and a public link will return in a single permission object.
|
|
22
|
+
# We therefore need to "explode" the permission sets into multiple permissions, one for each Audience.
|
|
23
|
+
permission_sets.flat_map(&:to_permissions)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
module ListResponses
|
|
3
|
+
class SharedWithMeList < ListResponse
|
|
4
|
+
attr_reader :shared_with_me_items
|
|
5
|
+
|
|
6
|
+
def initialize(response_hash)
|
|
7
|
+
super
|
|
8
|
+
|
|
9
|
+
@shared_with_me_items = response_hash.fetch("value", []).map do
|
|
10
|
+
MicroslopOneDrive::Deserializers::SharedWithMeItemDeserializer.create_from_hash(it)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
class ParentReference
|
|
3
|
+
attr_reader :drive_type, :drive_id, :id, :name, :path, :site_id
|
|
4
|
+
|
|
5
|
+
def initialize(drive_type:, drive_id:, id:, name:, path:, site_id:)
|
|
6
|
+
@drive_type = drive_type
|
|
7
|
+
@drive_id = drive_id
|
|
8
|
+
@id = id
|
|
9
|
+
@name = name
|
|
10
|
+
@path = path
|
|
11
|
+
@site_id = site_id
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -3,12 +3,10 @@ module MicroslopOneDrive
|
|
|
3
3
|
attr_reader :id, :role, :audiences
|
|
4
4
|
|
|
5
5
|
def initialize(drive_item_id:, parsed_response:)
|
|
6
|
-
@parsed_response = parsed_response
|
|
7
|
-
|
|
8
6
|
@drive_item_id = drive_item_id
|
|
9
|
-
@id =
|
|
10
|
-
@role = build_role
|
|
11
|
-
@audiences = build_audiences
|
|
7
|
+
@id = parsed_response.fetch("id", nil)
|
|
8
|
+
@role = build_role(parsed_response)
|
|
9
|
+
@audiences = build_audiences(parsed_response)
|
|
12
10
|
end
|
|
13
11
|
|
|
14
12
|
def to_permissions
|
|
@@ -17,31 +15,31 @@ module MicroslopOneDrive
|
|
|
17
15
|
|
|
18
16
|
private
|
|
19
17
|
|
|
20
|
-
def build_role
|
|
21
|
-
roles =
|
|
18
|
+
def build_role(parsed_response)
|
|
19
|
+
roles = parsed_response.fetch("roles", [])
|
|
22
20
|
roles.is_a?(Array) ? roles.first : roles
|
|
23
21
|
end
|
|
24
22
|
|
|
25
|
-
def build_audiences
|
|
23
|
+
def build_audiences(parsed_response)
|
|
26
24
|
audiences = []
|
|
27
25
|
|
|
28
|
-
audiences += audiences_from_site_users
|
|
29
|
-
audiences += audiences_from_anonymous_links
|
|
26
|
+
audiences += audiences_from_site_users(parsed_response)
|
|
27
|
+
audiences += audiences_from_anonymous_links(parsed_response)
|
|
30
28
|
|
|
31
29
|
audiences.compact
|
|
32
30
|
end
|
|
33
31
|
|
|
34
|
-
def audiences_from_site_users
|
|
32
|
+
def audiences_from_site_users(parsed_response)
|
|
35
33
|
site_users = []
|
|
36
|
-
site_users +=
|
|
37
|
-
site_users <<
|
|
34
|
+
site_users += parsed_response.fetch("grantedToIdentitiesV2", []).flat_map { it.fetch("siteUser", nil) }
|
|
35
|
+
site_users << parsed_response.dig("grantedToV2", "siteUser")
|
|
38
36
|
site_users.compact!
|
|
39
37
|
|
|
40
38
|
site_users.map { Audience.from_site_user(it) }
|
|
41
39
|
end
|
|
42
40
|
|
|
43
|
-
def audiences_from_anonymous_links
|
|
44
|
-
link =
|
|
41
|
+
def audiences_from_anonymous_links(parsed_response)
|
|
42
|
+
link = parsed_response.fetch("link", nil)
|
|
45
43
|
return [] if link.nil? || (link.respond_to?(:empty?) && link.empty?)
|
|
46
44
|
|
|
47
45
|
link_scope = link.fetch("scope", nil)
|