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
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
|
@@ -16,8 +16,7 @@ gem "microslop_one_drive"
|
|
|
16
16
|
|
|
17
17
|
## Usage
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
a batched manner:
|
|
19
|
+
Quickstart: current user, drives, drive items, shared-with-me, delta (changes), and permissions (single or batched).
|
|
21
20
|
|
|
22
21
|
### Creating a client
|
|
23
22
|
|
|
@@ -25,6 +24,17 @@ a batched manner:
|
|
|
25
24
|
access_token = "..." # Get an access token via OAuth 2.0
|
|
26
25
|
|
|
27
26
|
client = MicroslopOneDrive::Client.new(access_token)
|
|
27
|
+
|
|
28
|
+
# Optional: pass a logger to log all API requests and responses (e.g. Rails.logger)
|
|
29
|
+
client = MicroslopOneDrive::Client.new(access_token, logger: Rails.logger)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Get current user
|
|
33
|
+
|
|
34
|
+
```rb
|
|
35
|
+
user = client.me
|
|
36
|
+
user.display_name # => "Jane Doe"
|
|
37
|
+
user.email_address # => "jane@example.com"
|
|
28
38
|
```
|
|
29
39
|
|
|
30
40
|
### Listing Drives
|
|
@@ -34,7 +44,7 @@ Note: Microsoft will return all Drives a user has access to. Some of these seem
|
|
|
34
44
|
`drive_exists?()` method to check if it's a real drive you can interact with.
|
|
35
45
|
|
|
36
46
|
```rb
|
|
37
|
-
drive_list = client.
|
|
47
|
+
drive_list = client.all_drives
|
|
38
48
|
drive_list.drives.size # => 2
|
|
39
49
|
|
|
40
50
|
drive = drive_list.drives[1]
|
|
@@ -44,6 +54,29 @@ drive.id # => "0f0**********42"
|
|
|
44
54
|
client.drive_exists?(drive.id) # => true (it's a real Drive)
|
|
45
55
|
```
|
|
46
56
|
|
|
57
|
+
### Get a single drive
|
|
58
|
+
|
|
59
|
+
```rb
|
|
60
|
+
# Default (current user's) drive
|
|
61
|
+
drive = client.drive
|
|
62
|
+
|
|
63
|
+
# Or a specific drive by ID
|
|
64
|
+
drive = client.drive(drive_id: "0f0**********42")
|
|
65
|
+
drive.name # => "OneDrive"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Get a single drive item
|
|
69
|
+
|
|
70
|
+
```rb
|
|
71
|
+
item = client.drive_item(item_id: "01ABC123...", drive_id: drive.id)
|
|
72
|
+
item.name # => "My Document.docx"
|
|
73
|
+
item.file? # => true
|
|
74
|
+
item.folder? # => false
|
|
75
|
+
|
|
76
|
+
# Check if an item exists without raising
|
|
77
|
+
client.drive_item_exists?(item_id: "01ABC123...", drive_id: drive.id) # => true
|
|
78
|
+
```
|
|
79
|
+
|
|
47
80
|
### Listing Drive Items (Folders and Files)
|
|
48
81
|
|
|
49
82
|
```rb
|
|
@@ -59,6 +92,34 @@ delta_token = page2.delta_token # Save this somewhere and use as "token" in the
|
|
|
59
92
|
# only get new changes, and don't list the whole drive from the beginning again.
|
|
60
93
|
```
|
|
61
94
|
|
|
95
|
+
### Shared with me
|
|
96
|
+
|
|
97
|
+
Get drive items (files and folders) that others have shared with the current user.
|
|
98
|
+
|
|
99
|
+
```rb
|
|
100
|
+
shared_list = client.shared_with_me
|
|
101
|
+
shared_list.shared_with_me_items.size # => 5
|
|
102
|
+
|
|
103
|
+
item = shared_list.shared_with_me_items.first
|
|
104
|
+
item.name # => "Spreadsheet One.xlsx"
|
|
105
|
+
item.id # => "64E5DD3210FD6004!s1d8ad87a1d6e4d4e..."
|
|
106
|
+
item.web_url # => "https://onedrive.live.com?cid=..."
|
|
107
|
+
item.size # => 6183
|
|
108
|
+
item.created_at # => 2026-02-17 14:27:26 UTC
|
|
109
|
+
item.updated_at # => 2026-02-17 14:27:27 UTC
|
|
110
|
+
|
|
111
|
+
# Who shared it
|
|
112
|
+
item.created_by.display_name # => "Someone Else"
|
|
113
|
+
item.created_by.email_address # => "outlook_64E5DD3210FD6004@outlook.com"
|
|
114
|
+
item.last_modified_by.display_name # => "Someone Else"
|
|
115
|
+
|
|
116
|
+
# The underlying drive item (with file?, folder?, mime_type, shared?, etc.)
|
|
117
|
+
item.remote_item.file? # => true
|
|
118
|
+
item.remote_item.shared? # => true
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Use `shared_list.next_page?` and `shared_list.next_token` to paginate when there are many items.
|
|
122
|
+
|
|
62
123
|
### Get Permissions for a single Drive Item
|
|
63
124
|
|
|
64
125
|
```rb
|
|
@@ -86,10 +147,15 @@ Microsoft Graph API [batch](https://learn.microsoft.com/en-us/graph/json-batchin
|
|
|
86
147
|
drive_item_list = client.delta(drive_id: drive.id)
|
|
87
148
|
shared_items = drive_item_list.items.select(&:shared?)
|
|
88
149
|
|
|
89
|
-
|
|
150
|
+
permissions = client.batch_permissions(item_ids: shared_items.map(&:id))
|
|
151
|
+
# Returns a flat array of MicroslopOneDrive::Permission (batches of 20 are made under the hood).
|
|
152
|
+
permissions.each { |p| puts "#{p.audience.display_name}: #{p.role}" }
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Checking if the user's accounts supports SharePoint Sites
|
|
90
156
|
|
|
91
|
-
|
|
92
|
-
#
|
|
157
|
+
```rb
|
|
158
|
+
client.supports_sites? # => true or false
|
|
93
159
|
```
|
|
94
160
|
|
|
95
161
|
## Contributing
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
module Batch
|
|
3
|
+
class Response
|
|
4
|
+
attr_reader :id, :status, :headers, :body
|
|
5
|
+
|
|
6
|
+
def initialize(response_hash)
|
|
7
|
+
@id = response_hash.fetch("id")
|
|
8
|
+
@status = response_hash.fetch("status")
|
|
9
|
+
@headers = response_hash.fetch("headers")
|
|
10
|
+
@body = response_hash.fetch("body")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def success?
|
|
14
|
+
@status.between?(200, 299)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -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,163 +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::User.new(response.parsed_response)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
# Gets all Drives the current user has access to.
|
|
32
|
-
#
|
|
33
|
-
# NOTE: This will include some internal Microsoft drives that aren't real drives, such as AI, Face scans, and other
|
|
34
|
-
# shitty things.
|
|
35
|
-
#
|
|
36
|
-
# @return [MicroslopOneDrive::DriveList]
|
|
37
|
-
def drives
|
|
38
|
-
response = get(path: "me/drives", query: {})
|
|
39
|
-
handle_error(response) unless response.success?
|
|
40
|
-
MicroslopOneDrive::DriveList.new(response.parsed_response)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# Gets a specific Drive by its ID.
|
|
44
|
-
#
|
|
45
|
-
# @param drive_id [String] The ID of the Drive to get.
|
|
46
|
-
#
|
|
47
|
-
# @return [MicroslopOneDrive::Drive]
|
|
48
|
-
def drive(drive_id:)
|
|
49
|
-
response = get(path: "me/drives/#{drive_id}", query: {})
|
|
50
|
-
handle_error(response) unless response.success?
|
|
51
|
-
MicroslopOneDrive::Drive.new(response.parsed_response)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
# Asks if a Drive exists by its ID.
|
|
55
|
-
#
|
|
56
|
-
# @param drive_id [String] The ID of the Drive to check.
|
|
57
|
-
#
|
|
58
|
-
# @return [Boolean]
|
|
59
|
-
def drive_exists?(drive_id:)
|
|
60
|
-
response = get(path: "me/drives/#{drive_id}", query: {})
|
|
61
|
-
response.success?
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
# Gets a specific DriveItem (folder or file) by its ID.
|
|
65
|
-
#
|
|
66
|
-
# @param item_id [String] The ID of the Drive Item to get.
|
|
67
|
-
#
|
|
68
|
-
# @return [MicroslopOneDrive::DriveItem]
|
|
69
|
-
def drive_item(item_id:)
|
|
70
|
-
response = get(path: "me/drive/items/#{item_id}", query: {})
|
|
71
|
-
handle_error(response) unless response.success?
|
|
72
|
-
MicroslopOneDrive::DriveItem.new(response.parsed_response)
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
# Asks if a DriveItem (folder or file) exists by its ID.
|
|
76
|
-
#
|
|
77
|
-
# @param item_id [String] The ID of the Drive Item to check.
|
|
78
|
-
#
|
|
79
|
-
# @return [Boolean]
|
|
80
|
-
def item_exists?(item_id:)
|
|
81
|
-
response = get(path: "me/drive/items/#{item_id}", query: {})
|
|
82
|
-
|
|
83
|
-
return false if response.code == 404
|
|
84
|
-
return true if response.success?
|
|
85
|
-
|
|
86
|
-
handle_error(response)
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
# Gets a delta of changes to a Drive.
|
|
90
|
-
#
|
|
91
|
-
# @param drive_id [String] The ID of the Drive to get the delta of.
|
|
92
|
-
# @param token [String] The token to use for the delta. If not provided, the initial delta will be returned.
|
|
93
|
-
#
|
|
94
|
-
# @return [MicroslopOneDrive::DriveItemList]
|
|
95
|
-
def delta(drive_id:, token: nil)
|
|
96
|
-
response = get(path: "me/drives/#{drive_id}/root/delta", query: {token: token})
|
|
97
|
-
handle_error(response) unless response.success?
|
|
98
|
-
MicroslopOneDrive::DriveItemList.new(response.parsed_response)
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
# Gets the permissions for a DriveItem (folder or file).
|
|
102
|
-
#
|
|
103
|
-
# @param item_id [String] The ID of the Drive Item to get the permissions of.
|
|
104
|
-
#
|
|
105
|
-
# @return [MicroslopOneDrive::PermissionList]
|
|
106
|
-
def permissions(item_id:)
|
|
107
|
-
response = get(path: "me/drive/items/#{item_id}/permissions", query: {})
|
|
108
|
-
|
|
109
|
-
if response.code == 404
|
|
110
|
-
return MicroslopOneDrive::PermissionList.new(drive_item_id: item_id, parsed_response: { "value" => [] })
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
handle_error(response) unless response.success?
|
|
114
|
-
|
|
115
|
-
MicroslopOneDrive::PermissionList.new(drive_item_id: item_id, parsed_response: response.parsed_response)
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
# Gets the permissions for multiple Drive Items.
|
|
119
|
-
#
|
|
120
|
-
# Uses the batch Microsoft Graph API to make multiple API calls in batches of 20 (the max Microsoft allows on their
|
|
121
|
-
# batch endpoint).
|
|
122
|
-
#
|
|
123
|
-
# See: https://learn.microsoft.com/en-us/graph/json-batching
|
|
124
|
-
#
|
|
125
|
-
# @param item_ids [Array<String>] The IDs of the Drive Items to get the permissions of.
|
|
126
|
-
#
|
|
127
|
-
# @return [Array<MicroslopOneDrive::Permission>]
|
|
128
|
-
def batch_permissions(item_ids:)
|
|
129
|
-
requests = item_ids.map { |item_id| { id: item_id, method: "GET", url: "/me/drive/items/#{item_id}/permissions" } }
|
|
130
|
-
batch_response = batch(requests: requests)
|
|
131
|
-
successful_responses = batch_response.responses.select(&:success?)
|
|
132
|
-
|
|
133
|
-
permission_lists = successful_responses.map do |response|
|
|
134
|
-
MicroslopOneDrive::PermissionList.new(drive_item_id: response.id, parsed_response: response.body)
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
permission_lists.flat_map(&:permissions)
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
# Makes a batch request to the Microsoft Graph API.
|
|
141
|
-
#
|
|
142
|
-
# @param requests [Array<Hash>] The requests to make. Each request should be a hash with the following keys:
|
|
143
|
-
# - id: The ID of the request.
|
|
144
|
-
# - method: The HTTP method to use for the request.
|
|
145
|
-
# - url: The URL to make the request to.
|
|
146
|
-
#
|
|
147
|
-
# Note: Microsoft allows a maximum of 20 requests per batch. If you pass more than 20 requests, the client will
|
|
148
|
-
# make multiple batch requests to Microsoft. This might make this a slow method.
|
|
149
|
-
#
|
|
150
|
-
# @return [MicroslopOneDrive::BatchResponse]
|
|
151
|
-
def batch(requests:)
|
|
152
|
-
batch_response = MicroslopOneDrive::BatchResponse.new
|
|
153
|
-
|
|
154
|
-
# No requests, so simply return an empty batch response:
|
|
155
|
-
return batch_response if requests.empty?
|
|
156
|
-
|
|
157
|
-
batches = requests.each_slice(BATCH_REQUEST_LIMIT).to_a
|
|
158
|
-
batches.each do |batch|
|
|
159
|
-
response = post(path: "$batch", body: { requests: batch }.to_json)
|
|
160
|
-
handle_error(response) unless response.success?
|
|
161
|
-
new_responses = response.parsed_response.fetch("responses", [])
|
|
162
|
-
new_responses.each do |new_response_hash|
|
|
163
|
-
batch_response.add_response(MicroslopOneDrive::Response.new(new_response_hash))
|
|
164
|
-
end
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
batch_response
|
|
168
|
-
end
|
|
169
|
-
|
|
170
34
|
private
|
|
171
35
|
|
|
172
36
|
def get(path:, query: {})
|
|
173
37
|
url = "#{BASE_URL}/#{path}"
|
|
174
|
-
|
|
175
38
|
log_request("GET", url, query: query)
|
|
176
39
|
|
|
177
40
|
response = HTTParty.get(url, headers: @headers, query: query)
|
|
178
|
-
|
|
179
41
|
log_response(response, "GET", url)
|
|
180
42
|
|
|
181
43
|
response
|
|
@@ -183,11 +45,9 @@ module MicroslopOneDrive
|
|
|
183
45
|
|
|
184
46
|
def post(path:, body:)
|
|
185
47
|
url = "#{BASE_URL}/#{path}"
|
|
186
|
-
|
|
187
48
|
log_request("POST", url, body: body)
|
|
188
49
|
|
|
189
50
|
response = HTTParty.post(url, headers: @headers, body: body)
|
|
190
|
-
|
|
191
51
|
log_response(response, "POST", url)
|
|
192
52
|
|
|
193
53
|
response
|
|
@@ -200,7 +60,7 @@ module MicroslopOneDrive
|
|
|
200
60
|
@logger.info "==================== START MicroslopOneDrive #{method} #{url} ===================="
|
|
201
61
|
@logger.info "Request method: #{method}"
|
|
202
62
|
@logger.info "Request url: #{url}"
|
|
203
|
-
@logger.info "Request query: #{query.inspect}" if query
|
|
63
|
+
@logger.info "Request query: #{query.inspect}" if query&.any?
|
|
204
64
|
@logger.info "Request body: #{body.inspect}" if body
|
|
205
65
|
end
|
|
206
66
|
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require "microslop_one_drive/utils"
|
|
2
|
+
|
|
3
|
+
module MicroslopOneDrive
|
|
4
|
+
module Deserializers
|
|
5
|
+
class DriveDeserializer
|
|
6
|
+
# Creates a new Drive object from a hash.
|
|
7
|
+
#
|
|
8
|
+
# @param drive_hash [Hash] The hash to create the Drive object from.
|
|
9
|
+
# @return [MicroslopOneDrive::Drive] The created Drive object.
|
|
10
|
+
def self.create_from_hash(drive_hash)
|
|
11
|
+
drive_hash = Utils.deep_symbolize_keys(drive_hash)
|
|
12
|
+
|
|
13
|
+
created_by = build_created_by(drive_hash)
|
|
14
|
+
last_modified_by = build_last_modified_by(drive_hash)
|
|
15
|
+
owner = build_owner(drive_hash)
|
|
16
|
+
|
|
17
|
+
Drive.new(
|
|
18
|
+
id: drive_hash.fetch(:id, nil),
|
|
19
|
+
name: drive_hash.fetch(:name, nil),
|
|
20
|
+
description: drive_hash.fetch(:description, nil),
|
|
21
|
+
web_url: drive_hash.fetch(:webUrl, nil),
|
|
22
|
+
drive_type: drive_hash.fetch(:driveType, nil),
|
|
23
|
+
created_date_time: Utils.safe_parse_time(drive_hash.fetch(:createdDateTime, nil)),
|
|
24
|
+
last_modified_date_time: Utils.safe_parse_time(drive_hash.fetch(:lastModifiedDateTime, nil)),
|
|
25
|
+
created_by: created_by,
|
|
26
|
+
last_modified_by: last_modified_by,
|
|
27
|
+
owner: owner,
|
|
28
|
+
quota: QuotaDeserializer.create_from_hash(drive_hash.fetch(:quota, {}))
|
|
29
|
+
)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.build_created_by(drive_hash)
|
|
33
|
+
created_by_hash = drive_hash.dig(:createdBy, :user)
|
|
34
|
+
|
|
35
|
+
return unless created_by_hash
|
|
36
|
+
|
|
37
|
+
UserDeserializer.create_from_hash(created_by_hash)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self.build_last_modified_by(drive_hash)
|
|
41
|
+
last_modified_by_hash = drive_hash.dig(:lastModifiedBy, :user)
|
|
42
|
+
|
|
43
|
+
return unless last_modified_by_hash
|
|
44
|
+
|
|
45
|
+
UserDeserializer.create_from_hash(last_modified_by_hash)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def self.build_owner(drive_hash)
|
|
49
|
+
owner_hash = drive_hash.dig(:owner, :user)
|
|
50
|
+
|
|
51
|
+
return unless owner_hash
|
|
52
|
+
|
|
53
|
+
UserDeserializer.create_from_hash(owner_hash)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
require "microslop_one_drive/utils"
|
|
2
|
+
|
|
3
|
+
module MicroslopOneDrive
|
|
4
|
+
module Deserializers
|
|
5
|
+
class DriveItemDeserializer
|
|
6
|
+
# Creates a new DriveItem object from a hash.
|
|
7
|
+
#
|
|
8
|
+
# @param drive_item_hash [Hash] The hash to create the DriveItem object from.
|
|
9
|
+
# @return [MicroslopOneDrive::DriveItem] The created DriveItem object.
|
|
10
|
+
def self.create_from_hash(drive_item_hash)
|
|
11
|
+
drive_item_hash = Utils.deep_symbolize_keys(drive_item_hash)
|
|
12
|
+
|
|
13
|
+
parameters = build_parameters(drive_item_hash)
|
|
14
|
+
|
|
15
|
+
root = drive_item_hash.key?(:root) && parameters[:file_or_folder] == :folder
|
|
16
|
+
|
|
17
|
+
if root
|
|
18
|
+
RootFolder.new(**parameters)
|
|
19
|
+
elsif parameters[:file_or_folder] == :file
|
|
20
|
+
File.new(**parameters)
|
|
21
|
+
elsif parameters[:file_or_folder] == :folder
|
|
22
|
+
Folder.new(**parameters)
|
|
23
|
+
else
|
|
24
|
+
DriveItem.new(**parameters)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.build_parameters(drive_item_hash)
|
|
29
|
+
file_or_folder = drive_item_hash.key?(:file) ? :file : :folder
|
|
30
|
+
mime_type = build_mime_type(file_or_folder, drive_item_hash)
|
|
31
|
+
parent_reference = build_parent_reference(drive_item_hash)
|
|
32
|
+
|
|
33
|
+
{
|
|
34
|
+
id: drive_item_hash.fetch(:id, nil),
|
|
35
|
+
name: drive_item_hash.fetch(:name, nil),
|
|
36
|
+
download_url: drive_item_hash.fetch(:"@microsoft.graph.downloadUrl", nil),
|
|
37
|
+
web_url: drive_item_hash.fetch(:webUrl, nil),
|
|
38
|
+
size: drive_item_hash.fetch(:size, nil),
|
|
39
|
+
created_date_time: Utils.safe_parse_time(drive_item_hash.fetch(:createdDateTime, nil)),
|
|
40
|
+
last_modified_date_time: Utils.safe_parse_time(drive_item_hash.fetch(:lastModifiedDateTime, nil)),
|
|
41
|
+
e_tag: drive_item_hash.fetch(:eTag, nil),
|
|
42
|
+
c_tag: drive_item_hash.fetch(:cTag, nil),
|
|
43
|
+
file_or_folder: file_or_folder,
|
|
44
|
+
mime_type: mime_type,
|
|
45
|
+
is_deleted: drive_item_hash.dig(:deleted, :state) == "deleted",
|
|
46
|
+
is_shared: drive_item_hash.key?(:shared),
|
|
47
|
+
parent_reference: parent_reference
|
|
48
|
+
}
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def self.build_mime_type(file_or_folder, drive_item_hash)
|
|
52
|
+
if file_or_folder == :file
|
|
53
|
+
drive_item_hash.dig(:file, :mimeType)
|
|
54
|
+
else
|
|
55
|
+
MicroslopOneDrive::DriveItem::DIRECTORY_MIME_TYPE
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def self.build_parent_reference(drive_item_hash)
|
|
60
|
+
parent_reference_hash = drive_item_hash.fetch(:parentReference, nil)
|
|
61
|
+
return unless parent_reference_hash
|
|
62
|
+
|
|
63
|
+
ParentReferenceDeserializer.create_from_hash(parent_reference_hash)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require "microslop_one_drive/utils"
|
|
2
|
+
|
|
3
|
+
module MicroslopOneDrive
|
|
4
|
+
module Deserializers
|
|
5
|
+
class ParentReferenceDeserializer
|
|
6
|
+
def self.create_from_hash(parent_reference_hash)
|
|
7
|
+
parent_reference_hash = Utils.deep_symbolize_keys(parent_reference_hash)
|
|
8
|
+
|
|
9
|
+
ParentReference.new(
|
|
10
|
+
drive_type: parent_reference_hash.fetch(:driveType, nil),
|
|
11
|
+
drive_id: parent_reference_hash.fetch(:driveId, nil),
|
|
12
|
+
id: parent_reference_hash.fetch(:id, nil),
|
|
13
|
+
name: parent_reference_hash.fetch(:name, nil),
|
|
14
|
+
path: parent_reference_hash.fetch(:path, nil),
|
|
15
|
+
site_id: parent_reference_hash.fetch(:siteId, nil)
|
|
16
|
+
)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require "microslop_one_drive/utils"
|
|
2
|
+
|
|
3
|
+
module MicroslopOneDrive
|
|
4
|
+
module Deserializers
|
|
5
|
+
class QuotaDeserializer
|
|
6
|
+
# Creates a new Quota object from a hash.
|
|
7
|
+
#
|
|
8
|
+
# @param quota_hash [Hash] The hash to create the Quota object from.
|
|
9
|
+
# @return [MicroslopOneDrive::Quota] The created Quota object.
|
|
10
|
+
def self.create_from_hash(quota_hash)
|
|
11
|
+
quota_hash = Utils.deep_symbolize_keys(quota_hash)
|
|
12
|
+
|
|
13
|
+
Quota.new(
|
|
14
|
+
deleted: quota_hash.fetch(:deleted, nil),
|
|
15
|
+
remaining: quota_hash.fetch(:remaining, nil),
|
|
16
|
+
state: quota_hash.fetch(:state, nil),
|
|
17
|
+
total: quota_hash.fetch(:total, nil),
|
|
18
|
+
used: quota_hash.fetch(:used, nil),
|
|
19
|
+
upgrade_available: quota_hash.dig(:storagePlanInformation, :upgradeAvailable)
|
|
20
|
+
)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require "microslop_one_drive/utils"
|
|
2
|
+
|
|
3
|
+
module MicroslopOneDrive
|
|
4
|
+
module Deserializers
|
|
5
|
+
class SharedWithMeItemDeserializer
|
|
6
|
+
def self.create_from_hash(shared_with_me_item_hash)
|
|
7
|
+
shared_with_me_item_hash = Utils.deep_symbolize_keys(shared_with_me_item_hash)
|
|
8
|
+
|
|
9
|
+
created_by = build_created_by(shared_with_me_item_hash)
|
|
10
|
+
last_modified_by = build_last_modified_by(shared_with_me_item_hash)
|
|
11
|
+
remote_item = build_remote_item(shared_with_me_item_hash)
|
|
12
|
+
|
|
13
|
+
SharedWithMeItem.new(
|
|
14
|
+
id: shared_with_me_item_hash.fetch(:id, nil),
|
|
15
|
+
name: shared_with_me_item_hash.fetch(:name, nil),
|
|
16
|
+
web_url: shared_with_me_item_hash.fetch(:webUrl, nil),
|
|
17
|
+
size: shared_with_me_item_hash.fetch(:size, nil),
|
|
18
|
+
last_modified_date_time: Utils.safe_parse_time(shared_with_me_item_hash.fetch(:lastModifiedDateTime, nil)),
|
|
19
|
+
created_date_time: Utils.safe_parse_time(shared_with_me_item_hash.fetch(:createdDateTime, nil)),
|
|
20
|
+
created_by: created_by,
|
|
21
|
+
last_modified_by: last_modified_by,
|
|
22
|
+
remote_item: remote_item
|
|
23
|
+
)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.build_created_by(shared_with_me_item_hash)
|
|
27
|
+
created_by_hash = shared_with_me_item_hash.dig(:createdBy, :user)
|
|
28
|
+
return unless created_by_hash
|
|
29
|
+
|
|
30
|
+
UserDeserializer.create_from_hash(created_by_hash)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.build_last_modified_by(shared_with_me_item_hash)
|
|
34
|
+
last_modified_by_hash = shared_with_me_item_hash.dig(:lastModifiedBy, :user)
|
|
35
|
+
return unless last_modified_by_hash
|
|
36
|
+
|
|
37
|
+
UserDeserializer.create_from_hash(last_modified_by_hash)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self.build_remote_item(shared_with_me_item_hash)
|
|
41
|
+
remote_item_hash = shared_with_me_item_hash.fetch(:remoteItem, {})
|
|
42
|
+
return unless remote_item_hash
|
|
43
|
+
|
|
44
|
+
DriveItemDeserializer.create_from_hash(remote_item_hash)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require "microslop_one_drive/utils"
|
|
2
|
+
|
|
3
|
+
module MicroslopOneDrive
|
|
4
|
+
module Deserializers
|
|
5
|
+
class UserDeserializer
|
|
6
|
+
# Creates a new User object from a hash.
|
|
7
|
+
#
|
|
8
|
+
# @param user_hash [Hash] The hash to create the User object from.
|
|
9
|
+
# @return [MicroslopOneDrive::User] The created User object.
|
|
10
|
+
def self.create_from_hash(user_hash)
|
|
11
|
+
user_hash = Utils.deep_symbolize_keys(user_hash)
|
|
12
|
+
|
|
13
|
+
User.new(
|
|
14
|
+
id: user_hash.fetch(:id, nil),
|
|
15
|
+
principal_name: user_hash.fetch(:userPrincipalName, nil),
|
|
16
|
+
display_name: user_hash.fetch(:displayName, nil),
|
|
17
|
+
surname: user_hash.fetch(:surname, nil),
|
|
18
|
+
given_name: user_hash.fetch(:givenName, nil),
|
|
19
|
+
preferred_language: user_hash.fetch(:preferredLanguage, nil),
|
|
20
|
+
mail: user_hash.fetch(:mail, nil) || user_hash.fetch(:email, nil),
|
|
21
|
+
mobile_phone: user_hash.fetch(:mobilePhone, nil),
|
|
22
|
+
job_title: user_hash.fetch(:jobTitle, nil),
|
|
23
|
+
office_location: user_hash.fetch(:officeLocation, nil),
|
|
24
|
+
business_phones: user_hash.fetch(:businessPhones, [])
|
|
25
|
+
)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -1,18 +1,48 @@
|
|
|
1
1
|
module MicroslopOneDrive
|
|
2
2
|
class Drive
|
|
3
|
-
attr_reader :id, :name, :description, :
|
|
3
|
+
attr_reader :id, :name, :description, :web_url, :drive_type, :created_date_time, :last_modified_date_time,
|
|
4
|
+
:created_by, :last_modified_by, :owner, :quota
|
|
4
5
|
|
|
5
|
-
def initialize(
|
|
6
|
-
|
|
6
|
+
def initialize(
|
|
7
|
+
id:,
|
|
8
|
+
name:,
|
|
9
|
+
description:,
|
|
10
|
+
web_url:,
|
|
11
|
+
drive_type:,
|
|
12
|
+
created_date_time:,
|
|
13
|
+
last_modified_date_time:,
|
|
14
|
+
created_by:,
|
|
15
|
+
last_modified_by:,
|
|
16
|
+
owner:,
|
|
17
|
+
quota:
|
|
18
|
+
)
|
|
19
|
+
@id = id
|
|
20
|
+
@name = name
|
|
21
|
+
@description = description
|
|
22
|
+
@web_url = web_url
|
|
23
|
+
@drive_type = drive_type
|
|
24
|
+
@created_date_time = created_date_time
|
|
25
|
+
@last_modified_date_time = last_modified_date_time
|
|
26
|
+
@created_by = created_by
|
|
27
|
+
@last_modified_by = last_modified_by
|
|
28
|
+
@owner = owner
|
|
29
|
+
@quota = quota
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def created_at
|
|
33
|
+
@created_date_time
|
|
34
|
+
end
|
|
7
35
|
|
|
8
|
-
|
|
9
|
-
@
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
36
|
+
def updated_at
|
|
37
|
+
@last_modified_date_time
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def url
|
|
41
|
+
@web_url
|
|
42
|
+
end
|
|
13
43
|
|
|
14
|
-
|
|
15
|
-
@
|
|
44
|
+
def updated_by
|
|
45
|
+
@last_modified_by
|
|
16
46
|
end
|
|
17
47
|
end
|
|
18
48
|
end
|