Module: Legion::Extensions::MicrosoftTeams::Runners::Files
- Extended by:
- Definitions
- Includes:
- Helpers::Lex, Helpers::Client
- Defined in:
- lib/legion/extensions/microsoft_teams/runners/files.rb
Class Method Summary
collapse
Instance Method Summary
collapse
#bot_connection, #graph_connection, #oauth_connection, #user_path
Class Method Details
.trigger_words ⇒ Object
13
14
15
|
# File 'lib/legion/extensions/microsoft_teams/runners/files.rb', line 13
def self.trigger_words
%w[file files drive onedrive sharepoint document documents]
end
|
Instance Method Details
#get_drive_item(item_id:, user_id: 'me') ⇒ Object
73
74
75
76
77
|
# File 'lib/legion/extensions/microsoft_teams/runners/files.rb', line 73
def get_drive_item(item_id:, user_id: 'me', **)
log.debug "get_drive_item(item_id: #{item_id}), user_id: #{user_id}"
response = graph_connection(**).get("#{user_path(user_id)}/drive/items/#{item_id}")
{ result: response.body }
end
|
#get_drive_item_content(item_id:, user_id: 'me') ⇒ Object
88
89
90
91
92
|
# File 'lib/legion/extensions/microsoft_teams/runners/files.rb', line 88
def get_drive_item_content(item_id:, user_id: 'me', **)
log.debug "get_drive_item_content(item_id: #{item_id}, user_id: #{user_id})"
response = graph_connection(**).get("#{user_path(user_id)}/drive/items/#{item_id}/content")
{ result: response.body }
end
|
#list_drive_items(user_id: 'me', top: 200, max_pages: 1, select: nil, filter: nil) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/legion/extensions/microsoft_teams/runners/files.rb', line 34
def list_drive_items(user_id: 'me', top: 200, max_pages: 1, select: nil, filter: nil, **)
log.debug "list_drive_items(user_id: #{user_id})"
params = { '$top' => top }
params['$select'] = select if select
params['$filter'] = filter if filter
conn = graph_connection(**)
response = conn.get("#{user_path(user_id)}/drive/root/children", params)
body = response.body
return { result: body } if max_pages <= 1
all_values = Array(body['value'] || body[:value])
next_link = body['@odata.nextLink'] || body[:'@odata.nextLink']
pages_fetched = 1
while next_link && pages_fetched < max_pages
response = conn.get(next_link)
page_body = response.body
items = page_body['value'] || page_body[:value]
all_values.concat(Array(items)) if items
next_link = page_body['@odata.nextLink'] || page_body[:'@odata.nextLink']
pages_fetched += 1
end
result = { '@odata.context' => body['@odata.context'] || body[:'@odata.context'],
'value' => all_values }
result['@odata.nextLink'] = next_link if next_link
{ result: result }
end
|
#list_team_drive_items(team_id:, top: 200, max_pages: 1, select: nil) ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/legion/extensions/microsoft_teams/runners/files.rb', line 110
def list_team_drive_items(team_id:, top: 200, max_pages: 1, select: nil, **)
log.debug "list_team_drive_items(team_id: #{team_id})"
params = { '$top' => top }
params['$select'] = select if select
conn = graph_connection(**)
response = conn.get("teams/#{team_id}/drive/root/children", params)
body = response.body
return { result: body } if max_pages <= 1
all_values = Array(body['value'] || body[:value])
next_link = body['@odata.nextLink'] || body[:'@odata.nextLink']
pages_fetched = 1
while next_link && pages_fetched < max_pages
response = conn.get(next_link)
page_body = response.body
items = page_body['value'] || page_body[:value]
all_values.concat(Array(items)) if items
next_link = page_body['@odata.nextLink'] || page_body[:'@odata.nextLink']
pages_fetched += 1
end
result = { '@odata.context' => body['@odata.context'] || body[:'@odata.context'],
'value' => all_values }
result['@odata.nextLink'] = next_link if next_link
{ result: result }
end
|