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
- #update_message(id, update) ⇒ Object
- #update_rule(id, update) ⇒ Object
Constructor Details
#initialize(token) ⇒ MSGraphClient
Returns a new instance of MSGraphClient.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/osa/clients/ms_graph_client.rb', line 14 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
71 72 73 74 75 76 77 |
# File 'lib/osa/clients/ms_graph_client.rb', line 71 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
67 68 69 |
# File 'lib/osa/clients/ms_graph_client.rb', line 67 def (mail_id) @authenticated.post("/v1.0/me/messages/#{mail_id}/createForward") end |
#delete_mail(mail_id) ⇒ Object
79 80 81 |
# File 'lib/osa/clients/ms_graph_client.rb', line 79 def delete_mail(mail_id) @authenticated.delete("/v1.0/me/messages/#{mail_id}") end |
#folders ⇒ Object
35 36 37 |
# File 'lib/osa/clients/ms_graph_client.rb', line 35 def folders Paginated.new(@authenticated.get('/v1.0/me/mailFolders'), @authenticated) end |
#forward_mail_as_attachment(mail_id, to) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/osa/clients/ms_graph_client.rb', line 47 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
39 40 41 |
# File 'lib/osa/clients/ms_graph_client.rb', line 39 def mails(folder_id) Paginated.new(@authenticated.get("/v1.0/me/mailFolders/#{folder_id}/messages"), @authenticated) end |
#raw_mail(mail_id) ⇒ Object
43 44 45 |
# File 'lib/osa/clients/ms_graph_client.rb', line 43 def raw_mail(mail_id) @authenticated.get("/v1.0/me/messages/#{mail_id}/$value") end |
#rule(id) ⇒ Object
31 32 33 |
# File 'lib/osa/clients/ms_graph_client.rb', line 31 def rule(id) @authenticated.get("/v1.0/me/mailFolders/inbox/messageRules/#{id}") end |
#rules ⇒ Object
27 28 29 |
# File 'lib/osa/clients/ms_graph_client.rb', line 27 def rules @authenticated.get('/v1.0/me/mailFolders/inbox/messageRules') end |
#send_message(id) ⇒ Object
91 92 93 |
# File 'lib/osa/clients/ms_graph_client.rb', line 91 def (id) @authenticated.post("/v1.0/me/messages/#{id}/send") end |
#update_message(id, update) ⇒ Object
87 88 89 |
# File 'lib/osa/clients/ms_graph_client.rb', line 87 def (id, update) @authenticated.patch("/v1.0/me/messages/#{id}", update.to_json, 'content-type': 'application/json') end |
#update_rule(id, update) ⇒ Object
83 84 85 |
# File 'lib/osa/clients/ms_graph_client.rb', line 83 def update_rule(id, update) @authenticated.patch("/v1.0/me/mailFolders/inbox/messageRules/#{id}", update.to_json, 'content-type' => 'application/json') end |