macaco 0.0.2 → 0.0.3

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ef247b290b179c9b35eb058c9067ee3e34ae9028
4
+ data.tar.gz: c508f2cc3d6a5cecb15ed37847b6ccaf0b3c7fb3
5
+ SHA512:
6
+ metadata.gz: 41cbd0c14ab5e61333d1bcb0a0ce740650f89da0e0892ed21067ad5954497d99e7d38e68a690e7e54e5f2d4f2bb04b7a3c21f9ee25bf7b98d0449a4b89121ae1
7
+ data.tar.gz: 9284d424e25eb6e2ad266df81017d9ba3217fdf71b7efb1bff1b669886c658a2cf9027b569f52565ee6572b3c1c6f12acf73b548eeea3798111bbd32d7d88bd9
data/.travis.yml CHANGED
@@ -4,8 +4,11 @@ rvm:
4
4
  - 1.9.2
5
5
  - 1.9.3
6
6
  - 2.0.0
7
+ - 2.1.0
7
8
  - jruby-19mode
8
- - rbx-19mode
9
+ - rbx
9
10
  env:
10
11
  global:
11
- secure: RRPan9WyIeNkwnDDHlmL+BgwSVP7dLcdUc7ZBQ4MF/XWH6dbkkTu5wDGxRnnI/Rjuwz1GKBpbV74La7X/3QrAQeQIUu5B/jdj2CgZvrTt2ngsbsPcLqLJXd6cCIUqBt125tkyPMDn3n/s1flloVvTLYRWZHwG0jOZiVy5rEdf9Q=
12
+ - secure: bKfiz20c9hES95IOSzQmolmV5Rplhe11XS/puPsTeYANuL0jda6xlEP+r7/wtztFueQDIGJzVDrJPNkAaQms5qOwTVursdx5W4H9FanNTX7GBaAiaR6YmbcysBJTByPO48ustEUQR2mxsOA5JTYXdYb7nQd6hzJujGqzf+WTe58=
13
+ - secure: C3a8krkzZK3tPlWNpduon0LCUAUaa2d3CA/aU15GV/yG/CH+fjjXeQhQNcQMN5Ahe8DFvVdZly5VZf5VnXh1k1mzebrqGurTgX6D483l+oc8ym6igiDnxtB5Q3VxjDjMsK1uLBltSXzOcdoGjyKm5AflqWNH5RXHY+7vAIWu9bs=
14
+ - secure: dDpqHaTNH7Fway0b0WcVHCuaedMemAv3HMt92xD7wIHYkgue/Selx1MVA9e9f+/+x+2EkzyziktniKBGX77TgpCLBCq5x1CWOTQX0HSOt+hDOgJrLx2Yklo0LKoFGkjDw0tbH9nrMe6tA//bbn9FmUuKO3h5/nV7JZm1bmOQX84=
data/Gemfile CHANGED
@@ -1,10 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
-
5
- group :test do
6
- gem 'minitest'
7
- gem 'webmock'
8
- gem 'vcr'
9
- gem 'rake'
10
- end
data/bin/bundler ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'bundler' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('macaco', 'bundler')
data/lib/macaco/api.rb CHANGED
@@ -4,7 +4,7 @@ module Macaco
4
4
  def self.post(args = {})
5
5
 
6
6
  request = request_instance(args)
7
- request.body = args[:data].to_json
7
+ request.body = args[:data]
8
8
 
9
9
  JSON.parse(http_response(request, args).body)
10
10
 
@@ -17,7 +17,7 @@ module Macaco
17
17
  end
18
18
 
19
19
  def self.request_instance(args)
20
- Net::HTTP::Post.new(args[:mail].api_path, initheader = { 'Content-Type' => 'application/json' })
20
+ Net::HTTP::Post.new(args[:mail].api_path, { 'Content-Type' => args[:mail].content_type })
21
21
  end
22
22
 
23
23
  def self.http_instance(args)
@@ -1,8 +1,8 @@
1
1
  module Macaco
2
2
  class Mandrill < Sender
3
3
 
4
- def api_key
5
- Macaco.config.api_key || ENV['MACACO_API_KEY']
4
+ def docs
5
+ 'https://mandrillapp.com/api/docs/messages.JSON.html#method-send'
6
6
  end
7
7
 
8
8
  def api_root
@@ -13,6 +13,10 @@ module Macaco
13
13
  '/api/1.0/messages/send.json'
14
14
  end
15
15
 
16
+ def content_type
17
+ 'application/json'
18
+ end
19
+
16
20
  def to_hash
