Module: SendgridWeb

Defined in:
lib/sendgrid_web.rb,
lib/sendgrid_web/utils.rb,
lib/sendgrid_web/request.rb,
lib/sendgrid_web/version.rb

Overview

Module to provide thin ruby API to SendGrid Web API. Uses Faraday to make requests. Currently supports synchronous calls only.

Exposes both Sendgrid and Faraday interfaces.

Defined Under Namespace

Modules: Request, URL

Constant Summary collapse

VERSION =
"0.0.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_keyObject

Returns the value of attribute api_key.



43
44
45
# File 'lib/sendgrid_web.rb', line 43

def api_key
  @api_key
end

.api_namespaceObject

Returns the value of attribute api_namespace.



43
44
45
# File 'lib/sendgrid_web.rb', line 43

def api_namespace
  @api_namespace
end

.api_userObject

Returns the value of attribute api_user.



43
44
45
# File 'lib/sendgrid_web.rb', line 43

def api_user
  @api_user
end

.hostObject

Returns the value of attribute host.



43
44
45
# File 'lib/sendgrid_web.rb', line 43

def host
  @host
end

.schemeObject

Returns the value of attribute scheme.



43
44
45
# File 'lib/sendgrid_web.rb', line 43

def scheme
  @scheme
end

Class Method Details

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (SendgridWeb)

    the object that the method was called on



45
46
47
# File 'lib/sendgrid_web.rb', line 45

def configure
  yield self
end

.method_missing(resource, verb, format = :json, &block) ⇒ Object

Primary interface. Simply call the desired module directly on SendgridWeb and pass in the verb, format and a block to set any needed parameters.

Example usage:

# Make a request to SendGrid module, say Unsubscribes
# fetching a specific email.
faraday_response = SendgridWeb.unsubscribes(:get, :json) { request.param :email => '[email protected]' }

# Send an email.
faraday_response = SendgridWeb.mail(:send, :xml) do
  request.param :to => '[email protected]', :subject => 'Tada!', :from => '[email protected]'
  request.param :text => 'sample message body'
  request.param :html => '<p>sample message body</p>'
end


31
32
33
34
35
36
37
38
39
40
# File 'lib/sendgrid_web.rb', line 31

def self.method_missing(resource, verb, format=:json, &block)
  Request.configure do |request|
    request.verb = verb
    request.resource = resource
    request.format = format

    yield request
  end
  process
end