mailgun 0.0.3 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,78 @@
1
+ require "spec_helper"
2
+
3
+ describe Mailgun::Route do
4
+
5
+ before :each do
6
+ @mailgun = Mailgun({:api_key => "api-key"}) # used to get the default values
7
+ @sample_route_id = "a45cd"
8
+ end
9
+
10
+ describe "list routes" do
11
+ before :each do
12
+ sample_response = "{\"items\": []}"
13
+ RestClient.should_receive(:get)
14
+ .with("#{@mailgun.routes.send(:route_url)}",:limit=>100, :skip=>0)
15
+ .and_return(sample_response)
16
+ end
17
+
18
+ it "should make a GET request with the right params" do
19
+ @mailgun.routes.list
20
+ end
21
+
22
+ it "should respond with an Array" do
23
+ @mailgun.routes.list.should be_kind_of(Array)
24
+ end
25
+ end
26
+
27
+ describe "get route" do
28
+ it "should make a GET request with the right params" do
29
+ RestClient.should_receive(:get)
30
+ .with("#{@mailgun.routes.send(:route_url, @sample_route_id)}", {})
31
+ .and_return("{\"route\": {\"id\": \"#{@sample_route_id}\" }}")
32
+ @mailgun.routes.find @sample_route_id
33
+ end
34
+ end
35
+
36
+ describe "create route" do
37
+ it "should make a POST request with the right params" do
38
+ options = {}
39
+
40
+ options[:description] = "test_route"
41
+ options[:priority] = 1
42
+ options[:expression] = [:match_recipient, "sample.mailgun.org"]
43
+ options[:action] = [[:forward, "http://test-site.com"], [:stop]]
44
+
45
+ RestClient.should_receive(:post)
46
+ .with(@mailgun.routes.send(:route_url), instance_of(Multimap))
47
+ .and_return("{\"route\": {\"id\": \"@sample_route_id\"}}")
48
+
49
+ @mailgun.routes.create(
50
+ options[:description],
51
+ options[:priority],
52
+ options[:expression],
53
+ options[:action],
54
+ )
55
+ end
56
+ end
57
+
58
+ describe "update route" do
59
+ it "should make a PUT request with the right params" do
60
+ options = {}
61
+ options[:description] = "test_route"
62
+
63
+ RestClient.should_receive(:put)
64
+ .with("#{@mailgun.routes.send(:route_url, @sample_route_id)}", instance_of(Multimap))
65
+ .and_return("{\"id\": \"#{@sample_route_id}\"}")
66
+ @mailgun.routes.update @sample_route_id, options
67
+ end
68
+ end
69
+
70
+ describe "delete route" do
71
+ it "should make a DELETE request with the right params" do
72
+ RestClient.should_receive(:delete)
73
+ .with("#{@mailgun.routes.send(:route_url, @sample_route_id)}", {})
74
+ .and_return("{\"id\": \"#{@sample_route_id}\"}")
75
+ @mailgun.routes.destroy @sample_route_id
76
+ end
77
+ end
78
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  $:.unshift File.expand_path("../lib", File.dirname(__FILE__))
2
+ require 'simplecov'
3
+ SimpleCov.start
2
4
 
3
5
  require "rspec"
