mailstro 0.0.10 → 0.1.0

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
@@ -1,6 +1,6 @@
1
1
  # Mailstro Client for Ruby
2
2
 
3
- TODO: Write a gem description
3
+ A quick and easy way to send emails from your ruby application.
4
4
 
5
5
  ## Installation
6
6
 
@@ -21,19 +21,29 @@ TODO: Write a gem description
21
21
  In rails apps, put this code to a new file at `config/initializers/mailstro.rb`
22
22
 
23
23
  ```ruby
24
- require 'mailstro'
25
-
26
24
  Mailstro.configure do |config|
27
25
  config.api_key = "YOUR_API_KEY_HERE"
28
26
  end
29
27
  ```
30
28
 
29
+ By default, mailstro operates in test mode. This ensures accidental emails are not sent
30
+ in development or staging environments.
31
+
32
+ In rails apps, put this code to a new file at `config/environments/production.rb`
33
+
34
+ ```ruby
35
+ # Enable production mode, and start sending real emails.
36
+ Mailstro.configure do |config|
37
+ config.enabled = true
38
+ end
39
+ ```
40
+
31
41
  ## Usage
32
42
 
33
43
  Sending a basic email.
34
44
 
35
45
  ```ruby
36
- Mailstro.deliver(:welcome
46
+ Mailstro.deliver(:welcome,
37
47
  :to => 'shanon@mailstroapp.com',
38
48
  :data => {
39
49
  :coupon_code => 'THANKS01'
@@ -52,7 +62,7 @@ require 'mailsto/rspec'
52
62
  Verify emails are being sent with simple matchers.
53
63
 
54
64
  ```ruby
55
- Mailstro.deliver(:welcome
65
+ Mailstro.deliver(:welcome,
56
66
  :to => 'shanon@mailstroapp.com'
57
67
  )
58
68
 
@@ -1,15 +1,16 @@
1
1
  require 'faraday'
2
2
 
3
- require_relative "mailstro/version"
4
- require_relative "mailstro/configuration"
5
- require_relative "mailstro/error"
6
- require_relative "mailstro/resource"
7
- require_relative "mailstro/delivery"
3
+ require_relative 'mailstro/version'
4
+ require_relative 'mailstro/configuration'
5
+ require_relative 'mailstro/error'
6
+ require_relative 'mailstro/resource'
7
+ require_relative 'mailstro/delivery'
8
+ require_relative 'mailstro/test_strategy'
8
9
 
9
- module Mailstro
10
10
 
11
- # Allows us to remove default behaviour during testing.
12
- class RealStrategy
11
+ module Mailstro
12
+ # We want this disabled by default to avoid accidental emails.
13
+ class ProductionStrategy
13
14
  class << self
14
15
  def deliver(email_name, options)
15
16
  Delivery.new(email_name, options).deliver
@@ -21,7 +22,7 @@ module Mailstro
21
22
  attr_accessor :configuration, :strategy
22
23
  end
23
24
 
24
- @strategy = RealStrategy
25
+ @strategy = TestStrategy
25
26
  @configuration = Configuration.new
26
27
 
27
28
  def self.configure
@@ -2,11 +2,20 @@ module Mailstro
2
2
  class Configuration
3
3
  attr_accessor :api_endpoint
4
4
  attr_accessor :api_key
5
+ attr_accessor :enabled
5
6
 
6
7
  def initialize
7
8
  @api_endpoint = 'https://api.mailstroapp.com/v1'
8
9
  end
9
10
 
11
+ def enabled=(value)
12
+ if value
13
+ Mailstro.strategy = ProductionStrategy
14
+ else
15
+ Mailstro.strategy = TestStrategy
16
+ end
17
+ end
18
+
10
19
  def validate!
11
20
  raise Error::ConfigurationError, "api_key not provided" if api_key.nil?
12
21
  end
@@ -3,5 +3,6 @@ module Mailstro
3
3
  class ConfigurationError < StandardError; end
4
4
  class AuthorisationError < Faraday::Error::ClientError; end
5
5
  class ValidationError < StandardError; end
6
+ class MailstroError < StandardError; end
6
7
  end
7
8
  end
@@ -8,6 +8,8 @@ module Mailstro
8
8
  raise Error::AuthorisationError.new("api_key not authorised", env)
9
9
  when 422
10
10
  raise Error::ValidationError.new(env[:body][:errors])
11
+ when 500
12
+ raise Error::MailstroError.new(env[:body])
11
13
  else
12
14
  super
13
15
  end
@@ -1,10 +1,4 @@
1
- require 'mailstro/test_strategy'
2
-
3
1
  RSpec.configure do |config|
4
- config.before(:suite) do
5
- Mailstro::TestStrategy.enable
6
- end
7
-
8
2
  config.after(:each) do
9
3
  Mailstro::TestStrategy.clear
10
4
  end
@@ -1,3 +1,3 @@
1
1
  module Mailstro
2
- VERSION = "0.0.10"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -8,6 +8,7 @@ describe 'posting a delivery', :integration do
8
8
  before do
9
9
  Mailstro.configure do |config|
10
10
  config.api_key = 'lolapi'
11
+ config.enabled = true
11
12
  end
12
13
  end
13
14
 
@@ -8,7 +8,7 @@ Dir[SPEC_PATH.join("support/**/*.rb")].each { |f| require f }
8
8
  RSpec.configure do |config|
9
9
  config.after(:each) do
10
10
  Mailstro::TestStrategy.clear
11
- Mailstro.strategy = Mailstro::RealStrategy
11
+ Mailstro.strategy = Mailstro::ProductionStrategy
12
12
  end
13
13
 
14
14
  config.order = "random"
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.10
4
+ version: 0.1.0
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-05 00:00:00.000000000 Z
13
+ date: 2013-10-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday