mailstro 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bfb6f6f8d8402d20a20f56153d3cab92a269f810
4
+ data.tar.gz: 91bebe9ce5c5c57ba696b558efaa9345f4224b1d
5
+ SHA512:
6
+ metadata.gz: 442beb7b0c5cd4455dd7ea909c10b34cda4a7ef09dad54f27ffbff8f46379661fb1dc42f0df60ff4e551b39cd457d80942ad9494ecde1e6363c4753d13cdb03f
7
+ data.tar.gz: 7e06752aac384dd4b78e0e26db7670991cf25344e5055a4b51513d80c2e0a37bdfde9a8f5e69230baeff0e5d225e533456698ebeca83781d112bea73bade88a0
data/.env-sample ADDED
@@ -0,0 +1,4 @@
1
+ MAILMASK_API_KEY=secret
2
+ MAILMASK_ENDPOINT=api.mailmask.co
3
+ MAILMASK_API_VERSION=1
4
+ MAILMASK_USE_SSL=true
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .env
19
+ .rbenv-vars
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --backtrace
2
+ --color
3
+ --format doc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mailstro-ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Keith Pitt
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ rescue LoadError
7
+ puts "rspec no available"
8
+ end
9
+
10
+ task :default => ['spec']
data/Readme.md ADDED
@@ -0,0 +1,51 @@
1
+ # Mailstro Client for Ruby
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ 1. Add the `mailstro` gem to your `Gemfile`
8
+
9
+ ```ruby
10
+ gem "mailstro"
11
+ ```
12
+
13
+ 2. Install the gem
14
+
15
+ ```shell
16
+ bundle install
17
+ ```
18
+
19
+ 3. Configure the mailstro module with your API key.
20
+
21
+ In rails apps, put this code to a new file at `config/initializers/mailstro.rb`
22
+
23
+ ```ruby
24
+ require 'mailstro'
25
+
26
+ Mailstro.configure do |config|
27
+ config.api_key = "YOUR_API_KEY_HERE"
28
+ end
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ To send an email with the template name `welcome` use the following:
34
+
35
+ ```ruby
36
+ Mailstro.deliver(:welcome, :recipient => { :email => "test@example.com" }, :payload => { :greeting => "Hi" })
37
+ ```
38
+
39
+ ## Testing
40
+
41
+ Copy the `.env-sample` file, and rename it to `.env`. Here, put in your
42
+ Mailstro credentials. This should allow you to run the integration tests
43
+ against your account.
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
@@ -0,0 +1,14 @@
1
+ module Mailstro
2
+ class Configuration
3
+ attr_accessor :api_key
4
+ attr_accessor :endpoint
5
+ attr_accessor :use_ssl
6
+ attr_accessor :api_version
7
+
8
+ def initialize
9
+ @use_ssl = true
10
+ @endpoint = 'api.mailstro.co'
11
+ @api_version = 1
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,56 @@
1
+ module Mailstro
2
+ class Delivery
3
+ require 'net/http'
4
+ require 'openssl'
5
+ require 'json'
6
+
7
+ attr_reader :template, :recipient, :payload
8
+
9
+ def self.deliver(*args)
10
+ new(*args).deliver
11
+ end
12
+
13
+ def initialize(template, options)
14
+ @template = template
15
+ @recipient = options[:recipient]
16
+ @payload = options[:payload]
17
+ end
18
+
19
+ def deliver
20
+ http = Net::HTTP.new(endpoint_uri.host, endpoint_uri.port)
21
+ http.use_ssl = endpoint_uri.scheme == "https"
22
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
23
+
24
+ request = Net::HTTP::Post.new(endpoint_uri.request_uri, { 'Content-Type' =>'application/json' })
25
+ request.body = JSON.generate(post_data)
26
+
27
+ response = http.request(request)
28
+
29
+ # response.status
30
+ # response["header-here"] # All headers are lowercase
31
+
32
+ JSON.parse(response.body)
33
+ end
34
+
35
+ private
36
+
37
+ def post_data
38
+ { 'template' => template,
39
+ 'recipient' => recipient,
40
+ 'api_key' => Mailstro.configuration.api_key }.tap do |payload|
41
+ if self.payload.kind_of?(Hash)
42
+ payload['payload'] = self.payload
43
+ end
44
+ end
45
+ end
46
+
47
+ def endpoint_uri
48
+ @endpoint_uri ||= URI.parse(endpoint)
49
+ end
50
+
51
+ def endpoint
52
+ (Mailstro.configuration.use_ssl ? "https://" : "http://") +
53
+ "#{Mailstro.configuration.endpoint}/v#{Mailstro.configuration.api_version}/postman"
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,15 @@
1
+ require 'mailstro/test'
2
+
3
+ RSpec.configure do |config|
4
+ config.before(:suite) do
5
+ Mailstro::Test.enable
6
+ end
7
+
8
+ config.after(:suite) do
9
+ Mailstro::Test.disable
10
+ end
11
+
12
+ config.before(:each) do
13
+ Mailstro::Test.clear_deliveries
14
+ end
15
+ end
@@ -0,0 +1,41 @@
1
+ module Mailstro
2
+ module Test
3
+ @@enabled = false
4
+ @@deliveries = []
5
+
6
+ def self.deliveries
7
+ @@deliveries
8
+ end
9
+
10
+ def self.clear_deliveries
11
+ @@deliveries = []
12
+ end
13
+
14
+ def self.enable
15
+ def Mailstro.deliver(*args)
16
+ Mailstro::Test.deliveries << Mailstro::Delivery.new(*args)
17
+ true # insert response here
18
+ end
19
+
20
+ def Mailstro.has_delivered?(*args)
21
+ Mailstro::Test.has_delivered?(*args)
22
+ end
23
+
24
+ @@enabled = true
25
+ end
26
+
27
+ def self.disable
28
+ def Mailstro.deliver(*args)
29
+ Mailstro::Delivery.deliver(*args)
30
+ end
31
+
32
+ @@enabled = false
33
+ end
34
+
35
+ def self.has_delivered?(options)
36
+ templates = @@deliveries.map(&:template)
37
+
38
+ templates.include?(options[:template])
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module Mailstro
2
+ VERSION = "0.0.1"
3
+ end
data/lib/mailstro.rb ADDED
@@ -0,0 +1,18 @@
1
+ require "mailstro/version"
2
+ require "mailstro/configuration"
3
+ require "mailstro/delivery"
4
+
5
+ module Mailstro
6
+ class << self
7
+ attr_accessor :configuration
8
+ end
9
+
10
+ def self.configure
11
+ self.configuration ||= Configuration.new
12
+ yield(configuration)
13
+ end
14
+
15
+ def self.deliver(*args)
16
+ Delivery.deliver(*args)
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mailstro/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mailstro"
8
+ spec.version = Mailstro::VERSION
9
+ spec.authors = ["Keith Pitt"]
10
+ spec.email = ["me@keithpitt.com"]
11
+ spec.description = %q{Ruby notifier for mailstro.co}
12
+ spec.summary = %q{Ruby notifier for mailstro.co}
13
+ spec.homepage = "http://www.mailstro.co"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mailstro::Delivery, :integration do
4
+ let(:template) { :test }
5
+ let(:recipient) { { :email => "test@example.com" } }
6
+ let(:payload) { { :greeting => "Gday!" } }
7
+
8
+ before do
9
+ Mailstro.configure do |config|
10
+ config.use_ssl = ENV['MAILSTRO_USE_SSL'] == 'true'
11
+ config.endpoint = ENV['MAILSTRO_ENDPOINT']
12
+ config.api_version = ENV['MAILSTRO_API_VERSION']
13
+ config.api_key = ENV['MAILSTRO_API_KEY']
14
+ end
15
+ end
16
+
17
+ it "succesfully submits a delivery to mailstro" do
18
+ pending
19
+ response = Mailstro.deliver(template, :recipient => recipient, :payload => payload)
20
+ response['ok'].should == true
21
+ end
22
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mailstro::Configuration do
4
+ subject(:configuration) { Mailstro::Configuration.new }
5
+
6
+ it "has a default endpoint" do
7
+ configuration.endpoint.should =~ /mailstro/
8
+ end
9
+ end
@@ -0,0 +1,58 @@
1
+ require "spec_helper"
2
+
3
+ describe Mailstro::Delivery do
4
+ let(:template) { "name" }
5
+ let(:recipient) { { :email => "foo@bar.com" } }
6
+ let(:payload) { { :data => "here" } }
7
+
8
+ describe '.delivery' do
9
+ let(:delivery) { double }
10
+
11
+ it "creates an instance of the Delivery and delivers it" do
12
+ Mailstro::Delivery.should_receive(:new).with(template, :recipient => recipient, :payload => payload).and_return(delivery)
13
+ delivery.should_receive(:deliver)
14
+
15
+ Mailstro::Delivery.deliver(template, :recipient => recipient, :payload => payload)
16
+ end
17
+ end
18
+
19
+ describe "#delivery" do
20
+ let(:delivery) { Mailstro::Delivery.new(template, :recipient => recipient, :payload => payload) }
21
+ let(:request) { double.as_null_object }
22
+ let(:response) { double(:body => '{ "status": "OK" }').as_null_object }
23
+ let(:http) { double(:request => response).as_null_object }
24
+ let(:configuration) { double(:use_ssl => true, :endpoint => 'foo.com', :api_version => '2', :api_key => '1234') }
25
+
26
+ before do
27
+ Mailstro.stub(:configuration => configuration)
28
+ Net::HTTP.should_receive(:new).with('foo.com', 443).and_return(http)
29
+ Net::HTTP::Post.should_receive(:new).with('/v2/postman', { "Content-Type"=>"application/json" }).and_return(request)
30
+ end
31
+
32
+ it "sends a json payload to the mailstro server" do
33
+ http.should_receive(:request).with(request).and_return(response)
34
+
35
+ delivery.deliver
36
+ end
37
+
38
+ it "generates the correct payload" do
39
+ expected_form_data = {
40
+ 'template' => 'name',
41
+ 'recipient' => { 'email' => 'foo@bar.com' },
42
+ 'payload' => { 'data' => 'here' },
43
+ 'api_key' => '1234'
44
+ }
45
+
46
+ request.should_receive(:body=) do |body|
47
+ parsed_body = JSON.parse(body)
48
+ parsed_body.should == expected_form_data
49
+ end
50
+
51
+ delivery.deliver
52
+ end
53
+
54
+ it "parses the JSON response" do
55
+ delivery.deliver['status'].should == 'OK'
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+ require 'mailstro/test'
3
+
4
+ describe Mailstro::Test do
5
+ describe '.enable' do
6
+ before do
7
+ Mailstro::Test.enable
8
+ end
9
+
10
+ after do
11
+ Mailstro::Test.disable
12
+ end
13
+
14
+ it "doesn't send deliveries when enabled" do
15
+ Mailstro::Delivery.should_not_receive(:deliver).with(:template_name, {})
16
+
17
+ Mailstro.deliver(:template_name, {})
18
+ end
19
+
20
+ it "adds the delivery to the deliveries array" do
21
+ Mailstro.deliver(:template_name, {})
22
+
23
+ Mailstro::Test.deliveries.should_not be_empty
24
+ end
25
+ end
26
+
27
+ describe '.disable' do
28
+ it 'restores the previous behaviour of .deliver' do
29
+ Mailstro::Test.enable
30
+ Mailstro::Test.disable
31
+ Mailstro::Delivery.should_receive(:deliver).with(:template_name, {})
32
+
33
+ Mailstro.deliver(:template_name, {})
34
+ end
35
+ end
36
+
37
+ describe '.clear_deliveries' do
38
+ before do
39
+ Mailstro::Test.enable
40
+
41
+ Mailstro.deliver(:template_name, {})
42
+ end
43
+
44
+ after do
45
+ Mailstro::Test.disable
46
+ end
47
+
48
+ it 'empties out the .deliveries array' do
49
+ Mailstro::Test.deliveries.should_not be_empty
50
+ Mailstro::Test.clear_deliveries
51
+
52
+ Mailstro::Test.deliveries.should be_empty
53
+ end
54
+ end
55
+
56
+ describe '.has_delivered?' do
57
+ before do
58
+ Mailstro::Test.enable
59
+ end
60
+
61
+ after do
62
+ Mailstro::Test.disable
63
+ end
64
+
65
+ it 'returns true if there was a delivery matching the template name give' do
66
+ Mailstro.deliver(:template_name, {})
67
+
68
+ Mailstro.has_delivered?(:template => :template_name)
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Mailstro::VERSION" do
4
+ it "returns a version number" do
5
+ Mailstro::VERSION.should_not be_nil
6
+ end
7
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mailstro do
4
+ describe ".configure" do
5
+ it "allows you to pass a block to configure Mailstro" do
6
+ Mailstro.configure do |config|
7
+ config.endpoint = 'mailstro.dev'
8
+ end
9
+
10
+ Mailstro.configuration.endpoint.should == 'mailstro.dev'
11
+ end
12
+ end
13
+
14
+ describe ".delivery" do
15
+ let(:template) { "name" }
16
+ let(:recipient) { { :email => "foo@bar.com" } }
17
+ let(:payload) { { :data => "here" } }
18
+
19
+ it "creates a delivery object and delivers it" do
20
+ Mailstro::Delivery.should_receive(:deliver).with(template, :recipient => recipient, :payload => payload)
21
+
22
+ Mailstro.deliver(template, :recipient => recipient, :payload => payload)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ require 'mailstro'
2
+
3
+ RSpec.configure do |config|
4
+ config.treat_symbols_as_metadata_keys_with_true_values = true
5
+ config.run_all_when_everything_filtered = true
6
+ config.filter_run :focus
7
+
8
+ config.order = 'random'
9
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mailstro
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Keith Pitt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Ruby notifier for mailstro.co
56
+ email:
57
+ - me@keithpitt.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .env-sample
63
+ - .gitignore
64
+ - .rspec
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - Rakefile
68
+ - Readme.md
69
+ - lib/mailstro.rb
70
+ - lib/mailstro/configuration.rb
71
+ - lib/mailstro/delivery.rb
72
+ - lib/mailstro/rspec.rb
73
+ - lib/mailstro/test.rb
74
+ - lib/mailstro/version.rb
75
+ - mailmask-ruby.gemspec
76
+ - spec/integration/delivery_spec.rb
77
+ - spec/mailstro/configuration_spec.rb
78
+ - spec/mailstro/delivery_spec.rb
79
+ - spec/mailstro/test_spec.rb
80
+ - spec/mailstro/version_spec.rb
81
+ - spec/mailstro_spec.rb
82
+ - spec/spec_helper.rb
83
+ homepage: http://www.mailstro.co
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.0.0
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Ruby notifier for mailstro.co
107
+ test_files:
108
+ - spec/integration/delivery_spec.rb
109
+ - spec/mailstro/configuration_spec.rb
110
+ - spec/mailstro/delivery_spec.rb
111
+ - spec/mailstro/test_spec.rb
112
+ - spec/mailstro/version_spec.rb
113
+ - spec/mailstro_spec.rb
114
+ - spec/spec_helper.rb