4
6
  require "mailgun"
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mailgun::Unsubscribe do
4
+
5
+ before :each do
6
+ @mailgun = Mailgun({:api_key => "api-key"}) # used to get the default values
7
+
8
+ @unsubscribe_options = {
9
+ :email => "test@sample.mailgun.org",
10
+ :name => "test",
11
+ :domain => "sample.mailgun.org",
12
+ :tag => 'tag1'
13
+ }
14
+ end
15
+
16
+ describe "list unsubscribes" do
17
+ it "should make a GET request with the right params" do
18
+ sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.mailgun.org\" } ]}"
19
+ RestClient.should_receive(:get).with("#{@mailgun.unsubscribes.send(:unsubscribe_url, @unsubscribe_options[:domain])}", {}).and_return(sample_response)
20
+
21
+ @mailgun.unsubscribes.list @unsubscribe_options[:domain]
22
+ end
23
+ end
24
+
25
+ describe "find unsubscribe" do
26
+ it "should make a GET request with the right params to find given email address" do
27
+ sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.mailgun.org\" } ]}"
28
+ RestClient.should_receive(:get)
29
+ .with("#{@mailgun.unsubscribes.send(:unsubscribe_url, @unsubscribe_options[:domain], @unsubscribe_options[:email])}", {})
30
+ .and_return(sample_response)
31
+
32
+ @mailgun.unsubscribes.find(@unsubscribe_options[:domain], @unsubscribe_options[:email])
33
+ end
34
+ end
35
+
36
+ describe "delete unsubscribe" do
37
+ it "should make a DELETE request with correct params to remove a given email address" do
38
+ response_message = "{\"message\"=>\"Unsubscribe event has been removed\", \"address\"=>\"#{@unsubscribe_options[:email]}\"}"
39
+ Mailgun.should_receive(:submit)
40
+ .with(:delete, "#{@mailgun.unsubscribes.send(:unsubscribe_url, @unsubscribe_options[:domain], @unsubscribe_options[:email])}")
41
+ .and_return(response_message)
42
+
43
+ @mailgun.unsubscribes.remove(@unsubscribe_options[:domain], @unsubscribe_options[:email])
44
+ end
45
+ end
46
+
47
+ describe "add unsubscribe" do
48
+ context "to tag" do
49
+ it "should make a POST request with correct params to add a given email address to unsubscribe from a tag" do
50
+ response_message = "{\"message\"=>\"Address has been added to the unsubscribes table\", \"address\"=>\"#{@unsubscribe_options[:email]}\"}"
51
+ Mailgun.should_receive(:submit)
52
+ .with(:post, "#{@mailgun.unsubscribes.send(:unsubscribe_url, @unsubscribe_options[:domain])}",{:address=>@unsubscribe_options[:email], :tag=>@unsubscribe_options[:tag]})
53
+ .and_return(response_message)
54
+ @mailgun.unsubscribes.add(@unsubscribe_options[:email], @unsubscribe_options[:domain], @unsubscribe_options[:tag])
55
+ end
56
+ end
57
+
58
+ context "on all" do
59
+ it "should make a POST request with correct params to add a given email address to unsubscribe from all tags" do
60
+ sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.mailgun.org\" } ]}"
61
+ RestClient.should_receive(:post)
62
+ .with("#{@mailgun.unsubscribes.send(:unsubscribe_url, @unsubscribe_options[:domain])}", {
63
+ :address => @unsubscribe_options[:email], :tag => '*'
64
+ })
65
+ .and_return(sample_response)
66
+
67
+ @mailgun.unsubscribes.add(@unsubscribe_options[:email], @unsubscribe_options[:domain])
68
+ end
69
+ end
70
+ end
71
+
72
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailgun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: '0.5'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,13 +10,43 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-11-17 00:00:00.000000000 Z
14
- dependencies: []
13
+ date: 2013-01-17 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rest-client
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: multimap
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
15
47
  description: Mailgun library for Ruby
16
48
  email:
17
49
  - akash@akash.im
18
- - s@bushi.do
19
- - sean@fakecoolguys.com
20
50
  executables: []
21
51
  extensions: []
22
52
  extra_rdoc_files: []
@@ -28,12 +58,27 @@ files:
28
58
  - Rakefile
29
59
  - lib/mailgun.rb
30
60
  - lib/mailgun/base.rb
61
+ - lib/mailgun/bounce.rb
62
+ - lib/mailgun/complaint.rb
63
+ - lib/mailgun/list.rb
64
+ - lib/mailgun/list/member.rb
65
+ - lib/mailgun/log.rb
31
66
  - lib/mailgun/mail.rb
32
67
  - lib/mailgun/mailbox.rb
68
+ - lib/mailgun/mailgun_error.rb
69
+ - lib/mailgun/route.rb
70
+ - lib/mailgun/unsubscribe.rb
33
71
  - mailgun.gemspec
34
72
  - spec/base_spec.rb
73
+ - spec/bounce_spec.rb
74
+ - spec/complaint_spec.rb
75
+ - spec/list/member_spec.rb
76
+ - spec/list_spec.rb
77
+ - spec/log_spec.rb
35
78
  - spec/mailbox_spec.rb
79
+ - spec/route_spec.rb
36
80
  - spec/spec_helper.rb
81
+ - spec/unsubscribe_spec.rb
37
82
  homepage: http://github.com/Bushido/mailgun
38
83
  licenses: []
39
84
  post_install_message:
@@ -54,11 +99,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
99
  version: '0'
55
100
  requirements: []
56
101
  rubyforge_project:
57
- rubygems_version: 1.8.10
102
+ rubygems_version: 1.8.24
58
103
  signing_key:
59
104
  specification_version: 3
60
105
  summary: Idiomatic library for using the mailgun API from within ruby
61
106
  test_files:
62
107
  - spec/base_spec.rb
108
+ - spec/bounce_spec.rb
109
+ - spec/complaint_spec.rb
110
+ - spec/list/member_spec.rb
111
+ - spec/list_spec.rb
112
+ - spec/log_spec.rb
63
113
  - spec/mailbox_spec.rb
114
+ - spec/route_spec.rb
64
115
  - spec/spec_helper.rb
116
+ - spec/unsubscribe_spec.rb
117
+ has_rdoc: