mailstro 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Readme.md CHANGED
@@ -33,10 +33,9 @@ TODO: Write a gem description
33
33
  Sending a basic email.
34
34
 
35
35
  ```ruby
36
- Mailstro.deliver(
37
- :to => 'shanon@mailstroapp.com',
38
- :template_name => :welcome,
39
- :template_data => {
36
+ Mailstro.deliver(:welcome
37
+ :to => 'shanon@mailstroapp.com',
38
+ :data => {
40
39
  :coupon_code => 'THANKS01'
41
40
  }
42
41
  )
@@ -53,14 +52,12 @@ require 'mailsto/rspec'
53
52
  Verify emails are being sent with simple matchers.
54
53
 
55
54
  ```ruby
56
- Mailstro.deliver(
57
- :to => 'shanon@mailstroapp.com',
58
- :template_name => :welcome,
55
+ Mailstro.deliver(:welcome
56
+ :to => 'shanon@mailstroapp.com'
59
57
  )
60
58
 
61
- Mailstro.should have_delivered(
62
- :to => 'shanon@mailstroapp.com',
63
- :template_name => :welcome
59
+ Mailstro.should have_delivered(:welcome,
60
+ :to => 'shanon@mailstroapp.com'
64
61
  )
65
62
  ```
66
63
 
data/lib/mailstro.rb CHANGED
@@ -11,8 +11,8 @@ module Mailstro
11
11
  # Allows us to remove default behaviour during testing.
12
12
  class RealStrategy
13
13
  class << self
14
- def deliver(options)
15
- Delivery.new(options).deliver
14
+ def deliver(email_name, options)
15
+ Delivery.new(email_name, options).deliver
16
16
  end
17
17
  end
18
18
  end
@@ -28,11 +28,11 @@ module Mailstro
28
28
  yield(@configuration) && @configuration.validate!
29
29
  end
30
30
 
31
- def self.deliver(options)
32
- @strategy.deliver(options)
31
+ def self.deliver(email_name, options)
32
+ @strategy.deliver(email_name, options)
33
33
  end
34
34
 
35
- def self.has_delivered?(template_name)
36
- TestStrategy.has_delivered?(template_name)
35
+ def self.has_delivered?(email_name, options={})
36
+ TestStrategy.has_delivered?(email_name, options)
37
37
  end
38
38
  end
@@ -1,26 +1,25 @@
1
1
  module Mailstro
2
2
  class Delivery < Resource
3
- def initialize(options)
4
- @options = options
5
- end
3
+ attr_reader :email_name
6
4
 
7
- def contact_email
8
- @options.fetch(:to)
5
+ def initialize(email_name, options)
6
+ @email_name = email_name
7
+ @options = options
9
8
  end
10
9
 
11
- def template_name
12
- @options.fetch(:template_name)
10
+ def to
11
+ @options.fetch(:to)
13
12
  end
14
13
 
15
- def template_data
16
- @options.fetch(:template_data, nil)
14
+ def data
15
+ @options.fetch(:data, nil)
17
16
  end
18
17
 
19
18
  def deliver
20
19
  post("deliveries",
21
- :contact_email => contact_email,
22
- :template_name => template_name,
23
- :template_data => template_data
20
+ :to => to,
21
+ :email_name => email_name,
22
+ :data => data
24
23
  )
25
24
  end
26
25
  end
@@ -10,22 +10,15 @@ module Mailstro
10
10
  @@deliveries = []
11
11
  end
12
12
 
13
- def self.deliver(options)
14
- @@deliveries << Delivery.new(options)
13
+ def self.deliver(email_name, options)
14
+ @@deliveries << Delivery.new(email_name, options)
15
15
  end
16
16
 
17
- def self.has_delivered?(conditions)
17
+ def self.has_delivered?(email_name, conditions)
18
18
  @@deliveries.any? do |delivery|
19
- result = true
20
- if conditions.is_a?(Hash)
21
- if conditions[:template_name]
22
- result = result && delivery.template_name == conditions[:template_name]
23
- end
24
- if conditions[:to]
25
- result = result && delivery.contact_email == conditions[:to]
26
- end
27
- else
28
- result = delivery.template_name == conditions
19
+ result = delivery.email_name == email_name
20
+ if conditions[:to]
21
+ result = result && delivery.to == conditions[:to]
29
22
  end
30
23
  result
31
24
  end
@@ -1,3 +1,3 @@
1
1
  module Mailstro
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -2,8 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe 'posting a delivery', :integration do
4
4
  let(:contact_email) { "test@example.com" }
5
- let(:template_name) { :test }
6
- let(:template_data) { { :greeting => "Gday!" } }
5
+ let(:email_name) { :test }
6
+ let(:data) { { :greeting => "Gday!" } }
7
7
 
8
8
  before do
9
9
  Mailstro.configure do |config|
@@ -12,20 +12,19 @@ describe 'posting a delivery', :integration do
12
12
  end
13
13
 
14
14
  let(:expected_body) {{
15
- "api_key" => "lolapi",
16
- "contact_email" => "test@example.com",
17
- "template_name" => "test",
18
- "template_data" => { "greeting" => "Gday!" }
15
+ "api_key" => "lolapi",
16
+ "to" => "test@example.com",
17
+ "email_name" => "test",
18
+ "data" => { "greeting" => "Gday!" }
19
19
  }}
20
20
 
21
21
  it "succesfully submits a delivery to mailstro" do
22
22
  stub_request(:post, "https://api.mailstroapp.com/v1/deliveries").
23
23
  with(:body => expected_body).to_return(:status => 200, :body => fixture("response.json"))
24
24
 
25
- response = Mailstro.deliver(
26
- :to => contact_email,
27
- :template_name => template_name,
28
- :template_data => template_data
25
+ response = Mailstro.deliver(email_name,
26
+ :to => contact_email,
27
+ :data => data
29
28
  )
30
29
  response['success'].should == true
31
30
  end
@@ -35,10 +34,9 @@ describe 'posting a delivery', :integration do
35
34
  to_return(:status => 401)
36
35
 
37
36
  expect do
38
- Mailstro.deliver(
39
- :to => contact_email,
40
- :template_name => template_name,
41
- :template_data => template_data
37
+ Mailstro.deliver(email_name,
38
+ :to => contact_email,
39
+ :data => data
42
40
  )
43
41
  end.to raise_error(Mailstro::Error::AuthorisationError, "api_key not authorised")
44
42
  end
@@ -10,9 +10,8 @@ describe Mailstro::TestStrategy do
10
10
  it "doesn't send anything when enabled" do
11
11
  Mailstro::Delivery.should_not_receive(:deliver)
12
12
 
13
- Mailstro.deliver(
14
- :to => 'a@a.com',
15
- :template_name => :welcome
13
+ Mailstro.deliver(:welcome,
14
+ :to => 'a@a.com'
16
15
  )
17
16
  end
18
17
  end
@@ -20,9 +19,8 @@ describe Mailstro::TestStrategy do
20
19
  describe '.has_delivered?' do
21
20
  context "with a delivery" do
22
21
  before do
23
- Mailstro.deliver(
24
- :to => 'a@a.com',
25
- :template_name => :welcome
22
+ Mailstro.deliver(:welcome,
23
+ :to => 'a@a.com'
26
24
  )
27
25
  end
28
26
 
@@ -31,9 +29,8 @@ describe Mailstro::TestStrategy do
31
29
  end
32
30
 
33
31
  it 'matches contact email and template name' do
34
- Mailstro.should have_delivered(
35
- :to => 'a@a.com',
36
- :template_name => :welcome,
32
+ Mailstro.should have_delivered(:welcome,
33
+ :to => 'a@a.com'
37
34
  )
38
35
  end
39
36
 
@@ -42,9 +39,8 @@ describe Mailstro::TestStrategy do
42
39
  end
43
40
 
44
41
  it 'does not match an invalid contact email' do
45
- Mailstro.should_not have_delivered(
46
- :to => 'b@a.com',
47
- :template_name => :welcome,
42
+ Mailstro.should_not have_delivered(:welcome,
43
+ :to => 'b@a.com'
48
44
  )
49
45
  end
50
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailstro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-10-02 00:00:00.000000000 Z
13
+ date: 2013-10-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday