microslop_one_drive 3.0.0 → 4.0.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 +8 -0
- data/lib/microslop_one_drive/client.rb +12 -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/supports_sites.rb +27 -0
- data/lib/microslop_one_drive/version.rb +1 -1
- data/lib/microslop_one_drive.rb +13 -0
- metadata +12 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b67b506f45cdbaf68c26070ae5f63167d4a951a0d92718a0c8e752ba64ee519e
|
|
4
|
+
data.tar.gz: a4bf7735cf0e7b4758830fcaab56842d5f1fd8c36aef946fe29ae18c82d8e2e1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1868c6c9533d47d93226862a1015d20b9947238ed547e737319bb27294efabe568cc65adf4cd172fe718e0f05e541814d59f6fbd303d65c9d5c17a4cb01941d5
|
|
7
|
+
data.tar.gz: 0e3cdecf71b3230726887ef2b40c301fac68a5fc84018791338940b889f9808cf93e635f6e19617cb5e6ac301030c905e03eafb1f95646e89e7b03cdcea1a361
|
data/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# MicroslopOneDrive
|
|
2
2
|
|
|
3
|
+
[](https://badge.fury.io/rb/microslop_one_drive)
|
|
4
|
+
|
|
3
5
|
Microslop OneDrive API client.
|
|
4
6
|
|
|
5
7
|
See <https://learn.microsoft.com/en-us/onedrive/developer/rest-api/>
|
|
@@ -152,6 +154,12 @@ permissions = client.batch_permissions(item_ids: shared_items.map(&:id))
|
|
|
152
154
|
permissions.each { |p| puts "#{p.audience.display_name}: #{p.role}" }
|
|
153
155
|
```
|
|
154
156
|
|
|
157
|
+
### Checking if the user's accounts supports SharePoint Sites
|
|
158
|
+
|
|
159
|
+
```rb
|
|
160
|
+
client.supports_sites? # => true or false
|
|
161
|
+
```
|
|
162
|
+
|
|
155
163
|
## Contributing
|
|
156
164
|
|
|
157
165
|
### Setup
|
|
@@ -3,7 +3,18 @@ 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::Permissions
|
|
15
|
+
include Endpoints::Batch
|
|
16
|
+
include Endpoints::BatchPermissions
|
|
17
|
+
include Endpoints::SupportsSites
|
|
7
18
|
|
|
8
19
|
# @param access_token [String] OAuth access token for Microsoft Graph.
|
|
9
20
|
# @param logger [Object, nil] Optional logger (e.g. Rails.logger) that responds to +#info+, +#debug+, +#warn+, +#error+.
|
|
@@ -19,219 +30,13 @@ module MicroslopOneDrive
|
|
|
19
30
|
}
|
|
20
31
|
end
|
|
21
32
|
|
|
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
33
|
private
|
|
219
34
|
|
|
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
35
|
def get(path:, query: {})
|
|
229
36
|
url = "#{BASE_URL}/#{path}"
|
|
230
|
-
|
|
231
37
|
log_request("GET", url, query: query)
|
|
232
38
|
|
|
233
39
|
response = HTTParty.get(url, headers: @headers, query: query)
|
|
234
|
-
|
|
235
40
|
log_response(response, "GET", url)
|
|
236
41
|
|
|
237
42
|
response
|
|
@@ -239,11 +44,9 @@ module MicroslopOneDrive
|
|
|
239
44
|
|
|
240
45
|
def post(path:, body:)
|
|
241
46
|
url = "#{BASE_URL}/#{path}"
|
|
242
|
-
|
|
243
47
|
log_request("POST", url, body: body)
|
|
244
48
|
|
|
245
49
|
response = HTTParty.post(url, headers: @headers, body: body)
|
|
246
|
-
|
|
247
50
|
log_response(response, "POST", url)
|
|
248
51
|
|
|
249
52
|
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,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,19 @@ 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/permissions"
|
|
51
|
+
require_relative "microslop_one_drive/endpoints/batch"
|
|
52
|
+
require_relative "microslop_one_drive/endpoints/batch_permissions"
|
|
53
|
+
require_relative "microslop_one_drive/endpoints/supports_sites"
|
|
54
|
+
|
|
42
55
|
# Client
|
|
43
56
|
require_relative "microslop_one_drive/errors/client_error"
|
|
44
57
|
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:
|
|
4
|
+
version: 4.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bradley Marques
|
|
@@ -45,6 +45,17 @@ 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/supports_sites.rb
|
|
48
59
|
- lib/microslop_one_drive/errors/client_error.rb
|
|
49
60
|
- lib/microslop_one_drive/file.rb
|
|
50
61
|
- lib/microslop_one_drive/folder.rb
|