Class: DistributionWrappers::Office365

Inherits:
Email
  • Object
show all
Defined in:
lib/distribution_wrappers/office365/office365.rb

Instance Attribute Summary

Attributes inherited from Base

#params

Instance Method Summary collapse

Methods inherited from Email

#prepare

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from DistributionWrappers::Base

Instance Method Details

#get_contactsObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/distribution_wrappers/office365/office365.rb', line 33

def get_contacts
  key = @auth[:key]
  results = []
  
  response = RestClient.get('https://graph.microsoft.com/v1.0/me/contacts', {"Authorization" => "Bearer #{key}"})
  contacts = JSON.parse(response.body)
  
  csv_string = ""
  
  contacts['value'].each do |contact|
    csv_string += CSV.generate_line [contact['displayName'], contact['emailAddresses'].first['address'], '{"url": null}', 'email', @params[:channel_id]]
  end  
  
  @params[:temp_file].write(csv_string)
  
  return true
end

#send_message(email) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/distribution_wrappers/office365/office365.rb', line 4

def send_message(email)
  super
  key = @auth[:key]
  recipients = []
  
  # Office 365's API takes addresses in a specific way, so we have to build up an array 
  # of recipients before we hit their API 
  recipients << {'emailAddress' => {"address" => email['identifier']}}
  
  message = {
    'subject' => @params[:subject],
    'body' => {
      'contentType' => 'HTML',
      'content' => @message
    },
    "toRecipients" => recipients,
    "sender" => {
      "emailAddress" => {
        "address" => @params[:custom_opts]['send_from']
      }
    }
  }
  
  send_response = Curl.post('https://graph.microsoft.com/v1.0/me/sendMail', {"Message" => message}.to_json) do |http|
    http.headers['Authorization'] = "Bearer #{key}"
    http.headers['Content-Type'] = 'application/json'
  end
end