Class: OSA::MSGraphClient
- Inherits:
-
Object
- Object
- OSA::MSGraphClient
- Defined in:
- lib/osa/clients/ms_graph_client.rb
Constant Summary collapse
- URL =
'https://graph.microsoft.com'
Instance Method Summary collapse
- #add_email_attachment(mail_id, name, content) ⇒ Object
- #create_forward_message(mail_id) ⇒ Object
- #delete_mail(mail_id) ⇒ Object
- #folders ⇒ Object
- #forward_mail_as_attachment(mail_id, to) ⇒ Object
-
#initialize(token) ⇒ MSGraphClient
constructor
A new instance of MSGraphClient.
- #mails(folder_id) ⇒ Object
- #raw_mail(mail_id) ⇒ Object
- #rule(id) ⇒ Object
- #rules ⇒ Object
- #send_message(id) ⇒ Object
- #sender_ip(mail_id) ⇒ Object
- #update_message(id, update) ⇒ Object
- #update_rule(id, update) ⇒ Object
Constructor Details
#initialize(token) ⇒ MSGraphClient
Returns a new instance of MSGraphClient.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/osa/clients/ms_graph_client.rb', line 15 def initialize(token) @authenticated = HttpClient.new(Faraday.new( url: 'https://graph.microsoft.com', headers: { 'authorization' => "Bearer #{token}" } )) @unauthenticated = HttpClient.new(Faraday.new( url: 'https://graph.microsoft.com' )) end |
Instance Method Details
#add_email_attachment(mail_id, name, content) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/osa/clients/ms_graph_client.rb', line 78 def (mail_id, name, content) if content.length < 3.megabytes (mail_id, name, content) else (mail_id, name, content) end end |
#create_forward_message(mail_id) ⇒ Object
74 75 76 |
# File 'lib/osa/clients/ms_graph_client.rb', line 74 def (mail_id) @authenticated.post("/v1.0/me/messages/#{mail_id}/createForward") end |
#delete_mail(mail_id) ⇒ Object
86 87 88 |
# File 'lib/osa/clients/ms_graph_client.rb', line 86 def delete_mail(mail_id) @authenticated.delete("/v1.0/me/messages/#{mail_id}") end |
#folders ⇒ Object
36 37 38 |
# File 'lib/osa/clients/ms_graph_client.rb', line 36 def folders Paginated.new(@authenticated.get('/v1.0/me/mailFolders'), @authenticated) end |
#forward_mail_as_attachment(mail_id, to) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/osa/clients/ms_graph_client.rb', line 54 def (mail_id, to) raw_mail = self.raw_mail(mail_id) = (mail_id) update = { body: { content: '' }, toRecipients: [ { emailAddress: { address: to } } ] } (['id'], update) (['id'], 'email.eml', raw_mail) (['id']) end |
#mails(folder_id) ⇒ Object
40 41 42 |
# File 'lib/osa/clients/ms_graph_client.rb', line 40 def mails(folder_id) Paginated.new(@authenticated.get("/v1.0/me/mailFolders/#{folder_id}/messages"), @authenticated) end |
#raw_mail(mail_id) ⇒ Object
44 45 46 |
# File 'lib/osa/clients/ms_graph_client.rb', line 44 def raw_mail(mail_id) @authenticated.get("/v1.0/me/messages/#{mail_id}/$value") end |
#rule(id) ⇒ Object
32 33 34 |
# File 'lib/osa/clients/ms_graph_client.rb', line 32 def rule(id) @authenticated.get("/v1.0/me/mailFolders/inbox/messageRules/#{id}") end |
#rules ⇒ Object
28 29 30 |
# File 'lib/osa/clients/ms_graph_client.rb', line 28 def rules @authenticated.get('/v1.0/me/mailFolders/inbox/messageRules') end |
#send_message(id) ⇒ Object
98 99 100 |
# File 'lib/osa/clients/ms_graph_client.rb', line 98 def (id) @authenticated.post("/v1.0/me/messages/#{id}/send") end |
#sender_ip(mail_id) ⇒ Object
48 49 50 51 52 |
# File 'lib/osa/clients/ms_graph_client.rb', line 48 def sender_ip(mail_id) content = raw_mail(mail_id) mail = Mail.new(content) mail.header['x-sender-ip'] end |
#update_message(id, update) ⇒ Object
94 95 96 |
# File 'lib/osa/clients/ms_graph_client.rb', line 94 def (id, update) @authenticated.patch("/v1.0/me/messages/#{id}", update.to_json, 'content-type': 'application/json') end |
#update_rule(id, update) ⇒ Object
90 91 92 |
# File 'lib/osa/clients/ms_graph_client.rb', line 90 def update_rule(id, update) @authenticated.patch("/v1.0/me/mailFolders/inbox/messageRules/#{id}", update.to_json, 'content-type' => 'application/json') end |