macaco 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +63 -0
- data/Rakefile +2 -0
- data/lib/macaco/messages.rb +22 -0
- data/lib/macaco/version.rb +3 -0
- data/lib/macaco.rb +27 -0
- data/macaco.gemspec +19 -0
- data/spec/lib/macaco/messages_spec.rb +28 -0
- data/spec/lib/macaco_spec.rb +13 -0
- data/spec/spec_helper.rb +7 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cfd7cbd8435ea89f75b2cd6cadfdcad5b36b3a6d
|
4
|
+
data.tar.gz: 55f493eb3e10f825f35fdfbb588926dd3165c13c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 535d25ad21a393b6568396a329909026a9cb3f244f1e8f688c9391d5cfa1701b8bc00bf31cc8a8c5fc299faac086e817f0e1eb1dceb836601a423c2f8770bb06
|
7
|
+
data.tar.gz: f1eaf76c759b8f9883c2cc9a27e72eb5d32457bcb75ba32b7dbd1dbaabca86565147a2997c2148511c3ded7ea0dc6e6a84ae4d3b04ede20e6ae910a9c1967036
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 James Duncombe
|
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,63 @@
|
|
1
|
+
# Macaco
|
2
|
+
|
3
|
+
Tiny wrapper around [Mandrill's API](https://mandrillapp.com/api/docs/)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'macaco'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install macaco
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
You can configure Macaco to use an API by passing a block to the
|
22
|
+
configure method. Here I've used an environment variable:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
Macaco.configure do |config|
|
26
|
+
config.api_key = ENV['MANDRILL_API_KEY']
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
At the moment we just have the [send message](https://mandrillapp.com/api/docs/messages.JSON.html#method=send) method. Use it like this:
|
31
|
+
|
32
|
+
Form your data hash:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
data = {
|
36
|
+
message: {
|
37
|
+
text: 'Boom boom',
|
38
|
+
html: '''
|
39
|
+
<h1>My email title</h1>
|
40
|
+
<p>My email body</p>
|
41
|
+
<small>Monkey Corp Ltd</small>
|
42
|
+
''',
|
43
|
+
subject: 'Test subject',
|
44
|
+
from_email: 'james@jamesduncombe.com',
|
45
|
+
to: [{ email: 'james@jamesduncombe.com' }]
|
46
|
+
}
|
47
|
+
}
|
48
|
+
```
|
49
|
+
|
50
|
+
Then call the method:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
Macaco::Messages.send_message(data)
|
54
|
+
```
|
55
|
+
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
|
59
|
+
1. Fork it
|
60
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
61
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
62
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
63
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Macaco
|
2
|
+
class Messages
|
3
|
+
|
4
|
+
def self.send_message(data)
|
5
|
+
|
6
|
+
data.merge!({ key: Macaco.config.api_key })
|
7
|
+
|
8
|
+
request = Net::HTTP::Post.new('/api/1.0/messages/send.json',
|
9
|
+
initheader = { 'Content-Type'=> 'application/json' })
|
10
|
+
request.body = data.to_json
|
11
|
+
http = Net::HTTP.new(Macaco.config.api_root, Macaco.config.api_port)
|
12
|
+
http.use_ssl = true
|
13
|
+
|
14
|
+
response = http.start do |http|
|
15
|
+
http.request(request)
|
16
|
+
end
|
17
|
+
|
18
|
+
JSON.parse(response.body)
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/macaco.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
require 'macaco/version'
|
6
|
+
require 'macaco/messages'
|
7
|
+
|
8
|
+
module Macaco
|
9
|
+
class << self
|
10
|
+
attr_accessor :config
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.configure
|
14
|
+
self.config ||= Configuration.new
|
15
|
+
yield(config)
|
16
|
+
end
|
17
|
+
|
18
|
+
class Configuration
|
19
|
+
attr_accessor :api_key, :api_root, :api_port
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
@api_key = ENV['MANDRILL_API_KEY']
|
23
|
+
@api_root = 'mandrillapp.com'
|
24
|
+
@api_port = 443
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/macaco.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'macaco/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "macaco"
|
8
|
+
gem.version = Macaco::VERSION
|
9
|
+
gem.authors = ["James Duncombe"]
|
10
|
+
gem.email = ["james@jamesduncombe.com"]
|
11
|
+
gem.summary = %q{A tiny gem to handle Mandrill's API}
|
12
|
+
gem.description = %q{Tiny gem to handle Mandrill's API without other gem dependencies}
|
13
|
+
gem.homepage = "https://github.com/jamesduncombe/macaco"
|
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.require_paths = ["lib"]
|
19
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Macaco::Messages do
|
4
|
+
|
5
|
+
describe '#send_message' do
|
6
|
+
subject do
|
7
|
+
data = {
|
8
|
+
message: {
|
9
|
+
text: 'Boom boom',
|
10
|
+
html: '''
|
11
|
+
<h1>My email title</h1>
|
12
|
+
<p>My email body</p>
|
13
|
+
<small>Monkey Corp Ltd</small>
|
14
|
+
''',
|
15
|
+
subject: 'Test subject',
|
16
|
+
from_email: 'james@jamesduncombe.com',
|
17
|
+
to: [{ email: 'james@jamesduncombe.com' }]
|
18
|
+
}
|
19
|
+
}
|
20
|
+
Macaco.configure do |config|
|
21
|
+
config.api_key = ENV['MANDRILL_API_KEY']
|
22
|
+
end
|
23
|
+
Macaco::Messages.send_message(data)
|
24
|
+
end
|
25
|
+
it { subject.must_be_kind_of Array }
|
26
|
+
it { subject.first['status'].must_equal 'sent' }
|
27
|
+
end
|
28
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: macaco
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Duncombe
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-27 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Tiny gem to handle Mandrill's API without other gem dependencies
|
14
|
+
email:
|
15
|
+
- james@jamesduncombe.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- .gitignore
|
21
|
+
- Gemfile
|
22
|
+
- LICENSE.txt
|
23
|
+
- README.md
|
24
|
+
- Rakefile
|
25
|
+
- lib/macaco.rb
|
26
|
+
- lib/macaco/messages.rb
|
27
|
+
- lib/macaco/version.rb
|
28
|
+
- macaco.gemspec
|
29
|
+
- spec/lib/macaco/messages_spec.rb
|
30
|
+
- spec/lib/macaco_spec.rb
|
31
|
+
- spec/spec_helper.rb
|
32
|
+
homepage: https://github.com/jamesduncombe/macaco
|
33
|
+
licenses: []
|
34
|
+
metadata: {}
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 2.0.3
|
52
|
+
signing_key:
|
53
|
+
specification_version: 4
|
54
|
+
summary: A tiny gem to handle Mandrill's API
|
55
|
+
test_files:
|
56
|
+
- spec/lib/macaco/messages_spec.rb
|
57
|
+
- spec/lib/macaco_spec.rb
|
58
|
+
- spec/spec_helper.rb
|