microslop_one_drive 3.0.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 +6 -0
- data/lib/microslop_one_drive/client.rb +13 -209
- 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/version.rb +1 -1
- data/lib/microslop_one_drive.rb +14 -0
- metadata +13 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9db184b4df0a4b6a58972d944c9c9abea1e898d81be33f180fc041fbd79c2a99
|
|
4
|
+
data.tar.gz: 21d761f38fb51a2985f49e082dd592f1f3e9361d39a38749ba44715360d9899d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fa9435c4a163c94012c88461c9330048ae08870a4cdf9fc0d4f8a31895aeac85ae3948fa5b420e4ec06bd00f2b202bdac25c968ad58dc36a1d905b0aff60ac55
|
|
7
|
+
data.tar.gz: ebd2a33ffbf3880edc209a176371c15963df82642f6ed69167b32cf0867eadf5fddf2b06cab59b936c509a1df82cded8b2a6728b4e10513d7680f1835601c17b
|
data/README.md
CHANGED
|
@@ -152,6 +152,12 @@ permissions = client.batch_permissions(item_ids: shared_items.map(&:id))
|
|
|
152
152
|
permissions.each { |p| puts "#{p.audience.display_name}: #{p.role}" }
|
|
153
153
|
```
|
|
154
154
|
|
|
155
|
+
### Checking if the user's accounts supports SharePoint Sites
|
|
156
|
+
|
|
157
|
+
```rb
|
|
158
|
+
client.supports_sites? # => true or false
|
|
159
|
+
```
|
|
160
|
+
|
|
155
161
|
## Contributing
|
|
156
162
|
|
|
157
163
|
### Setup
|
|
@@ -3,7 +3,19 @@ require "json"
|
|
|
3
3
|
module MicroslopOneDrive
|
|
4
4
|
class Client
|
|
5
5
|
BASE_URL = "https://graph.microsoft.com/v1.0".freeze
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
include Endpoints::Me
|
|
8
|
+
include Endpoints::Drive
|
|
9
|
+
include Endpoints::AllDrives
|
|
10
|
+
include Endpoints::DriveExists
|
|
11
|
+
include Endpoints::DriveItem
|
|
12
|
+
include Endpoints::DriveItemExists
|
|
13
|
+
include Endpoints::Delta
|
|
14
|
+
include Endpoints::SharedWithMe
|
|
15
|
+
include Endpoints::Permissions
|
|
16
|
+
include Endpoints::Batch
|
|
17
|
+
include Endpoints::BatchPermissions
|
|
18
|
+
include Endpoints::SupportsSites
|
|
7
19
|
|
|
8
20
|
# @param access_token [String] OAuth access token for Microsoft Graph.
|
|
9
21
|
# @param logger [Object, nil] Optional logger (e.g. Rails.logger) that responds to +#info+, +#debug+, +#warn+, +#error+.
|
|
@@ -19,219 +31,13 @@ module MicroslopOneDrive
|
|
|
19
31
|
}
|
|
20
32
|
end
|
|
21
33
|
|
|
22
|
-
# Gets the current user
|
|
23
|
-
#
|
|
24
|
-
# @return [MicroslopOneDrive::User]
|
|
25
|
-
def me
|
|
26
|
-
response = get(path: "me", query: {})
|
|
27
|
-
handle_error(response) unless response.success?
|
|
28
|
-
MicroslopOneDrive::Deserializers::UserDeserializer.create_from_hash(response.parsed_response)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
# Gets a Drive.
|
|
32
|
-
#
|
|
33
|
-
# If no drive_id is provided, the current User's default Drive will be returned, else, the specific Drive identified
|
|
34
|
-
# by the drive_id will be returned.
|
|
35
|
-
#
|
|
36
|
-
# From the docs:
|
|
37
|
-
#
|
|
38
|
-
# > Most users will only have a single Drive resource.
|
|
39
|
-
# > Groups and Sites may have multiple Drive resources available.
|
|
40
|
-
#
|
|
41
|
-
# @param drive_id [String, nil] The ID of the Drive to get. If not provided, the current User's default Drive will
|
|
42
|
-
# be returned.
|
|
43
|
-
#
|
|
44
|
-
# @return [MicroslopOneDrive::Drive]
|
|
45
|
-
def drive(drive_id: nil)
|
|
46
|
-
url = drive_id.nil? ? "me/drive" : "me/drives/#{drive_id}"
|
|
47
|
-
response = get(path: url, query: {})
|
|
48
|
-
|
|
49
|
-
handle_error(response) unless response.success?
|
|
50
|
-
MicroslopOneDrive::Deserializers::DriveDeserializer.create_from_hash(response.parsed_response)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
# Gets ALL Drives the current user has access to.
|
|
54
|
-
#
|
|
55
|
-
# NOTE: This will include some internal Microsoft drives that aren't real drives, such as AI, Face scans, and other
|
|
56
|
-
# shitty things.
|
|
57
|
-
#
|
|
58
|
-
# @return [MicroslopOneDrive::DriveList]
|
|
59
|
-
def all_drives
|
|
60
|
-
response = get(path: "me/drives", query: {})
|
|
61
|
-
handle_error(response) unless response.success?
|
|
62
|
-
MicroslopOneDrive::ListResponses::DriveList.new(response.parsed_response)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
# Asks if a Drive exists by its ID.
|
|
66
|
-
#
|
|
67
|
-
# @param drive_id [String] The ID of the Drive to check.
|
|
68
|
-
#
|
|
69
|
-
# @return [Boolean]
|
|
70
|
-
def drive_exists?(drive_id:)
|
|
71
|
-
response = get(path: "me/drives/#{drive_id}", query: {})
|
|
72
|
-
response.success?
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
# Gets a specific DriveItem (folder or file)
|
|
76
|
-
#
|
|
77
|
-
# @param drive_id [String, nil] The ID of the Drive to get the Drive Item from. If not provided, the current User's
|
|
78
|
-
# default Drive will be used.
|
|
79
|
-
# @param item_id [String] The ID of the Drive Item to get.
|
|
80
|
-
#
|
|
81
|
-
# @return [MicroslopOneDrive::DriveItem]
|
|
82
|
-
def drive_item(item_id:, drive_id: nil)
|
|
83
|
-
url = drive_id.nil? ? "me/drive/items/#{item_id}" : "me/drives/#{drive_id}/items/#{item_id}"
|
|
84
|
-
response = get(path: url, query: {})
|
|
85
|
-
|
|
86
|
-
handle_error(response) unless response.success?
|
|
87
|
-
MicroslopOneDrive::Deserializers::DriveItemDeserializer.create_from_hash(response.parsed_response)
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
# Asks if a DriveItem (folder or file) exists by its ID.
|
|
91
|
-
#
|
|
92
|
-
# @param drive_id [String, nil] The ID of the Drive to check the Drive Item in. If not provided, the current User's
|
|
93
|
-
# default Drive will be used.
|
|
94
|
-
# @param item_id [String] The ID of the Drive Item to check.
|
|
95
|
-
#
|
|
96
|
-
# @return [Boolean]
|
|
97
|
-
def drive_item_exists?(item_id:, drive_id: nil)
|
|
98
|
-
url = drive_id.nil? ? "me/drive/items/#{item_id}" : "me/drives/#{drive_id}/items/#{item_id}"
|
|
99
|
-
response = get(path: url, query: {})
|
|
100
|
-
|
|
101
|
-
return false if response.code == 404
|
|
102
|
-
return true if response.success?
|
|
103
|
-
|
|
104
|
-
handle_error(response)
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
# Gets a delta of changes in a Drive.
|
|
108
|
-
#
|
|
109
|
-
# @param drive_id [String, nil] The ID of the Drive to get the delta of. If not provided, the current User's default
|
|
110
|
-
# Drive will be used.
|
|
111
|
-
# @param token [String, nil] The token to use for the delta. If not provided, the initial delta will be returned.
|
|
112
|
-
#
|
|
113
|
-
# @return [MicroslopOneDrive::DriveItemList]
|
|
114
|
-
def delta(drive_id: nil, token: nil)
|
|
115
|
-
url = drive_id.nil? ? "me/drive/root/delta" : "me/drives/#{drive_id}/root/delta"
|
|
116
|
-
response = get(path: url, query: {token: token})
|
|
117
|
-
handle_error(response) unless response.success?
|
|
118
|
-
MicroslopOneDrive::ListResponses::DriveItemList.new(response.parsed_response)
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
# Gets the Drive Items shared with the current user.
|
|
122
|
-
#
|
|
123
|
-
# @return [MicroslopOneDrive::SharedWithMeList]
|
|
124
|
-
def shared_with_me
|
|
125
|
-
response = get(path: "me/drive/sharedWithMe")
|
|
126
|
-
handle_error(response) unless response.success?
|
|
127
|
-
MicroslopOneDrive::ListResponses::SharedWithMeList.new(response.parsed_response)
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
# Gets the permissions for a DriveItem (folder or file) in a Drive.
|
|
131
|
-
#
|
|
132
|
-
# @param drive_id [String, nil] The ID of the Drive to get the permissions of. If not provided, the current User's
|
|
133
|
-
# default Drive will be used.
|
|
134
|
-
# @param item_id [String] The ID of the Drive Item to get the permissions of.
|
|
135
|
-
#
|
|
136
|
-
# @return [MicroslopOneDrive::PermissionList]
|
|
137
|
-
def permissions(item_id:, drive_id: nil)
|
|
138
|
-
url = if drive_id.nil?
|
|
139
|
-
"me/drive/items/#{item_id}/permissions"
|
|
140
|
-
else
|
|
141
|
-
"me/drives/#{drive_id}/items/#{item_id}/permissions"
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
response = get(path: url, query: {})
|
|
145
|
-
|
|
146
|
-
if response.code == 404
|
|
147
|
-
return MicroslopOneDrive::ListResponses::PermissionList.new(
|
|
148
|
-
drive_item_id: item_id,
|
|
149
|
-
parsed_response: {"value" => []}
|
|
150
|
-
)
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
handle_error(response) unless response.success?
|
|
154
|
-
|
|
155
|
-
MicroslopOneDrive::ListResponses::PermissionList.new(
|
|
156
|
-
drive_item_id: item_id,
|
|
157
|
-
parsed_response: response.parsed_response
|
|
158
|
-
)
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
# Gets the permissions for multiple Drive Items.
|
|
162
|
-
#
|
|
163
|
-
# Uses the batch Microsoft Graph API to make multiple API calls in batches of 20 (the max Microsoft allows on their
|
|
164
|
-
# batch endpoint).
|
|
165
|
-
#
|
|
166
|
-
# See: https://learn.microsoft.com/en-us/graph/json-batching
|
|
167
|
-
#
|
|
168
|
-
# @param drive_id [String, nil] The ID of the Drive to get the permissions of. If not provided, the current User's
|
|
169
|
-
# default Drive will be used.
|
|
170
|
-
# @param item_ids [Array<String>] The IDs of the Drive Items to get the permissions of.
|
|
171
|
-
#
|
|
172
|
-
# @return [Array<MicroslopOneDrive::Permission>]
|
|
173
|
-
def batch_permissions(item_ids:, drive_id: nil)
|
|
174
|
-
requests = build_batch_permissions_requests(item_ids: item_ids, drive_id: drive_id)
|
|
175
|
-
batch_response = batch(requests: requests)
|
|
176
|
-
successful_responses = batch_response.responses.select(&:success?)
|
|
177
|
-
|
|
178
|
-
permission_lists = successful_responses.map do
|
|
179
|
-
MicroslopOneDrive::ListResponses::PermissionList.new(
|
|
180
|
-
drive_item_id: it.id,
|
|
181
|
-
parsed_response: it.body
|
|
182
|
-
)
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
permission_lists.flat_map(&:permissions)
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
# Makes a batch request to the Microsoft Graph API.
|
|
189
|
-
#
|
|
190
|
-
# @param requests [Array<Hash>] The requests to make. Each request should be a hash with the following keys:
|
|
191
|
-
# - id: The ID of the request.
|
|
192
|
-
# - method: The HTTP method to use for the request.
|
|
193
|
-
# - url: The URL to make the request to.
|
|
194
|
-
#
|
|
195
|
-
# Note: Microsoft allows a maximum of 20 requests per batch. If you pass more than 20 requests, the client will
|
|
196
|
-
# make multiple batch requests to Microsoft. This might make this a slow method.
|
|
197
|
-
#
|
|
198
|
-
# @return [MicroslopOneDrive::BatchResponse]
|
|
199
|
-
def batch(requests:)
|
|
200
|
-
batch_response = MicroslopOneDrive::Batch::BatchResponse.new
|
|
201
|
-
|
|
202
|
-
# No requests, so simply return an empty batch response:
|
|
203
|
-
return batch_response if requests.empty?
|
|
204
|
-
|
|
205
|
-
batches = requests.each_slice(BATCH_REQUEST_LIMIT).to_a
|
|
206
|
-
batches.each do
|
|
207
|
-
response = post(path: "$batch", body: {requests: it}.to_json)
|
|
208
|
-
handle_error(response) unless response.success?
|
|
209
|
-
new_responses = response.parsed_response.fetch("responses", [])
|
|
210
|
-
new_responses.each do
|
|
211
|
-
batch_response.add_response(MicroslopOneDrive::Batch::Response.new(it))
|
|
212
|
-
end
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
batch_response
|
|
216
|
-
end
|
|
217
|
-
|
|
218
34
|
private
|
|
219
35
|
|
|
220
|
-
def build_batch_permissions_requests(item_ids:, drive_id: nil)
|
|
221
|
-
if drive_id.nil?
|
|
222
|
-
item_ids.map { {id: it, method: "GET", url: "/me/drive/items/#{it}/permissions"} }
|
|
223
|
-
else
|
|
224
|
-
item_ids.map { {id: it, method: "GET", url: "/me/drives/#{drive_id}/items/#{it}/permissions"} }
|
|
225
|
-
end
|
|
226
|
-
end
|
|
227
|
-
|
|
228
36
|
def get(path:, query: {})
|
|
229
37
|
url = "#{BASE_URL}/#{path}"
|
|
230
|
-
|
|
231
38
|
log_request("GET", url, query: query)
|
|
232
39
|
|
|
233
40
|
response = HTTParty.get(url, headers: @headers, query: query)
|
|
234
|
-
|
|
235
41
|
log_response(response, "GET", url)
|
|
236
42
|
|
|
237
43
|
response
|
|
@@ -239,11 +45,9 @@ module MicroslopOneDrive
|
|
|
239
45
|
|
|
240
46
|
def post(path:, body:)
|
|
241
47
|
url = "#{BASE_URL}/#{path}"
|
|
242
|
-
|
|
243
48
|
log_request("POST", url, body: body)
|
|
244
49
|
|
|
245
50
|
response = HTTParty.post(url, headers: @headers, body: body)
|
|
246
|
-
|
|
247
51
|
log_response(response, "POST", url)
|
|
248
52
|
|
|
249
53
|
response
|
|
@@ -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
|
data/lib/microslop_one_drive.rb
CHANGED
|
@@ -39,6 +39,20 @@ require_relative "microslop_one_drive/audience"
|
|
|
39
39
|
require_relative "microslop_one_drive/quota"
|
|
40
40
|
require_relative "microslop_one_drive/shared_with_me_item"
|
|
41
41
|
|
|
42
|
+
# Endpoints
|
|
43
|
+
require_relative "microslop_one_drive/endpoints/me"
|
|
44
|
+
require_relative "microslop_one_drive/endpoints/drive"
|
|
45
|
+
require_relative "microslop_one_drive/endpoints/all_drives"
|
|
46
|
+
require_relative "microslop_one_drive/endpoints/drive_exists"
|
|
47
|
+
require_relative "microslop_one_drive/endpoints/drive_item"
|
|
48
|
+
require_relative "microslop_one_drive/endpoints/drive_item_exists"
|
|
49
|
+
require_relative "microslop_one_drive/endpoints/delta"
|
|
50
|
+
require_relative "microslop_one_drive/endpoints/shared_with_me"
|
|
51
|
+
require_relative "microslop_one_drive/endpoints/permissions"
|
|
52
|
+
require_relative "microslop_one_drive/endpoints/batch"
|
|
53
|
+
require_relative "microslop_one_drive/endpoints/batch_permissions"
|
|
54
|
+
require_relative "microslop_one_drive/endpoints/supports_sites"
|
|
55
|
+
|
|
42
56
|
# Client
|
|
43
57
|
require_relative "microslop_one_drive/errors/client_error"
|
|
44
58
|
require_relative "microslop_one_drive/client"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: microslop_one_drive
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bradley Marques
|
|
@@ -45,6 +45,18 @@ files:
|
|
|
45
45
|
- lib/microslop_one_drive/deserializers/user_deserializer.rb
|
|
46
46
|
- lib/microslop_one_drive/drive.rb
|
|
47
47
|
- lib/microslop_one_drive/drive_item.rb
|
|
48
|
+
- lib/microslop_one_drive/endpoints/all_drives.rb
|
|
49
|
+
- lib/microslop_one_drive/endpoints/batch.rb
|
|
50
|
+
- lib/microslop_one_drive/endpoints/batch_permissions.rb
|
|
51
|
+
- lib/microslop_one_drive/endpoints/delta.rb
|
|
52
|
+
- lib/microslop_one_drive/endpoints/drive.rb
|
|
53
|
+
- lib/microslop_one_drive/endpoints/drive_exists.rb
|
|
54
|
+
- lib/microslop_one_drive/endpoints/drive_item.rb
|
|
55
|
+
- lib/microslop_one_drive/endpoints/drive_item_exists.rb
|
|
56
|
+
- lib/microslop_one_drive/endpoints/me.rb
|
|
57
|
+
- lib/microslop_one_drive/endpoints/permissions.rb
|
|
58
|
+
- lib/microslop_one_drive/endpoints/shared_with_me.rb
|
|
59
|
+
- lib/microslop_one_drive/endpoints/supports_sites.rb
|
|
48
60
|
- lib/microslop_one_drive/errors/client_error.rb
|
|
49
61
|
- lib/microslop_one_drive/file.rb
|
|
50
62
|
- lib/microslop_one_drive/folder.rb
|