Skip to content
A Ruby library wrapping SendGrid's Newsletter API.
Ruby
Pull request Compare This branch is 14 commits ahead, 11 commits behind bmuller:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
data
lib
.gitignore
Gemfile
README.markdown
Rakefile
gatling_gun.gemspec

README.markdown

Gatling Gun

Gatling Gun is a library that helps you blast out a group of emails. It's a simple wrapper over SendGrid's Newsletter API.

Install

If you want to use this code in a Rails application, just add it to your Gemfile:

gem "gatling_gun"

To use the code in a non-Rails application, first install the gem:

gem install gatling_gun

Then require the library in your code:

require "gatling_gun"

Either way, you will want to setup Gatling Gun as your application loads. You can configure GatlingGun using a configure block or you can create a GatlingGun::Client directly. In Rails, I would put the following code in config/initializers/gatling_gun.rb. Setup is easy, just add you SendGrid credentials:

GatlingGun.configure do |config|
  config.username = "USERNAME"
  config.password = "PASSWORD"
end

A client can then be accessed as a method on GatlingGun

GatlingGun.client

Alternately, you can instantiate a client directly:

GatlingGun::Client.new("USERNAME", "PASSWORD")

Usage

The minimal steps to create and send a newsletter would be something like the following. First, you need an identity to send from:

GatlingGun.client.add_identity( "test", :name    => "Test User",
                                :email   => "test@subinterest.com",
                                :address => "513 Cinnamon Dr.",
                                :city    => "Edmond",
                                :state   => "OK",
                                :zip     => "73003",
                                :country => "USA" )

Then you can create a newsletter using that identity:

GatlingGun.client.add_newsletter( "episode1", :identity => "test",
                                  :subject  => "Episode 1",
                                  :text     => "The Text Body",
                                  :html     => "<h1>The HTML Body</h1>" )

Next you need to create a list of recipients, add some emails to it, and attach that list to the newsletter:

GatlingGun.client.add_list("subscribers")
GatlingGun.client.add_emails( "subscribers", [ { :name  => "James Edward Gray II",
                                                 :email => "james@graysoftinc.com" },
                                               { :name  => "Admin",
                                                 :email => "admin@graysoftinc.com" } ] )
SendGrid.add_recipients("episode1", "subscribers")

Of course, you could reuse identities and recipient lists for future newsletter messages without needing to recreate them.

Finally, you can schedule when to have the message sent:

GatlingGun.client.add_schedule("episode1", :at => Time.now + 10 * 60)

That would sent it 10 minutes from now, but you can adjust the time to whenever you desire or even leave it out to send now.

Something went wrong with that request. Please try again.