Skip to content

gemspec + delivery_method (+ Added Bearer to Authorization header) #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# rcov generated
coverage
coverage.data

# rdoc generated
rdoc

# yard generated
doc
.yardoc

# bundler
.bundle

# jeweler generated
pkg

# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
#
# * Create a file at ~/.gitignore
# * Include files you want ignored
# * Run: git config --global core.excludesfile ~/.gitignore
#
# After doing this, these files will be ignored in all your git projects,
# saving you from having to 'pollute' every project you touch with them
#
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
#
# For MacOS:
#
#.DS_Store

# For TextMate
#*.tmproj
#tmtags

# For emacs:
#*~
#\#*
#.\#*

# For vim:
#*.swp

# For redcar:
#.redcar

# For rubinius:
#*.rbc
12 changes: 12 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true
source "https://rubygems.org"

# gem "rails"

group :development do
gem "shoulda", ">= 0"
gem "rdoc", "~> 3.12"
gem "bundler", "~> 1.0"
gem "jeweler", "~> 2.3.0"
gem "simplecov", ">= 0"
end
87 changes: 87 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (5.1.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.4.0)
builder (3.2.3)
concurrent-ruby (1.0.5)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
docile (1.1.5)
faraday (0.9.2)
multipart-post (>= 1.2, < 3)
git (1.3.0)
github_api (0.16.0)
addressable (~> 2.4.0)
descendants_tracker (~> 0.0.4)
faraday (~> 0.8, < 0.10)
hashie (>= 3.4)
mime-types (>= 1.16, < 3.0)
oauth2 (~> 1.0)
hashie (3.5.5)
highline (1.7.8)
i18n (0.8.4)
jeweler (2.3.6)
builder
bundler (>= 1)
git (>= 1.2.5)
github_api (~> 0.16.0)
highline (>= 1.6.15)
nokogiri (>= 1.5.10)
psych (~> 2.2)
rake
rdoc
semver2
json (1.8.6)
jwt (1.5.6)
mime-types (2.99.3)
mini_portile2 (2.2.0)
minitest (5.10.2)
multi_json (1.12.1)
multi_xml (0.6.0)
multipart-post (2.0.0)
nokogiri (1.8.0)
mini_portile2 (~> 2.2.0)
oauth2 (1.3.1)
faraday (>= 0.8, < 0.12)
jwt (~> 1.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (>= 1.2, < 3)
psych (2.2.4)
rack (2.0.3)
rake (12.0.0)
rdoc (3.12.2)
json (~> 1.4)
semver2 (3.4.2)
shoulda (3.5.0)
shoulda-context (~> 1.0, >= 1.0.1)
shoulda-matchers (>= 1.4.1, < 3.0)
shoulda-context (1.2.2)
shoulda-matchers (2.8.0)
activesupport (>= 3.0.0)
simplecov (0.14.1)
docile (~> 1.1.0)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.1)
thread_safe (0.3.6)
tzinfo (1.2.3)
thread_safe (~> 0.1)

PLATFORMS
ruby

DEPENDENCIES
bundler (~> 1.0)
jeweler (~> 2.3.0)
rdoc (~> 3.12)
shoulda
simplecov

BUNDLED WITH
1.15.1
128 changes: 128 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,130 @@
# sendpulse-rest-api-ruby

A simple SendPulse REST client library and example for Ruby.

Includes a REST API and a Rails ActionMailer Delivery Method using the REST API.

## REST API Pre-requisites

Please activate REST API and obtain your API Client ID and Secret values by following these instructions:
- Login to login.sendpulse.com
- Go to Account Settings -> API tab
- Activate REST API (if not already activated).
- Copy and paste ID and Secret from there

## Setup Instructions

### Ruby without Bundler

Run the following command in your terminal:
```bash
gem install sendpulse-rest-api-ruby
```

Add the following require line to your ruby code:
```ruby
require 'sendpulse-rest-api-ruby'
```

### Rails or Ruby with Bundler

Add the following to `Gemfile`:
```ruby
gem 'sendpulse-rest-api-ruby'
```

Run the following command in your terminal:

```bash
bundle
```

Outside of Rails, you'd have to add a require line like the one in "Ruby without Bundler".

### Rails REST API Configuration

In Rails, you'd also have to configure the `API_CLIENT_ID` and `API_CLIENT_SECRET` variables at minimum.

It is recommended to do so by adding a Rails initializer as follows:
- Under `config/initializers`, create a file named `sendpulse_initializer.rb`
- Add the following code to it (entering the correct values):
```ruby
Sendpulse.configure do |config|
config.api_client_id = 'apiclientidvalue'
config.api_client_secret = 'apiclientsecretvalue'
end
```

For use with Heroku, it is recommended you configure Rails initializer via environment variables as follows:

```ruby
Sendpulse.configure do |config|
config.api_client_id = ENV['SENDPULSE_API_CLIENT_ID']
config.api_client_secret = ENV['SENDPULSE_API_CLIENT_SECRET']
end
```

Then run the following command to configure these environment variables in Heroku:
```bash
heroku config:add SENDPULSE_API_CLIENT_ID=apiclientidvalue SENDPULSE_API_CLIENT_SECRET=apiclientsecretvalue
```

### Rails ActionMailer Delivery Method Configuration

This depends on Rails REST API Configuration being done.

Simply set your `config.action_mailer.delivery_method` to `:sendpulse` in your environment config file.

For example, you can add the following to `config/environments/production.rb` for production's deployment:
```ruby
config.action_mailer.delivery_method = :sendpulse
```

## API Example

```ruby
require 'sendpulse-rest-api-ruby'
require 'yaml'

API_CLIENT_ID = 'apiclientidvalue'
API_CLIENT_SECRET = 'apiclientsecretvalue'
API_PROTOCOL = 'https'
API_TOKEN = ''

sendpulse_api = SendpulseApi.new(API_CLIENT_ID, API_CLIENT_SECRET, API_PROTOCOL, API_TOKEN)

result = sendpulse_api.get_token
YAML::dump(result)

result = sendpulse_api.create_campaign('Name', '[email protected]', 'Example subject', '<html><b>Example</b></html>', 'book_id') #+
YAML::dump(result)

result = sendpulse_api.add_sender('Some name', '[email protected]')
YAML::dump(result)

result = sendpulse_api.get_balance
YAML::dump(result)

email = {
html: '<html><body><H1>TEXT</H1></body></html>',
text: 'TEST',
subject: 'Test, test test test',
from: { name: 'some', email: '[email protected]' },
to: [
{ name: 'some1', email: '[email protected]' },
{ name: 'some3', email: '[email protected]' },
],
bcc: [{ name: 'some2', email: '[email protected]' }]
}

result = sendpulse_api.smtp_send_mail(email)
YAML::dump(result)
```

## License

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Copyright 2015 SendPulse
See `LICENSE` for more details.
44 changes: 44 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# encoding: utf-8

require 'rubygems'
require 'bundler'
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
require 'rake'

require 'jeweler'
Jeweler::Tasks.new do |gem|
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
gem.name = "sendpulse-rest-api-ruby"
gem.homepage = "http://github.com/sendpulse/sendpulse-rest-api-ruby"
gem.license = "MIT"
gem.summary = %Q{A simple SendPulse REST client library and example for Ruby.}
gem.description = %Q{A simple SendPulse REST client library and example for Ruby.}
gem.email = "[email protected]"
gem.authors = ["SendPulse Tech Team"]
# dependencies defined in Gemfile
end
Jeweler::RubygemsDotOrgTasks.new

desc "Code coverage detail"
task :simplecov do
ENV['COVERAGE'] = "true"
Rake::Task['test'].execute
end

task :default => :version #TODO change to test/rspec once added

require 'rdoc/task'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""

rdoc.rdoc_dir = 'rdoc'
rdoc.title = "sendpulse-rest-api-ruby #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0
4 changes: 2 additions & 2 deletions example.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require './api/sendpulse_api'
require_relative 'lib/sendpulse-rest-api-ruby'
require 'yaml'

API_CLIENT_ID = ''
Expand Down Expand Up @@ -33,4 +33,4 @@
}

result = sendpulse_api.smtp_send_mail(email)
YAML::dump(result)
YAML::dump(result)
15 changes: 15 additions & 0 deletions lib/action_mailer/sendpulse.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Sendpulse

def self.configuration
@configration ||= Configuration.new
end

def self.configure
yield(configuration)
end
end

require_relative 'sendpulse/configuration'
require_relative 'sendpulse/delivery_method'
require_relative 'sendpulse/message'
require_relative 'sendpulse/railtie' if defined?(Rails::Railtie)
10 changes: 10 additions & 0 deletions lib/action_mailer/sendpulse/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Sendpulse
class Configuration
attr_accessor :api_client_id, :api_client_secret, :api_protocol, :options, :logger

def initialize
@api_protocol = 'https'
@logger = Rails.logger if defined?(Rails)
end
end
end
Loading