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
Constant Summary collapse
- VERSION =
"0.0.1"
Class Attribute Summary collapse
-
.api_key ⇒ Object
Returns the value of attribute api_key.
-
.api_namespace ⇒ Object
Returns the value of attribute api_namespace.
-
.api_user ⇒ Object
Returns the value of attribute api_user.
-
.host ⇒ Object
Returns the value of attribute host.
-
.scheme ⇒ Object
Returns the value of attribute scheme.
Class Method Summary collapse
- .configure {|_self| ... } ⇒ Object
-
.method_missing(resource, verb, format = :json, &block) ⇒ Object
Primary interface.
Class Attribute Details
.api_key ⇒ Object
Returns the value of attribute api_key.
43 44 45 |
# File 'lib/sendgrid_web.rb', line 43 def api_key @api_key end |
.api_namespace ⇒ Object
Returns the value of attribute api_namespace.
43 44 45 |
# File 'lib/sendgrid_web.rb', line 43 def api_namespace @api_namespace end |
.api_user ⇒ Object
Returns the value of attribute api_user.
43 44 45 |
# File 'lib/sendgrid_web.rb', line 43 def api_user @api_user end |
.host ⇒ Object
Returns the value of attribute host.
43 44 45 |
# File 'lib/sendgrid_web.rb', line 43 def host @host end |
.scheme ⇒ Object
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
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 |