mailstro 0.0.10 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.md +15 -5
- data/lib/mailstro.rb +10 -9
- data/lib/mailstro/configuration.rb +9 -0
- data/lib/mailstro/error.rb +1 -0
- data/lib/mailstro/middleware/response/raise_error.rb +2 -0
- data/lib/mailstro/rspec.rb +0 -6
- data/lib/mailstro/version.rb +1 -1
- data/spec/integration/delivery_spec.rb +1 -0
- data/spec/spec_helper.rb +1 -1
- metadata +2 -2
data/Readme.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Mailstro Client for Ruby
|
2
2
|
|
3
|
-
|
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
|
|
data/lib/mailstro.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
require 'faraday'
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
5
|
-
require_relative
|
6
|
-
require_relative
|
7
|
-
require_relative
|
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
|
-
|
12
|
-
|
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 =
|
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
|
data/lib/mailstro/error.rb
CHANGED
data/lib/mailstro/rspec.rb
CHANGED
data/lib/mailstro/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -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::
|
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
|
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-
|
13
|
+
date: 2013-10-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday
|