macaco 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1078ceb7dcd54467dbbd9273ab210fd1c1ac8f12
4
- data.tar.gz: 5430c892dafa8b343f999f581605cf0708355ac6
3
+ metadata.gz: 6c311cce7eb6b749472dc6545918ec37cd9b0f4a
4
+ data.tar.gz: fd41959ac47959eebe4511f602f7d9ddeba47eff
5
5
  SHA512:
6
- metadata.gz: 1af44dd2a4569cc3d21883ebad45aab3377bd44b73762c1517f07bce44e1643e9d5926069de27687b60606acd928e8b5c1524e6e9567b9843a008cfa150bb9b1
7
- data.tar.gz: 134a25373c4dd29a5f11f6063e2f8f5fb0c3d624ec14cbf11be1bab03b60c68f550ba2e6cbe9d590d639dfcf03319ffd1fa3b16235208ae87bb5f7e7a9ab2f28
6
+ metadata.gz: 807ada9767d78334929d61824d3256e442406ea682867507b358750169d2a3e3cd8bff1b98110514580b84320cfcee64636d090f3e0241379b4b17a4e913a48e
7
+ data.tar.gz: 050d3a949f4c66deb632cab47e7c6cd75233bd29db41665fa59dd30bc0790f01f79a1fed32ee9c7e1377a2d29bf41aefcf72bf87b4f86b97c4576adb6d9c8986
data/.gitignore CHANGED
@@ -19,3 +19,4 @@ tmp
19
19
  .ruby-version
20
20
  .ruby-gemset