17
21
  {
18
22
  message: {
@@ -27,7 +31,17 @@ module Macaco
27
31
 
28
32
  def send
29
33
  data = to_hash.merge!({ key: api_key })
30
- Macaco::Api.post({ mail: self, data: data })
34
+ Macaco::Api.post({ mail: self, data: convert_data_params(data) })
35
+ end
36
+
37
+ private
38
+
39
+ def convert_data_params(data)
40
+ data.to_json
41
+ end
42
+
43
+ def api_key
44
+ Macaco.config.api_key || ENV['MACACO_API_KEY']
31
45
  end
32
46
 
33
47
  end
@@ -0,0 +1,57 @@
1
+ module Macaco
2
+ class Sendgrid < Sender
3
+
4
+ def docs
5
+ 'http://sendgrid.com/docs/API_Reference/Web_API/mail.html'
6
+ end
7
+
8
+ def api_root
9
+ 'api.sendgrid.com'
10
+ end
11
+
12
+ def api_path
13
+ '/api/mail.send.json'
14
+ end
15
+
16
+ def content_type
17
+ 'application/x-www-form-urlencoded'
18
+ end
19
+
20
+ def to_hash
21
+ {
22
+ from: @from,
23
+ to: @to,
24
+ subject: @subject,
25
+ html: @body_html,
26
+ text: @body_text
27
+ }
28
+ end
29
+
30
+ def to(val = nil)
31
+ return @to unless val
32
+ @to << val
33
+ end
34
+
35
+ def send
36
+ data = to_hash.merge!({ api_key: api_key, api_user: api_user })
37
+ Macaco::Api.post({ mail: self, data: convert_data_params(data) })
38
+ end
39
+
40
+ private
41
+
42
+ def convert_data_params(data)
43
+ addr = Addressable::URI.new
44
+ addr.query_values = data
45
+ addr.query
46
+ end
47
+
48
+ def api_key
49
+ Macaco.config.api_key || ENV['MACACO_API_KEY']
50
+ end
51
+
52
+ def api_user
53
+ Macaco.config.api_user || ENV['MACACO_USER']
54
+ end
55
+
56
+ end
57
+ end
@@ -1,3 +1,3 @@
1
1
  module Macaco
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/macaco.rb CHANGED
@@ -6,6 +6,7 @@ require 'macaco/version'
6
6
  require 'macaco/api'
7
7
  require 'macaco/senders/sender'
8
8
  require 'macaco/senders/mandrill'
9
+ require 'macaco/senders/sendgrid'
9
10
 
10
11
  module Macaco
11
12
  class << self
@@ -18,10 +19,9 @@ module Macaco
18
19
  end
19
20
 
20
21
  class Configuration
21
- attr_accessor :api_key, :sender
22
+ attr_accessor :api_key, :api_user, :sender
22
23
 
23
24
  def initialize
24
- @api_key = ENV['MACACO_API_KEY']
25
25
  @sender = :mandrill
26
26
  end
27
27
  end
data/macaco.gemspec CHANGED
@@ -17,4 +17,12 @@ Gem::Specification.new do |gem|
17
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
+
21
+ gem.add_development_dependency 'minitest', '~> 0'
22
+ gem.add_development_dependency 'webmock', '~> 1.15'
23
+ gem.add_development_dependency 'vcr', '~> 2.9'
24
+ gem.add_development_dependency 'rake', '~> 10.1'
25
+
26
+ gem.add_runtime_dependency 'addressable', '~> 2.3'
27
+
20
28
  end
@@ -2,16 +2,28 @@ require 'spec_helper'
2
2
 
3
3
  describe Macaco::Mandrill do
4
4
 
5
+ before do
6
+ Macaco.configure do |config|
7
+ config.api_key = ENV['MANDRILL_API_KEY']
8
+ end
9
+ end
10
+
5
11
  let(:mail) do
6
12
  Macaco::Mandrill.new do
7
- to 'to@test.com'
8
- from 'from@test.com'
13
+ to 'james@jamesduncombe.com'
14
+ from 'james@jamesduncombe.com'
9
15
  subject 'Subject for my email'
10
16
  body_html '<h1>This is a header for the HTML version</h1>'
11
17
  body_text 'This is the Text version'
12
18
  end
13
19
  end
14
20
 
21
+ describe '#docs' do
22
+ it 'returns back the address for the documentation for the REAL API method' do
23
+ Macaco::Mandrill.new.docs.must_equal 'https://mandrillapp.com/api/docs/messages.JSON.html#method-send'
24
+ end
25
+ end
26
+
15
27
  describe '#api_root' do
16
28
  it { Macaco::Mandrill.new.api_root.must_equal 'mandrillapp.com' }
17
29
  end
@@ -33,7 +45,7 @@ describe Macaco::Mandrill do
33
45
 
34
46
  describe '#send' do
35
47
  subject do
36
- VCR.use_cassette('send') do
48
+ VCR.use_cassette('send_mandrill') do
37
49
  mail.send
38
50
  end
39
51
  end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe Macaco::Sendgrid do
4
+
5
+ before do
6
+ Macaco.configure do |config|
7
+ config.api_key = ENV['SENDGRID_API_KEY']
8
+ config.api_user = ENV['SENDGRID_USER']
9
+ end
10
+ end
11
+
12
+ let(:mail) do
13
+ Macaco::Sendgrid.new do
14
+ to 'james@jamesduncombe.com'
15
+ from 'james@jamesduncombe.com'
16
+ subject 'Subject for my email'
17
+ body_html '<h1>This is a header for the HTML version</h1>'
18
+ body_text 'This is the Text version'
19
+ end
20
+ end
21
+
22
+ describe '#docs' do
23
+ it 'returns back the address for the documentation for the REAL API method' do
24
+ Macaco::Sendgrid.new.docs.must_equal 'http://sendgrid.com/docs/API_Reference/Web_API/mail.html'
25
+ end
26
+ end
27
+
28
+ describe '#api_root' do
29
+ it { Macaco::Sendgrid.new.api_root.must_equal 'api.sendgrid.com' }
30
+ end
31
+
32
+ describe '#api_path' do
33
+ it { Macaco::Sendgrid.new.api_path.must_equal '/api/mail.send.json' }
34
+ end
35
+
36
+ describe '#to_hash' do
37
+ subject { mail.to_hash }
38
+ it { subject.must_be_kind_of Hash }
39
+ end
40
+
41
+ describe '#to_json' do
42
+ it 'converts the mandrill hash into a JSON string' do
43
+ mail.to_json.must_be_kind_of String
44
+ end
45
+ end
46
+
47
+ describe '#send' do
48
+ subject do
49
+ VCR.use_cassette('send_sendgrid') do
50
+ mail.send
51
+ end
52
+ end
53
+ it { subject.must_be_kind_of Hash }
54
+ it { subject['message'].must_equal 'success' }
55
+ end
56
+ end
data/spec/spec_helper.rb CHANGED
@@ -5,14 +5,9 @@ require 'minitest/autorun'
5
5
  require 'minitest/pride'
6
6
 
7
7
  require 'vcr'
8
-
9
8
  require 'macaco'
10
9
 
11
10
  VCR.configure do |c|
12
11
  c.cassette_library_dir = 'fixtures/vcr_cassettes'
13
12
  c.hook_into :webmock
14
13
  end
15
-
16
- Macaco.configure do |config|
17
- config.api_key = ENV['MANDRILL_API_KEY']
18
- end
metadata CHANGED
@@ -1,68 +1,141 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: macaco
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.0.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - James Duncombe
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-11-10 00:00:00.000000000 Z
13
- dependencies: []
11
+ date: 2014-04-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: webmock
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.15'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.15'
41
+ - !ruby/object:Gem::Dependency
42
+ name: vcr
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: addressable
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.3'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.3'
14
83
  description: Tiny gem to wrap Mandrill API's send method without other gem dependencies
15
84
  email:
16
85
  - james@jamesduncombe.com
17
86
  executables:
87
+ - bundler
18
88
  - rake
19
89
  extensions: []
20
90
  extra_rdoc_files: []
21
91
  files:
22
- - .gitignore
23
- - .travis.yml
92
+ - ".gitignore"
93
+ - ".travis.yml"
24
94
  - Gemfile
25
95
  - LICENSE.txt
26
96
  - README.md
27
97
  - Rakefile
98
+ - bin/bundler
28
99
  - bin/rake
29
100
  - lib/macaco.rb
30
101
  - lib/macaco/api.rb
31
102
  - lib/macaco/senders/mandrill.rb
32
103
  - lib/macaco/senders/sender.rb
104
+ - lib/macaco/senders/sendgrid.rb
33
105
  - lib/macaco/version.rb
34
106
  - macaco.gemspec
35
107
  - spec/lib/macaco/senders/mandrill_spec.rb
36
108
  - spec/lib/macaco/senders/sender_spec.rb
109
+ - spec/lib/macaco/senders/sendgrid_spec.rb
37
110
  - spec/lib/macaco_spec.rb
38
111
  - spec/spec_helper.rb
39
112
  homepage: https://github.com/jamesduncombe/macaco
40
113
  licenses:
41
114
  - MIT
115
+ metadata: {}
42
116
  post_install_message:
43
117
  rdoc_options: []
44
118
  require_paths:
45
119
  - lib
46
120
  required_ruby_version: !ruby/object:Gem::Requirement
47
- none: false
48
121
  requirements:
49
- - - ! '>='
122
+ - - ">="
50
123
  - !ruby/object:Gem::Version
51
124
  version: '0'
52
125
  required_rubygems_version: !ruby/object:Gem::Requirement
53
- none: false
54
126
  requirements:
55
- - - ! '>='
127
+ - - ">="
56
128
  - !ruby/object:Gem::Version
57
129
  version: '0'
58
130
  requirements: []
59
131
  rubyforge_project:
60
- rubygems_version: 1.8.25
132
+ rubygems_version: 2.2.2
61
133
  signing_key:
62
- specification_version: 3
134
+ specification_version: 4
63
135
  summary: Tiny wrapper around Mandrill API's send method
64
136
  test_files:
65
137
  - spec/lib/macaco/senders/mandrill_spec.rb
66
138
  - spec/lib/macaco/senders/sender_spec.rb
139
+ - spec/lib/macaco/senders/sendgrid_spec.rb
67
140
  - spec/lib/macaco_spec.rb
68
141
  - spec/spec_helper.rb