class DistributionWrappers::Office365
Public Instance Methods
get_contacts()
click to toggle source
# 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)
click to toggle source
Calls superclass method
DistributionWrappers::Base#send_message
# 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