21
21
  fixtures/vcr_cassettes/*
22
+ bin/
data/.travis.yml CHANGED
@@ -1,14 +1,18 @@
1
1
  language: ruby
2
+
2
3
  cache: bundler
4
+
3
5
  rvm:
4
- - 1.9.2
5
- - 1.9.3
6
- - 2.0.0
7
- - 2.1.0
8
- - jruby-19mode
9
- - rbx
6
+ - 1.9.3
7
+ - 2.1
8
+ - 2.2
9
+ - 2.3.0
10
+ - jruby-19mode
11
+
12
+ before_install:
13
+ - gem install bundler -v 1.11.2
14
+
10
15
  env:
11
16
  global:
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=
17
+ - secure: er1Lqs3NDljT6tTinixr2pHonlCP8G33dW1INaEQwoTFRR9BqRqsfci6LVF9yJH+vtrK1d6Pf+rmtq9Qf8M+PqHmDe5YPhF6qRsrVAcnQt27sYP6c+XPB0v3IY9Nokl8mR+CysLgv/mPwEUEdoMymgpdiTKcA+c3ZOUaoKVk+Is=
18
+ - secure: pHFAESEdswQm3Ser9ex+gmdRTz0UBEj3+57lzi3lQyZu2cHoV3kEirZjwEdjJUzXcMxV00I2i87ULnO+IuDPvbMvmvncJtseMHQ2WeX17tvWTe5TiEFxLE4IqwzTiHbuFFqAAO6gi+rbNa3St09zAf/7FPDP9aY4+5JSqW8hK/s=
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Macaco
2
- [![Build Status](https://travis-ci.org/jamesduncombe/macaco.png?branch=master)](https://travis-ci.org/jamesduncombe/macaco)
2
+ [![Build Status](https://travis-ci.org/jamesduncombe/macaco.svg?branch=master)](https://travis-ci.org/jamesduncombe/macaco)
3
3
 
4
- Tiny wrapper around (for now) [Mandrill API's send method](https://mandrillapp.com/api/docs/messages.JSON.html#method=send). Later to be expanded to handle Sendgrid's send method too.
4
+ Tiny wrapper around [Sendgrid](https://sendgrid.com/docs/API_Reference/Web_API/mail.html#-send) and [Mandrill API's send methods](https://mandrillapp.com/api/docs/messages.JSON.html#method=send).
5
5
 
6
6
  ## Installation
7
7
 
@@ -19,24 +19,19 @@ Or install it yourself as:
19
19
 
20
20
  ## Usage
21
21
 
22
- By default Macaco tries to find your mail API key with the `MACACO_API_KEY`
23
- environment variable.
24
-
25
- However, you can configure Macaco to use a different key by passing a block to the
26
- configure method. Here I've used a different environment variable:
22
+ You can configure Macaco to use your API key by passing a block to the
23
+ configure method. Here I've used one for Sendgrid:
27
24
 
28
25
  ```ruby
29
26
  Macaco.configure do |config|
30
- config.api_key = ENV['MANDRILL_API_KEY']
27
+ config.api_key = ENV['SENDGRID_API_KEY']
31
28
  end
32
29
  ```
33
30
 
34
- At the moment we just have the [send message](https://mandrillapp.com/api/docs/messages.JSON.html#method=send) method. Use it like this:
35
-
36
31
  First create a new mail object:
37
32
 
38
33
  ```ruby
39
- mail = Macaco::Mandrill.new do
34
+ mail = Macaco::Sendgrid.new do
40
35
  to 'to@test.com'
41
36
  from 'from@test.com'
42
37
  subject 'This is my subject'
@@ -54,8 +49,7 @@ mail.send
54
49
  ## Todo
55
50
 
56
51
  - Add further reflection methods to be able to inspect the mail object
57
- - Add support for Sendgrid's send method
58
-
52
+ - Add support for other API's send methods
59
53
 
60
54
  ## Contributing
61
55
 
data/lib/macaco/api.rb CHANGED
@@ -2,12 +2,10 @@ module Macaco
2
2
  class Api
3
3
 
4
4
  def self.post(args = {})
5
-
6
5
  request = request_instance(args)
7
6
  request.body = args[:data]
8
7
 
9
8
  JSON.parse(http_response(request, args).body)
10
-
11
9
  end
12
10
 
13
11
  private
@@ -17,7 +15,10 @@ module Macaco
17
15
  end
18
16
 
19
17
  def self.request_instance(args)
20
- Net::HTTP::Post.new(args[:mail].api_path, { 'Content-Type' => args[:mail].content_type })
18
+ headers = {
19
+ 'Content-Type' => args[:mail].content_type
20
+ }.merge(args.fetch(:headers) { Hash.new })
21
+ Net::HTTP::Post.new(args[:mail].api_path, headers)
21
22
  end
22
23
 
23
24
  def self.http_instance(args)
@@ -29,6 +29,11 @@ module Macaco
29
29
  }
30
30
  end
31
31
 
32
+ def to(val = nil)
33
+ return @to unless val
34
+ @to << { email: val }
35
+ end
36
+
32
37
  def send
33
38
  data = to_hash.merge!({ key: api_key })
34
39
  Macaco::Api.post({ mail: self, data: convert_data_params(data) })
@@ -30,7 +30,7 @@ module Macaco
30
30
 
31
31
  def to(val = nil)
32
32
  return @to unless val
33
- @to << { email: val }
33
+ @to << val
34
34
  end
35
35
 
36
36
  def from(val = nil)
@@ -2,7 +2,7 @@ module Macaco
2
2
  class Sendgrid < Sender
3
3
 
4
4
  def docs
5
- 'http://sendgrid.com/docs/API_Reference/Web_API/mail.html'
5
+ 'https://sendgrid.com/docs/API_Reference/Web_API/mail.html#-send'
6
6
  end
7
7
 
8
8
  def api_root
@@ -27,30 +27,23 @@ module Macaco
27
27
  }
28
28
  end
29
29
 
30
- def to(val = nil)
31
- return @to unless val
32
- @to << val
33
- end
34
-
35
30
  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) })
31
+ data = to_hash
32
+ Macaco::Api.post({
33
+ mail: self,
34
+ data: convert_data_params(data),
35
+ headers: { "Authorization" => "Bearer #{api_key}" }
36
+ })
38
37
  end
39
38
 
40
39
  private
41
40
 
42
41
  def convert_data_params(data)
43
- addr = Addressable::URI.new
44
- addr.query_values = data
45
- addr.query
42
+ URI.encode_www_form(data)
46
43
  end
47
44
 
48
45
  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']
46
+ Macaco.config.api_key || ENV['SENDGRID_API_KEY']
54
47
  end
55
48
 
56
49
  end
@@ -1,3 +1,3 @@
1
1
  module Macaco
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/macaco.rb CHANGED
@@ -19,10 +19,6 @@ module Macaco
19
19
  end
20
20
 
21
21
  class Configuration
22
- attr_accessor :api_key, :api_user, :sender
23
-
24
- def initialize
25
- @sender = :mandrill
26
- end
22
+ attr_accessor :api_key
27
23
  end
28
24
  end
data/macaco.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |gem|
8
8
  gem.version = Macaco::VERSION
9
9
  gem.authors = ["James Duncombe"]
10
10
  gem.email = ["james@jamesduncombe.com"]
11
- gem.summary = %q{Tiny wrapper around Mandrill API's send method}
12
- gem.description = %q{Tiny gem to wrap Mandrill API's send method without other gem dependencies}
11
+ gem.summary = %q{When all you want to do is send email}
12
+ gem.description = %q{Tiny gem to send email using popular email providers}
13
13
  gem.homepage = "https://github.com/jamesduncombe/macaco"
14
14
  gem.license = 'MIT'
15
15
 
@@ -19,10 +19,8 @@ Gem::Specification.new do |gem|
19
19
  gem.require_paths = ["lib"]
20
20
 
21
21
  gem.add_development_dependency 'minitest', '~> 5.0'
22
- gem.add_development_dependency 'webmock', '~> 1.15'
23
- gem.add_development_dependency 'vcr', '~> 2.9'
22
+ gem.add_development_dependency 'webmock', '~> 0'
23
+ gem.add_development_dependency 'vcr', '~> 3.0'
24
24
  gem.add_development_dependency 'rake', '~> 10.1'
25
25
 
26
- gem.add_runtime_dependency 'addressable', '~> 2.3'
27
-
28
26
  end
@@ -21,7 +21,7 @@ describe Macaco::Sender do
21
21
 
22
22
  describe '#to' do
23
23
  it 'sets the recipient if theres a string provided' do
24
- mail.to.must_equal [ { email: 'to@test.com' } ]
24
+ mail.to.must_equal [ 'to@test.com' ]
25
25
  end
26
26
  end
27
27
 
@@ -52,5 +52,5 @@ describe Macaco::Sender do
52
52
  n.body_text.must_equal 'This is a test'
53
53
  end
54
54
  end
55
-
55
+
56
56
  end
@@ -5,7 +5,6 @@ describe Macaco::Sendgrid do
5
5
  before do
6
6
  Macaco.configure do |config|
7
7
  config.api_key = ENV['SENDGRID_API_KEY']
8
- config.api_user = ENV['SENDGRID_USER']
9
8
  end
10
9
  end
11
10
 
@@ -21,7 +20,7 @@ describe Macaco::Sendgrid do
21
20
 
22
21
  describe '#docs' do
23
22
  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'
23
+ Macaco::Sendgrid.new.docs.must_equal 'https://sendgrid.com/docs/API_Reference/Web_API/mail.html#-send'
25
24
  end
26
25
  end
27
26
 
@@ -5,9 +5,9 @@ describe Macaco do
5
5
  describe '#configure' do
6
6
  it 'configures the gem' do
7
7
  Macaco.configure do |config|
8
- config.api_key = 'dfsdf'
8
+ config.api_key = 'YOUR_API_KEY'
9
9
  end
10
- Macaco.config.api_key.must_match 'dfsdf'
10
+ Macaco.config.api_key.must_match 'YOUR_API_KEY'
11
11
  end
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: macaco
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Duncombe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-02 00:00:00.000000000 Z
11
+ date: 2016-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.15'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.15'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: vcr
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.9'
47
+ version: '3.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2.9'
54
+ version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,26 +66,10 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
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'
83
- description: Tiny gem to wrap Mandrill API's send method without other gem dependencies
69
+ description: Tiny gem to send email using popular email providers
84
70
  email:
85
71
  - james@jamesduncombe.com
86
- executables:
87
- - bundler
88
- - rake
72
+ executables: []
89
73
  extensions: []
90
74
  extra_rdoc_files: []
91
75
  files:
@@ -95,8 +79,6 @@ files:
95
79
  - LICENSE.txt
96
80
  - README.md
97
81
  - Rakefile
98
- - bin/bundler
99
- - bin/rake
100
82
  - lib/macaco.rb
101
83
  - lib/macaco/api.rb
102
84
  - lib/macaco/senders/mandrill.rb
@@ -129,10 +111,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
111
  version: '0'
130
112
  requirements: []
131
113
  rubyforge_project:
132
- rubygems_version: 2.2.2
114
+ rubygems_version: 2.4.8
133
115
  signing_key:
134
116
  specification_version: 4
135
- summary: Tiny wrapper around Mandrill API's send method
117
+ summary: When all you want to do is send email
136
118
  test_files:
137
119
  - spec/lib/macaco/senders/mandrill_spec.rb
138
120
  - spec/lib/macaco/senders/sender_spec.rb
data/bin/bundler DELETED
@@ -1,16 +0,0 @@
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/bin/rake DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'rake' 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', 'rake')