mailgun 0.5 → 0.6

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0473a66b46e7ce54574d5f4f4c89867a563f2982
4
+ data.tar.gz: 9ad4fff672c513bc611fd99f724570177fa19582
5
+ SHA512:
6
+ metadata.gz: 1cddcab564ee3f9a8e1759a1ec253fef84ccb88a65debd3ab7c1e139a39c4d2c577dd90937e600cfbb90ffe8bd78cfea0378d472999749f0ecdeefab23a9ee36
7
+ data.tar.gz: e768a1407bdf85514d1ba2940b2fdb3d34f35de5d76159ad0274437441897d0e2c0e92df4f24d255948a2b4bf4718603cf6b9f15ae3ebc006b2c3fe64c79279e
data/Gemfile CHANGED
@@ -1,9 +1,7 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
3
  group :development do
4
- gem "rspec"
5
- gem "guard"
6
- gem 'simplecov', :require => false, :group => :test
4
+ gem "simplecov", :require => false, :group => :test
7
5
  end
8
6
 
9
7
  # Specify your gem's dependencies in mailgun.gemspec
data/README.md CHANGED
@@ -1,11 +1,10 @@
1
- Mailgun
2
- =========
3
- This gem allows for idiomatic Mailgun usage from within ruby. Mailgun is a kickass email-as-a-service that lets you use email as if it made sense. Check it out at http://mailgun.net/
1
+ # Mailgun rubygem
4
2
 
5
- The official gem repo is at https://github.com/Bushido/mailgun
3
+ This gem allows for idiomatic Mailgun usage from within ruby. Mailgun is a kickass email-as-a-service that lets you use email as if it made sense. Check it out at http://mailgun.net
6
4
 
7
5
  Mailgun exposes the following resources:
8
6
 
7
+ * Sending email
9
8
  * Mailing Lists
10
9
  * Mailing List Members
11
10
  * Mailboxes
@@ -17,136 +16,156 @@ Mailgun exposes the following resources:
17
16
  * Unsubscribes
18
17
  * Complaints
19
18
 
20
- Currently the gem only exposes the Mailbox and Routes APIs, but patches are welcome (and easy!).
19
+ Patches are welcome (and easy!).
21
20
 
22
- ActionMailer
23
- ============
21
+ ## Sending mail using ActionMailer
24
22
 
25
- This gem is unnecessary if you'd like to simply hook up Mailgun to Rails' Action Mailer. Just add the below to your Configuration.
23
+ If you simply want to send mail using Mailgun, just set the smtp settings in the Rails application like the following. Replace wherever necessary in the following snippet :)
24
+ ```ruby
25
+ ActionMailer::Base.smtp_settings = {
26
+ :port => 587,
27
+ :address => 'smtp.mailgun.org',
28
+ :user_name => 'postmaster@your.mailgun.domain',
29
+ :password => 'mailgun-smtp-password',
30
+ :domain => 'your.mailgun.domain',
31
+ :authentication => :plain,
32
+ }
33
+ ActionMailer::Base.delivery_method = :smtp
34
+ ```
26
35
 
27
- ActionMailer::Base.smtp_settings = {
28
- :port => 587,
29
- :address => 'smtp.mailgun.org',
30
- :user_name => 'postmaster@your.mailgun.domain',
31
- :password => 'mailgun-smtp-password',
32
- :domain => 'your.mailgun.domain',
33
- :authentication => :plain,
34
- }
35
- ActionMailer::Base.delivery_method = :smtp
36
+ ## Usage
36
37
 
37
- Usage
38
- =====
39
38
  We mimic the ActiveRecord-style interface.
40
39
 
41
40
 
