Class: Mailgunner::Client
- Inherits:
-
Object
- Object
- Mailgunner::Client
- Defined in:
- lib/mailgunner.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#http ⇒ Object
Returns the value of attribute http.
Instance Method Summary collapse
- #add_bounce(attributes = {}) ⇒ Object
- #add_campaign(attributes = {}) ⇒ Object
- #add_complaint(attributes = {}) ⇒ Object
- #add_credentials(attributes) ⇒ Object
- #add_domain(attributes = {}) ⇒ Object
- #add_list(attributes = {}) ⇒ Object
- #add_list_member(list_address, member_attributes) ⇒ Object
- #add_route(attributes = {}) ⇒ Object
- #add_unsubscribe(attributes = {}) ⇒ Object
- #delete_bounce(address) ⇒ Object
- #delete_campaign(id) ⇒ Object
- #delete_complaint(address) ⇒ Object
- #delete_credentials(login) ⇒ Object
- #delete_domain(name) ⇒ Object
- #delete_list(address) ⇒ Object
- #delete_list_member(list_address, member_address) ⇒ Object
- #delete_message(key) ⇒ Object
- #delete_route(id) ⇒ Object
- #delete_unsubscribe(address_or_id) ⇒ Object
- #get_bounce(address) ⇒ Object
- #get_bounces(params = {}) ⇒ Object
- #get_campaign(id) ⇒ Object
- #get_campaign_clicks(campaign_id, params = {}) ⇒ Object
- #get_campaign_complaints(campaign_id, params = {}) ⇒ Object
- #get_campaign_events(campaign_id, params = {}) ⇒ Object
- #get_campaign_opens(campaign_id, params = {}) ⇒ Object
- #get_campaign_stats(campaign_id, params = {}) ⇒ Object
- #get_campaign_unsubscribes(campaign_id, params = {}) ⇒ Object
- #get_campaigns(params = {}) ⇒ Object
- #get_complaint(address) ⇒ Object
- #get_complaints(params = {}) ⇒ Object
- #get_credentials ⇒ Object
- #get_domain(name) ⇒ Object
- #get_domains(params = {}) ⇒ Object
- #get_events(params = {}) ⇒ Object
- #get_list(address) ⇒ Object
- #get_list_member(list_address, member_address) ⇒ Object
- #get_list_members(list_address, params = {}) ⇒ Object
- #get_list_stats(list_address) ⇒ Object
- #get_lists(params = {}) ⇒ Object
- #get_message(key) ⇒ Object
- #get_mime_message(key) ⇒ Object
- #get_route(id) ⇒ Object
- #get_routes(params = {}) ⇒ Object
- #get_stats(params = {}) ⇒ Object
- #get_unsubscribe(address) ⇒ Object
- #get_unsubscribes(params = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #parse_addresses(values) ⇒ Object
- #send_message(attributes = {}) ⇒ Object
- #send_mime(mail) ⇒ Object
- #update_campaign(id, attributes = {}) ⇒ Object
- #update_credentials(login, attributes) ⇒ Object
- #update_list(address, attributes = {}) ⇒ Object
- #update_list_member(list_address, member_address, member_attributes) ⇒ Object
- #update_route(id, attributes = {}) ⇒ Object
- #validate_address(value) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mailgunner.rb', line 19 def initialize( = {}) @domain = if .key?(:domain) .fetch(:domain) elsif ENV.key?('MAILGUN_SMTP_LOGIN') ENV['MAILGUN_SMTP_LOGIN'].to_s.split('@').last else NoDomainProvided end @api_key = .fetch(:api_key) { ENV.fetch('MAILGUN_API_KEY') } @http = Net::HTTP.new('api.mailgun.net', Net::HTTP.https_default_port) @http.use_ssl = true end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
17 18 19 |
# File 'lib/mailgunner.rb', line 17 def api_key @api_key end |
#domain ⇒ Object
Returns the value of attribute domain.
17 18 19 |
# File 'lib/mailgunner.rb', line 17 def domain @domain end |
#http ⇒ Object
Returns the value of attribute http.
17 18 19 |
# File 'lib/mailgunner.rb', line 17 def http @http end |
Instance Method Details
#add_bounce(attributes = {}) ⇒ Object
139 140 141 |
# File 'lib/mailgunner.rb', line 139 def add_bounce(attributes = {}) post("/v3/#{escape @domain}/bounces", attributes) end |
#add_campaign(attributes = {}) ⇒ Object
183 184 185 |
# File 'lib/mailgunner.rb', line 183 def add_campaign(attributes = {}) post("/v3/#{escape @domain}/campaigns", attributes) end |
#add_complaint(attributes = {}) ⇒ Object
123 124 125 |
# File 'lib/mailgunner.rb', line 123 def add_complaint(attributes = {}) post("/v3/#{escape @domain}/complaints", attributes) end |
#add_credentials(attributes) ⇒ Object
87 88 89 |
# File 'lib/mailgunner.rb', line 87 def add_credentials(attributes) post("/v3/domains/#{escape @domain}/credentials", attributes) end |
#add_domain(attributes = {}) ⇒ Object
75 76 77 |
# File 'lib/mailgunner.rb', line 75 def add_domain(attributes = {}) post('/v3/domains', attributes) end |
#add_list(attributes = {}) ⇒ Object
227 228 229 |
# File 'lib/mailgunner.rb', line 227 def add_list(attributes = {}) post('/v3/lists', attributes) end |
#add_list_member(list_address, member_attributes) ⇒ Object
247 248 249 |
# File 'lib/mailgunner.rb', line 247 def add_list_member(list_address, member_attributes) post("/v3/lists/#{escape list_address}/members", member_attributes) end |
#add_route(attributes = {}) ⇒ Object
163 164 165 |
# File 'lib/mailgunner.rb', line 163 def add_route(attributes = {}) post('/v3/routes', attributes) end |
#add_unsubscribe(attributes = {}) ⇒ Object
111 112 113 |
# File 'lib/mailgunner.rb', line 111 def add_unsubscribe(attributes = {}) post("/v3/#{escape @domain}/unsubscribes", attributes) end |
#delete_bounce(address) ⇒ Object
143 144 145 |
# File 'lib/mailgunner.rb', line 143 def delete_bounce(address) delete("/v3/#{escape @domain}/bounces/#{escape address}") end |
#delete_campaign(id) ⇒ Object
191 192 193 |
# File 'lib/mailgunner.rb', line 191 def delete_campaign(id) delete("/v3/#{escape @domain}/campaigns/#{escape id}") end |
#delete_complaint(address) ⇒ Object
127 128 129 |
# File 'lib/mailgunner.rb', line 127 def delete_complaint(address) delete("/v3/#{escape @domain}/complaints/#{escape address}") end |
#delete_credentials(login) ⇒ Object
95 96 97 |
# File 'lib/mailgunner.rb', line 95 def delete_credentials(login) delete("/v3/domains/#{escape @domain}/credentials/#{escape login}") end |
#delete_domain(name) ⇒ Object
79 80 81 |
# File 'lib/mailgunner.rb', line 79 def delete_domain(name) delete("/v3/domains/#{escape name}") end |
#delete_list(address) ⇒ Object
235 236 237 |
# File 'lib/mailgunner.rb', line 235 def delete_list(address) delete("/v3/lists/#{escape address}") end |
#delete_list_member(list_address, member_address) ⇒ Object
255 256 257 |
# File 'lib/mailgunner.rb', line 255 def delete_list_member(list_address, member_address) delete("/v3/lists/#{escape list_address}/members/#{escape member_address}") end |
#delete_message(key) ⇒ Object
63 64 65 |
# File 'lib/mailgunner.rb', line 63 def (key) delete("/v3/domains/#{escape @domain}/messages/#{escape key}") end |
#delete_route(id) ⇒ Object
171 172 173 |
# File 'lib/mailgunner.rb', line 171 def delete_route(id) delete("/v3/routes/#{escape id}") end |
#delete_unsubscribe(address_or_id) ⇒ Object
107 108 109 |
# File 'lib/mailgunner.rb', line 107 def delete_unsubscribe(address_or_id) delete("/v3/#{escape @domain}/unsubscribes/#{escape address_or_id}") end |
#get_bounce(address) ⇒ Object
135 136 137 |
# File 'lib/mailgunner.rb', line 135 def get_bounce(address) get("/v3/#{escape @domain}/bounces/#{escape address}") end |
#get_bounces(params = {}) ⇒ Object
131 132 133 |
# File 'lib/mailgunner.rb', line 131 def get_bounces(params = {}) get("/v3/#{escape @domain}/bounces", params) end |
#get_campaign(id) ⇒ Object
179 180 181 |
# File 'lib/mailgunner.rb', line 179 def get_campaign(id) get("/v3/#{escape @domain}/campaigns/#{escape id}") end |
#get_campaign_clicks(campaign_id, params = {}) ⇒ Object
203 204 205 |
# File 'lib/mailgunner.rb', line 203 def get_campaign_clicks(campaign_id, params = {}) get("/v3/#{escape @domain}/campaigns/#{escape campaign_id}/clicks", params) end |
#get_campaign_complaints(campaign_id, params = {}) ⇒ Object
215 216 217 |
# File 'lib/mailgunner.rb', line 215 def get_campaign_complaints(campaign_id, params = {}) get("/v3/#{escape @domain}/campaigns/#{escape campaign_id}/complaints", params) end |
#get_campaign_events(campaign_id, params = {}) ⇒ Object
195 196 197 |
# File 'lib/mailgunner.rb', line 195 def get_campaign_events(campaign_id, params = {}) get("/v3/#{escape @domain}/campaigns/#{escape campaign_id}/events", params) end |
#get_campaign_opens(campaign_id, params = {}) ⇒ Object
207 208 209 |
# File 'lib/mailgunner.rb', line 207 def get_campaign_opens(campaign_id, params = {}) get("/v3/#{escape @domain}/campaigns/#{escape campaign_id}/opens", params) end |
#get_campaign_stats(campaign_id, params = {}) ⇒ Object
199 200 201 |
# File 'lib/mailgunner.rb', line 199 def get_campaign_stats(campaign_id, params = {}) get("/v3/#{escape @domain}/campaigns/#{escape campaign_id}/stats", params) end |
#get_campaign_unsubscribes(campaign_id, params = {}) ⇒ Object
211 212 213 |
# File 'lib/mailgunner.rb', line 211 def get_campaign_unsubscribes(campaign_id, params = {}) get("/v3/#{escape @domain}/campaigns/#{escape campaign_id}/unsubscribes", params) end |
#get_campaigns(params = {}) ⇒ Object
175 176 177 |
# File 'lib/mailgunner.rb', line 175 def get_campaigns(params = {}) get("/v3/#{escape @domain}/campaigns", params) end |
#get_complaint(address) ⇒ Object
119 120 121 |
# File 'lib/mailgunner.rb', line 119 def get_complaint(address) get("/v3/#{escape @domain}/complaints/#{escape address}") end |
#get_complaints(params = {}) ⇒ Object
115 116 117 |
# File 'lib/mailgunner.rb', line 115 def get_complaints(params = {}) get("/v3/#{escape @domain}/complaints", params) end |
#get_credentials ⇒ Object
83 84 85 |
# File 'lib/mailgunner.rb', line 83 def get_credentials get("/v3/domains/#{escape @domain}/credentials") end |
#get_domain(name) ⇒ Object
71 72 73 |
# File 'lib/mailgunner.rb', line 71 def get_domain(name) get("/v3/domains/#{escape name}") end |
#get_domains(params = {}) ⇒ Object
67 68 69 |
# File 'lib/mailgunner.rb', line 67 def get_domains(params = {}) get('/v3/domains', params) end |
#get_events(params = {}) ⇒ Object
151 152 153 |
# File 'lib/mailgunner.rb', line 151 def get_events(params = {}) get("/v3/#{escape @domain}/events", params) end |
#get_list(address) ⇒ Object
223 224 225 |
# File 'lib/mailgunner.rb', line 223 def get_list(address) get("/v3/lists/#{escape address}") end |
#get_list_member(list_address, member_address) ⇒ Object
243 244 245 |
# File 'lib/mailgunner.rb', line 243 def get_list_member(list_address, member_address) get("/v3/lists/#{escape list_address}/members/#{escape member_address}") end |
#get_list_members(list_address, params = {}) ⇒ Object
239 240 241 |
# File 'lib/mailgunner.rb', line 239 def get_list_members(list_address, params = {}) get("/v3/lists/#{escape list_address}/members", params) end |
#get_list_stats(list_address) ⇒ Object
259 260 261 |
# File 'lib/mailgunner.rb', line 259 def get_list_stats(list_address) get("/v3/lists/#{escape list_address}/stats") end |
#get_lists(params = {}) ⇒ Object
219 220 221 |
# File 'lib/mailgunner.rb', line 219 def get_lists(params = {}) get('/v3/lists', params) end |
#get_message(key) ⇒ Object
43 44 45 |
# File 'lib/mailgunner.rb', line 43 def (key) get("/v3/domains/#{escape @domain}/messages/#{escape key}") end |
#get_mime_message(key) ⇒ Object
47 48 49 |
# File 'lib/mailgunner.rb', line 47 def (key) get("/v3/domains/#{escape @domain}/messages/#{escape key}", {}, {'Accept' => 'message/rfc2822'}) end |
#get_route(id) ⇒ Object
159 160 161 |
# File 'lib/mailgunner.rb', line 159 def get_route(id) get("/v3/routes/#{escape id}") end |
#get_routes(params = {}) ⇒ Object
155 156 157 |
# File 'lib/mailgunner.rb', line 155 def get_routes(params = {}) get('/v3/routes', params) end |
#get_stats(params = {}) ⇒ Object
147 148 149 |
# File 'lib/mailgunner.rb', line 147 def get_stats(params = {}) get("/v3/#{escape @domain}/stats", params) end |
#get_unsubscribe(address) ⇒ Object
103 104 105 |
# File 'lib/mailgunner.rb', line 103 def get_unsubscribe(address) get("/v3/#{escape @domain}/unsubscribes/#{escape address}") end |
#get_unsubscribes(params = {}) ⇒ Object
99 100 101 |
# File 'lib/mailgunner.rb', line 99 def get_unsubscribes(params = {}) get("/v3/#{escape @domain}/unsubscribes", params) end |
#parse_addresses(values) ⇒ Object
39 40 41 |
# File 'lib/mailgunner.rb', line 39 def parse_addresses(values) get('/v3/address/parse', addresses: Array(values).join(',')) end |
#send_message(attributes = {}) ⇒ Object
51 52 53 |
# File 'lib/mailgunner.rb', line 51 def (attributes = {}) post("/v3/#{escape @domain}/messages", attributes) end |
#send_mime(mail) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/mailgunner.rb', line 55 def send_mime(mail) to = ['to', Array(mail.to).join(',')] = ['message', mail.encoded, {filename: 'message.mime'}] multipart_post("/v3/#{escape @domain}/messages.mime", [to, ]) end |
#update_campaign(id, attributes = {}) ⇒ Object
187 188 189 |
# File 'lib/mailgunner.rb', line 187 def update_campaign(id, attributes = {}) put("/v3/#{escape @domain}/campaigns/#{escape id}", attributes) end |
#update_credentials(login, attributes) ⇒ Object
91 92 93 |
# File 'lib/mailgunner.rb', line 91 def update_credentials(login, attributes) put("/v3/domains/#{escape @domain}/credentials/#{escape login}", attributes) end |
#update_list(address, attributes = {}) ⇒ Object
231 232 233 |
# File 'lib/mailgunner.rb', line 231 def update_list(address, attributes = {}) put("/v3/lists/#{escape address}", attributes) end |
#update_list_member(list_address, member_address, member_attributes) ⇒ Object
251 252 253 |
# File 'lib/mailgunner.rb', line 251 def update_list_member(list_address, member_address, member_attributes) put("/v3/lists/#{escape list_address}/members/#{escape member_address}", member_attributes) end |
#update_route(id, attributes = {}) ⇒ Object
167 168 169 |
# File 'lib/mailgunner.rb', line 167 def update_route(id, attributes = {}) put("/v3/routes/#{escape id}", attributes) end |
#validate_address(value) ⇒ Object
35 36 37 |
# File 'lib/mailgunner.rb', line 35 def validate_address(value) get('/v3/address/validate', address: value) end |