Class: OSA::MSGraphClient
Instance Method Summary
collapse
Methods inherited from HttpClient
#delete, #get, #patch, #post
Constructor Details
10
11
12
13
14
15
16
17
18
|
# File 'lib/osa/clients/ms_graph_client.rb', line 10
def initialize(token)
connection = Faraday.new(
url: 'https://graph.microsoft.com',
headers: {
'authorization' => "Bearer #{token}"
}
)
super connection
end
|
Instance Method Details
#add_email_attachment(mail_id, content) ⇒ Object
61
62
63
64
65
66
67
68
|
# File 'lib/osa/clients/ms_graph_client.rb', line 61
def add_email_attachment(mail_id, content)
body = {
"@odata.type": '#microsoft.graph.fileAttachment',
"contentBytes": Base64.encode64(content),
"name": 'email.eml'
}
post("/v1.0/me/messages/#{mail_id}/attachments", body.to_json, 'content-type': 'application/json')
end
|
#create_forward_message(mail_id) ⇒ Object
57
58
59
|
# File 'lib/osa/clients/ms_graph_client.rb', line 57
def create_forward_message(mail_id)
post("/v1.0/me/messages/#{mail_id}/createForward")
end
|
#delete_mail(mail_id) ⇒ Object
70
71
72
|
# File 'lib/osa/clients/ms_graph_client.rb', line 70
def delete_mail(mail_id)
delete("/v1.0/me/messages/#{mail_id}")
end
|
#folders ⇒ Object
28
29
30
|
# File 'lib/osa/clients/ms_graph_client.rb', line 28
def folders
Paginated.new(get('/v1.0/me/mailFolders'), self)
end
|
#forward_mail_as_attachment(mail_id, to) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/osa/clients/ms_graph_client.rb', line 40
def forward_mail_as_attachment(mail_id, to)
raw_mail = self.raw_mail(mail_id)
forward_message = create_forward_message(mail_id)
add_email_attachment(forward_message['id'], raw_mail)
update = {
toRecipients: [
{
emailAddress: {
address: to
}
}
]
}
update_message(forward_message['id'], update)
send_message(forward_message['id'])
end
|
#mails(folder_id) ⇒ Object
32
33
34
|
# File 'lib/osa/clients/ms_graph_client.rb', line 32
def mails(folder_id)
Paginated.new(get("/v1.0/me/mailFolders/#{folder_id}/messages"), self)
end
|
#raw_mail(mail_id) ⇒ Object
36
37
38
|
# File 'lib/osa/clients/ms_graph_client.rb', line 36
def raw_mail(mail_id)
get("/v1.0/me/messages/#{mail_id}/$value")
end
|
#rule(id) ⇒ Object
24
25
26
|
# File 'lib/osa/clients/ms_graph_client.rb', line 24
def rule(id)
get("/v1.0/me/mailFolders/inbox/messageRules/#{id}")
end
|
#rules ⇒ Object
20
21
22
|
# File 'lib/osa/clients/ms_graph_client.rb', line 20
def rules
get('/v1.0/me/mailFolders/inbox/messageRules')
end
|
#send_message(id) ⇒ Object
82
83
84
|
# File 'lib/osa/clients/ms_graph_client.rb', line 82
def send_message(id)
post("/v1.0/me/messages/#{id}/send")
end
|
#update_message(id, update) ⇒ Object
78
79
80
|
# File 'lib/osa/clients/ms_graph_client.rb', line 78
def update_message(id, update)
patch("/v1.0/me/messages/#{id}", update.to_json, 'content-type': 'application/json')
end
|
#update_rule(id, update) ⇒ Object
74
75
76
|
# File 'lib/osa/clients/ms_graph_client.rb', line 74
def update_rule(id, update)
patch("/v1.0/me/mailFolders/inbox/messageRules/#{id}", update.to_json, 'content-type' => 'application/json')
end
|