42
- Configuration:
41
+ #### Configuration
42
+ ```ruby
43
+ # Initialize your Mailgun object:
44
+ Mailgun.configure do |config|
45
+ config.api_key = 'your-api-key'
46
+ config.domain = 'your-mailgun-domain'
47
+ end
48
+
49
+ @mailgun = Mailgun()
50
+
51
+ # or alternatively:
52
+ @mailgun = Mailgun(:api_key => 'your-api-key')
53
+ ```
54
+
55
+ #### Sending Email
56
+ ```ruby
57
+ parameters = {
58
+ :to => "cooldev@your.mailgun.domain",
59
+ :subject => "missing tps reports",
60
+ :text => "yeah, we're gonna need you to come in on friday...yeah.",
61
+ :from => "lumberg.bill@initech.mailgun.domain"
62
+ }
63
+ @mailgun.messages.send_email(parameters)
64
+ ```
65
+ ####
66
+
67
+ #### Mailing Lists
68
+ ```ruby
69
+ # Create a mailing list
70
+ @mailgun.lists.create "devs@your.mailgun.domain"
71
+
72
+ # List all Mailing lists
73
+ @mailgun.lists.all
74
+
75
+ # Find a mailing list
76
+ @mailgun.lists.find "devs@your.mailgun.domain"
77
+
78
+ # Update a mailing list
79
+ @mailgun.lists.update("devs@your.mailgun.domain", "developers@your.mailgun.domain", "Developers", "Develepor Mailing List")
80
+
81
+ # Delete a mailing list
82
+ @mailgun.lists.delete("developers@your.mailgun.domain")
83
+ ```
84
+
85
+ #### Mailing List Members
86
+ ```ruby
87
+ # List all members within a mailing list
88
+ @mailgun.list_members.list "devs@your.mailgun.domain"
89
+
90
+ # Find a particular member in a list
91
+ @mailgun.list_members.find "devs@your.mailgun.domain", "bond@mi6.co.uk"
92
+
93
+ # Add a member to a list
94
+ @mailgun.list_members.add "devs@your.mailgun.domain", "Q@mi6.co.uk"
95
+
96
+ # Update a member on a list
97
+ @mailgun.list_members.update "devs@your.mailgun.domain", "Q@mi6.co.uk", "Q", {:gender => 'male'}.to_json, :subscribed => 'no')
98
+
99
+ # Remove a member from a list
100
+ @mailgun.list_members.remove "devs@your.mailgun.domain", "M@mi6.co.uk"
101
+ ```
102
+
103
+ #### Mailboxes
104
+ ```ruby
105
+ # Create a mailbox
106
+ @mailgun.mailboxes.create "new-mailbox@your-domain.com", "password"
107
+
108
+ # List all mailboxes that belong to a domain
109
+ @mailgun.mailboxes.list "domain.com"
110
+
111
+ # Destroy a mailbox (queue bond-villian laughter)
112
+ # "I'm sorry Bond, it seems your mailbox will be... destroyed!"
113
+ @mailbox.mailboxes.destroy "bond@mi6.co.uk"
114
+ ```
115
+
116
+ #### Routes
117
+ ```ruby
118
+ # Initialize your Mailgun object:
119
+ @mailgun = Mailgun(:api_key => 'your-api-key')
120
+
121
+ # Create a route
122
+ # Give it a human-readable description for later, a priority
123
+ # filters, and actions
124
+ @mailgun.routes.create "Description for the new route", 1,
125
+ [:match_recipient, "apowers@mi5.co.uk"],
126
+ [[:forward, "http://my-site.com/incoming-mail-route"],
127
+ [:stop]]
128
+
129
+ # List all routes that belong to a domain
130
+ # limit the query to 100 routes starting from 0
131
+ @mailgun.routes.list 100, 0
132
+
133
+ # Get the details of a route via its id
134
+ @mailgun.routes.find "4e97c1b2ba8a48567f007fb6"
135
+
136
+ # Update a route via its id
137
+ # (all keys are optional)
138
+ @mailgun.routes.update "4e97c1b2ba8a48567f007fb6", {
139
+ :priority => 2,
140
+ :filter => [:match_header, :subject, "*.support"],
141
+ :actions => [[:forward, "http://new-site.com/incoming-emails"]]
142
+ }
143
+
144
+ # Destroy a route via its id
145
+ @mailbox.routes.destroy "4e97c1b2ba8a48567f007fb6"
146
+ ```
43
147
 
44
- # Initialize your Mailgun object:
45
- Mailgun.configure do |config|
46
- config.api_key = 'your-api-key'
47
- config.domain = 'your-mailgun-domain'
48
- end
49
-
50
- @mailgun = Mailgun()
51
-
52
- # or alternatively:
53
- @mailgun = Mailgun(:api_key => 'your-api-key')
54
-
55
-
56
- Mailing Lists:
57
-
58
- # Create a mailing list
59
- @mailgun.lists.create "devs@your.mailgun.domain"
60
-
61
- # List all Mailing lists
62
- @mailgun.lists.all
63
-
64
- # Find a mailing list
65
- @mailgun.lists.find "devs@your.mailgun.domain"
66
-
67
- # Update a mailing list
68
- @mailgun.lists.update("devs@your.mailgun.domain", "developers@your.mailgun.domain", "Developers", "Develepor Mailing List")
69
-
70
- # Delete a mailing list
71
- @mailgun.lists.delete("developers@your.mailgun.domain")
72
-
73
- Mailing List Members:
74
-
75
- # List all members within a mailing list
76
- @mailgun.list_members.list "devs@your.mailgun.domain"
77
-
78
- # Find a particular member in a list
79
- @mailgun.list_members.find "devs@your.mailgun.domain", "bond@mi6.co.uk"
80
-
81
- # Add a member to a list
82
- @mailgun.list_members.add "devs@your.mailgun.domain", "Q@mi6.co.uk"
83
-
84
- # Update a member on a list
85
- @mailgun.list_members.update "devs@your.mailgun.domain", "Q@mi6.co.uk", "Q", {:gender => 'male'}.to_json, :subscribed => 'no')
86
-
87
- # Remove a member from a list
88
- @mailgun.list_members.remove "devs@your.mailgun.domain", "M@mi6.co.uk"
89
-
90
- Mailboxes:
148
+ Supported route filters are: `:match_header`, `:match_recipient`, and `:catch_all`
91
149
 
92
- # Create a mailbox
93
- @mailgun.mailboxes.create "new-mailbox@your-domain.com", "password"
94
-
95
- # List all mailboxes that belong to a domain
96
- @mailgun.mailboxes.list "domain.com"
97
-
98
- # Destroy a mailbox (queue bond-villian laughter)
99
- # "I'm sorry Bond, it seems your mailbox will be... destroyed!"
100
- @mailbox.mailboxes.destroy "bond@mi6.co.uk"
101
-
150
+ Supported route actions are: `:forward`, and `:stop`
102
151
 
103
- Routes:
104
152
 
105
- # Initialize your Mailgun object:
106
- @mailgun = Mailgun(:api_key => 'your-api-key')
153
+ ## Making Your Changes
107
154
 
108
- # Create a route
109
- # Give it a human-readable description for later, a priority
110
- # filters, and actions
111
- @mailgun.routes.create "Description for the new route", 1,
112
- [:match_recipient, "apowers@mi5.co.uk"],
113
- [[:forward, "http://my-site.com/incoming-mail-route"],
114
- [:stop]]
115
-
116
- # List all routes that belong to a domain
117
- # limit the query to 100 routes starting from 0
118
- @mailgun.routes.list 100, 0
155
+ * Fork the project (Github has really good step-by-step directions)
119
156
 
120
- # Get the details of a route via its id
121
- @mailgun.routes.find "4e97c1b2ba8a48567f007fb6"
157
+ * Start a feature/bugfix branch
122
158
 
123
- # Update a route via its id
124
- # (all keys are optional)
125
- @mailgun.routes.update "4e97c1b2ba8a48567f007fb6", {
126
- :priority => 2,
127
- :filter => [:match_header, :subject, "*.support"],
128
- :actions => [[:forward, "http://new-site.com/incoming-emails"]]
129
- }
130
-
131
- # Destroy a route via its id
132
- @mailbox.routes.destroy "4e97c1b2ba8a48567f007fb6"
159
+ * Commit and push until you are happy with your contribution
133
160
 
134
- Supported route filters are: `:match_header`, `:match_recipient`, and `:catch_all`
135
- Supported route actions are: `:forward`, and `:stop`
161
+ * Make sure to add tests for it. This is important so we don't break it in a future version unintentionally.
136
162
 
137
- Making Your Changes
138
- ===================
163
+ * After making your changes, be sure to run the Mailgun tests using the `rspec spec` to make sure everything works.
139
164
 
140
- * Fork the project (Github has really good step-by-step directions)
141
- * Start a feature/bugfix branch
142
- * Commit and push until you are happy with your contribution
143
- * Make sure to add tests for it. This is important so we don't break it in a future version unintentionally.
144
- * After making your changes, be sure to run the Mailgun RSpec specs to make sure everything works.
145
165
  * Submit your change as a Pull Request and update the GitHub issue to let us know it is ready for review.
146
166
 
147
167
 
148
- TODO
149
- =========
168
+ ## TODO
150
169
 
151
170
  * Mailgun() is overwriting api key. api key is not persisting
152
171
  * Add skip and limit functionality
@@ -156,16 +175,18 @@ TODO
156
175
  * Stats?
157
176
  * Campaign?
158
177
 
159
- Authors
160
- =======
161
178
 
162
- * Akash Manohar J (akash@akash.im)
163
- * Scott Carleton (@scotterc) - for new functionality and major improvements.
164
- * Sean Grove (sean@gobushido.com)
165
-
179
+ ## Authors
180
+
181
+ * Akash Manohar J ([@HashNuke](http://github.com/HashNuke))
182
+ * Sean Grove ([@sgrove](http://github.com/sgrove))
183
+
184
+ ## Contrubutions
185
+
186
+ * Yomi Colledge ([@baphled](http://github.com/baphled))
187
+ * Scott Carleton ([@scotterc](http://github.com/scotterc)) - new functionality and improvements
188
+ * Alan deLevie ([@adelevie](http://github.com/adelevie)) - Sending email
166
189
 
167
- License
168
- ===================
169
- Released under the MIT license by CloudFuji. See LICENSE for more details.
190
+ ## License
170
191
 
171
- This is a fork of he Cloudfuji/mailgun repo.
192
+ Released under the MIT license. See LICENSE for more details.
@@ -12,6 +12,7 @@ require "mailgun/complaint"
12
12
  require "mailgun/log"
13
13
  require "mailgun/list"
14
14
  require "mailgun/list/member"
15
+ require "mailgun/message"
15
16
 
16
17
  #require "startup"
17
18
 
@@ -20,36 +20,40 @@ module Mailgun
20
20
  end
21
21
 
22
22
  # Returns an instance of Mailgun::Mailbox configured for the current API user
23
- def mailboxes
24
- @mailboxes ||= Mailgun::Mailbox.new(self)
23
+ def mailboxes(domain = Mailgun.domain)
24
+ Mailgun::Mailbox.new(self, domain)
25
+ end
26
+
27
+ def messages(domain = Mailgun.domain)
28
+ @messages ||= Mailgun::Message.new(self, domain)
25
29
  end
26
30
 
27
31
  def routes
28
32
  @routes ||= Mailgun::Route.new(self)
29
33
  end
30
34
 
31
- def bounces
32
- @bounces ||= Mailgun::Bounce.new(self)
35
+ def bounces(domain = Mailgun.domain)
36
+ Mailgun::Bounce.new(self, domain)
33
37
  end
34
38
 
35
- def unsubscribes
36
- @unsubscribes ||= Mailgun::Unsubscribe.new(self)
39
+ def unsubscribes(domain = Mailgun.domain)
40
+ Mailgun::Unsubscribe.new(self, domain)
37
41
  end
38
42
 
39
- def complaints
40
- @complaints ||= Mailgun::Complaint.new(self)
43
+ def complaints(domain = Mailgun.domain)
44
+ Mailgun::Complaint.new(self, domain)
41
45
  end
42
46
 
43
- def log
44
- @log ||= Mailgun::Log.new(self)
47
+ def log(domain=Mailgun.domain)
48
+ Mailgun::Log.new(self, domain)
45
49
  end
46
50
 
47
51
  def lists
48
- @lists ||= Mailgun::List.new(self)
52
+ @lists ||= Mailgun::MailingList.new(self)
49
53
  end
50
54
 
51
- def list_members
52
- @list_members ||= Mailgun::List::Member.new(self)
55
+ def list_members(address)
56
+ Mailgun::MailingList::Member.new(self, address)
53
57
  end
54
58
  end
55
59
 
@@ -57,6 +61,7 @@ module Mailgun
57
61
  # Submits the API call to the Mailgun server
58
62
  def self.submit(method, url, parameters={})
59
63
  begin
64
+ parameters = {:params => parameters} if method == :get
60
65
  return JSON(RestClient.send(method, url, parameters))
61
66
  rescue => e
62
67
  error_message = nil
@@ -1,34 +1,33 @@
1
1
  module Mailgun
2
+
3
+ # Interface to manage bounce lists
4
+ # Refer - http://documentation.mailgun.net/api-bounces.html for optional params to pass
2
5
  class Bounce
3
6
  # Used internally, called from Mailgun::Base
4
- def initialize(mailgun)
7
+ def initialize(mailgun, domain)
5
8
  @mailgun = mailgun
9
+ @domain = domain
6
10
  end
7
11
 
8
12
  # List all bounces for a given domain
9
- # * domain the domain for which all bounces will listed
10
- def list(domain = Mailgun.domain)
11
- response = Mailgun.submit :get, bounce_url(domain)
12
-
13
- if response
14
- response["items"].collect {|item| item["address"]}
15
- end
13
+ def list(options={})
14
+ Mailgun.submit(:get, bounce_url, options)["items"] || []
16
15
  end
17
16
 
18
- def find(domain = Mailgun.domain, email)
19
- Mailgun.submit :get, bounce_url(domain, email)
17
+ # Find bounce events for an email address
18
+ def find(email)
19
+ Mailgun.submit :get, bounce_url(email)
20
20
  end
21
21
 
22
- def add(domain = Mailgun.domain, email)
23
- Mailgun.submit :post, bounce_url(domain), :address => email
22
+ def add(email)
23
+ Mailgun.submit :post, bounce_url, :address => email
24
24
  end
25
25
 
26
26
  private
27
27
 
28
28
  # Helper method to generate the proper url for Mailgun mailbox API calls
29
- def bounce_url(domain, address=nil)
30
- domain = Mailgun.domain if Mailgun.domain
31
- "#{@mailgun.base_url}/#{domain}/bounces#{'/' + address if address}"
29
+ def bounce_url(address=nil)
30
+ "#{@mailgun.base_url}/#{@domain}/bounces#{'/' + address if address}"
32
31
  end
33
32
 
34
33
  end
@@ -1,38 +1,39 @@
1
1
  module Mailgun
2
+
3
+ # Complaints interface. Refer to http://documentation.mailgun.net/api-complaints.html
2
4
  class Complaint
3
5
  # Used internally, called from Mailgun::Base
4
- def initialize(mailgun)
6
+ def initialize(mailgun, domain)
5
7
  @mailgun = mailgun
8
+ @domain = domain
6
9
  end
7
10
 
8
- # List all complaints for a given domain
9
- # * domain the domain for which all complaints will listed
10
- def list(domain = Mailgun.domain)
11
- response = Mailgun.submit :get, complaint_url(domain)
12
-
13
- if response
14
- response["items"].collect {|item| item["address"]}
15
- end
11
+ # List all the users who have complained
12
+ def list(options={})
13
+ Mailgun.submit(:get, complaint_url, options)["items"] || []
16
14
  end
17
-
18
- def find(domain = Mailgun.domain, email)
19
- Mailgun.submit :get, complaint_url(domain, email)
15
+
16
+ # Find a complaint by email
17
+ def find(email)
18
+ Mailgun.submit :get, complaint_url(email)
20
19
  end
21
20
 
22
- def add(domain=Mailgun.domain, email)
23
- Mailgun.submit :post, complaint_url(domain), {:address => email}
21
+ # Add an email to the complaints list
22
+ def add(email)
23
+ Mailgun.submit :post, complaint_url, {:address => email}
24
24
  end
25
25
 
26
- def remove(domain = Mailgun.domain, email)
27
- Mailgun.submit :delete, complaint_url(domain, email)
26
+ # Removes a complaint by email
27
+ def destroy(email)
28
+ Mailgun.submit :delete, complaint_url(email)
28
29
  end
29
30
 
30
31
  private
31
32
 
32
33
  # Helper method to generate the proper url for Mailgun complaints API calls
33
- def complaint_url(domain, address=nil)
34
- "#{@mailgun.base_url}/#{domain}/complaints#{'/' + address if address}"
34
+ def complaint_url(address=nil)
35
+ "#{@mailgun.base_url}/#{@domain}/complaints#{'/' + address if address}"
35
36
  end
36
-
37
+
37
38
  end
38
39
  end