Class: SendgridRuby::Sendgrid

Inherits:
Object
  • Object
show all
Defined in:
lib/sendgrid_ruby.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, password, options = {"turn_off_ssl_verification" => false}) ⇒ Sendgrid

Returns a new instance of Sendgrid.



11
12
13
14
15
16
# File 'lib/sendgrid_ruby.rb', line 11

def initialize(username, password, options={"turn_off_ssl_verification" => false})
  @username = username
  @password = password
  @options = options
  @debug_output = false
end

Instance Attribute Details

#debug_outputObject

Returns the value of attribute debug_output.



9
10
11
# File 'lib/sendgrid_ruby.rb', line 9

def debug_output
  @debug_output
end

Instance Method Details

#send(email) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sendgrid_ruby.rb', line 18

def send(email)
  form              = email.to_web_format
  form['api_user']  = @username
  form['api_key']   = @password

  RestClient.log = $stderr if @debug_output

  headers          = Hash.new
  headers[:content_type] = :json
  response = RestClient.post 'https://api.sendgrid.com/api/mail.send.json', form, :content_type => :json, "User-Agent" => "sendgrid/#{SendgridRuby::VERSION};ruby"

  JSON.parse(response.body)
end