lib/macaco/senders/sendgrid.rb in macaco-0.0.4 vs lib/macaco/senders/sendgrid.rb in macaco-0.0.5
- old
+ new
@@ -1,10 +1,10 @@
module Macaco
class Sendgrid < Sender
def docs
- 'http://sendgrid.com/docs/API_Reference/Web_API/mail.html'
+ 'https://sendgrid.com/docs/API_Reference/Web_API/mail.html#-send'
end
def api_root
'api.sendgrid.com'
end
@@ -25,33 +25,26 @@
html: @body_html,
text: @body_text
}
end
- def to(val = nil)
- return @to unless val
- @to << val
- end
-
def send
- data = to_hash.merge!({ api_key: api_key, api_user: api_user })
- Macaco::Api.post({ mail: self, data: convert_data_params(data) })
+ data = to_hash
+ Macaco::Api.post({
+ mail: self,
+ data: convert_data_params(data),
+ headers: { "Authorization" => "Bearer #{api_key}" }
+ })
end
private
def convert_data_params(data)
- addr = Addressable::URI.new
- addr.query_values = data
- addr.query
+ URI.encode_www_form(data)
end
def api_key
- Macaco.config.api_key || ENV['MACACO_API_KEY']
- end
-
- def api_user
- Macaco.config.api_user || ENV['MACACO_USER']
+ Macaco.config.api_key || ENV['SENDGRID_API_KEY']
end
end
end