mailercity 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/Gemfile +2 -0
- data/LICENSE +22 -0
- data/README.md +37 -0
- data/Rakefile +7 -0
- data/lib/mailercity.rb +68 -0
- data/lib/mailercity/errors/authentication_error.rb +4 -0
- data/lib/mailercity/helper.rb +14 -0
- data/lib/mailercity/version.rb +3 -0
- data/mailercity.gemspec +21 -0
- data/spec/mailercity_spec.rb +34 -0
- data/spec/spec_helper.rb +18 -0
- metadata +109 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.9.3@mailercity
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Rob Forman
|
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/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Mailercity
|
2
|
+
|
3
|
+
Ruby bindings for Mailercity API
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'mailercity'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install mailercity
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Use this:
|
22
|
+
```ruby
|
23
|
+
Mailercity::UserMailer.welcome_email(:user_email => "rob@robforman.com").deliver
|
24
|
+
```
|
25
|
+
|
26
|
+
In order to send to the below mail in Mailercity:
|
27
|
+
```ruby
|
28
|
+
UserMailer.welcome_email(:user_email => "rob@robforman.com").deliver
|
29
|
+
```
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
1. Fork it
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/mailercity.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "mailercity/helper"
|
3
|
+
require "mailercity/version"
|
4
|
+
require 'mailercity/errors/authentication_error'
|
5
|
+
|
6
|
+
module Mailercity
|
7
|
+
@@api_base = 'https://mailercity.onthecity.org'
|
8
|
+
@@api_key = nil
|
9
|
+
|
10
|
+
def self.api_base=(api_base)
|
11
|
+
@@api_base = api_base
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.api_base
|
15
|
+
@@api_base
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.api_url(url='')
|
19
|
+
@@api_base + url
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.api_key=(api_key)
|
23
|
+
@@api_key = api_key
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.api_key
|
27
|
+
@@api_key
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.request(path, params)
|
31
|
+
raise AuthenticationError.new('No API key provided. (HINT: set your API key using "Mailercity.api_key = <API-KEY>".') unless api_key
|
32
|
+
response = Faraday.post(api_url(path), params, "X-Api-Key" => Mailercity.api_key)
|
33
|
+
# TODO: CATCH ALL EXCEPTIONS (like URI::InvalidURIError) AND RAISE MY OWN ERROR
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.const_missing(const_name)
|
37
|
+
new_class = Class.new(super_class=Message)
|
38
|
+
|
39
|
+
# Non-obvious: we assign it to a const in order to name.
|
40
|
+
const_set(const_name, new_class)
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
class Message
|
45
|
+
include Mailercity::Helper
|
46
|
+
attr_reader :template, :params
|
47
|
+
|
48
|
+
def initialize(args)
|
49
|
+
@template = args.fetch(:template)
|
50
|
+
@params = args.fetch(:params)
|
51
|
+
end
|
52
|
+
|
53
|
+
def mailer_name
|
54
|
+
underscore self.class.name.split(/::/).last
|
55
|
+
end
|
56
|
+
|
57
|
+
def deliver
|
58
|
+
response = Mailercity.request("/#{mailer_name}/#{template}", params)
|
59
|
+
response.status == 200
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def self.method_missing(method_name, args, &block)
|
65
|
+
new(template: method_name, params: args)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Mailercity
|
2
|
+
module Helper
|
3
|
+
# From activesupport/lib/active_support/inflector/methods.rb, line 77
|
4
|
+
def underscore(camel_cased_word)
|
5
|
+
word = camel_cased_word.to_s.dup
|
6
|
+
word.gsub!(/::/, '/')
|
7
|
+
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
|
8
|
+
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
9
|
+
word.tr!("-", "_")
|
10
|
+
word.downcase!
|
11
|
+
word
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/mailercity.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/mailercity/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Rob Forman"]
|
6
|
+
gem.email = ["rob@robforman.com"]
|
7
|
+
gem.description = %q{Ruby bindings for Mailercity API}
|
8
|
+
gem.summary = %q{Mailercity is a central email repository and sending service.}
|
9
|
+
gem.homepage = "https://github.com/robforman/mailercity"
|
10
|
+
|
11
|
+
gem.add_dependency('faraday')
|
12
|
+
gem.add_development_dependency('rake')
|
13
|
+
gem.add_development_dependency('webmock')
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($\)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.name = "mailercity"
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
gem.version = Mailercity::VERSION
|
21
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require_relative "../lib/mailercity"
|
3
|
+
|
4
|
+
Mailercity.api_base = "http://testhost"
|
5
|
+
Mailercity.api_key = "testkey"
|
6
|
+
|
7
|
+
describe Mailercity do
|
8
|
+
def stub_post(url, params, options={})
|
9
|
+
status = options.fetch(:status, 200)
|
10
|
+
api_key = options.fetch(:api_key, Mailercity.api_key)
|
11
|
+
stub_request(:post, url).with(:body => params, :headers => {'X-Api-Key' => api_key}).to_return(:status => status, :body => "", :headers => {})
|
12
|
+
end
|
13
|
+
|
14
|
+
it "can create dynamic mailer classes and template methods while passing appropriate parameters" do
|
15
|
+
mail = Mailercity::MyTestMailer.my_test_template(:user_email => "rob@robforman.com")
|
16
|
+
mail.should be_kind_of Mailercity::Message
|
17
|
+
end
|
18
|
+
|
19
|
+
describe ".deliver" do
|
20
|
+
context "without http error" do
|
21
|
+
it "should post and return true" do
|
22
|
+
stub = stub_post("http://testhost/my_test_mailer/my_test_template", {"user_email"=>"rob@robforman.com"})
|
23
|
+
Mailercity::MyTestMailer.my_test_template(:user_email => "rob@robforman.com").deliver.should == true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "with http error" do
|
28
|
+
it "should fail to post and return false" do
|
29
|
+
stub = stub_post("http://testhost/my_test_mailer/my_test_template", {"user_email"=>"rob@robforman.com"}, :status => 403)
|
30
|
+
Mailercity::MyTestMailer.my_test_template(:user_email => "rob@robforman.com").deliver.should == false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'webmock/rspec'
|
2
|
+
|
3
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
4
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
5
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
6
|
+
# loaded once.
|
7
|
+
#
|
8
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
|
13
|
+
# Run specs in random order to surface order dependencies. If you find an
|
14
|
+
# order dependency and want to debug it, you can fix the order by providing
|
15
|
+
# the seed, which is printed after each run.
|
16
|
+
# --seed 1234
|
17
|
+
config.order = 'random'
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mailercity
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Rob Forman
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: webmock
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Ruby bindings for Mailercity API
|
63
|
+
email:
|
64
|
+
- rob@robforman.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- .rspec
|
71
|
+
- .rvmrc
|
72
|
+
- Gemfile
|
73
|
+
- LICENSE
|
74
|
+
- README.md
|
75
|
+
- Rakefile
|
76
|
+
- lib/mailercity.rb
|
77
|
+
- lib/mailercity/errors/authentication_error.rb
|
78
|
+
- lib/mailercity/helper.rb
|
79
|
+
- lib/mailercity/version.rb
|
80
|
+
- mailercity.gemspec
|
81
|
+
- spec/mailercity_spec.rb
|
82
|
+
- spec/spec_helper.rb
|
83
|
+
homepage: https://github.com/robforman/mailercity
|
84
|
+
licenses: []
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 1.8.24
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: Mailercity is a central email repository and sending service.
|
107
|
+
test_files:
|
108
|
+
- spec/mailercity_spec.rb
|
109
|
+
- spec/spec_helper.rb
|