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.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mailgunner.rb', line 18 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.
16 17 18 |
# File 'lib/mailgunner.rb', line 16 def api_key @api_key end |
#domain ⇒ Object
Returns the value of attribute domain.
16 17 18 |
# File 'lib/mailgunner.rb', line 16 def domain @domain end |
#http ⇒ Object
Returns the value of attribute http.
16 17 18 |
# File 'lib/mailgunner.rb', line 16 def http @http end |
Instance Method Details
#add_bounce(attributes = {}) ⇒ Object
138 139 140 |
# File 'lib/mailgunner.rb', line 138 def add_bounce(attributes = {}) post("/v3/#{escape @domain}/bounces", attributes) end |
#add_campaign(attributes = {}) ⇒ Object
182 183 184 |
# File 'lib/mailgunner.rb', line 182 def add_campaign(attributes = {}) post("/v3/#{escape @domain}/campaigns", attributes) end |
#add_complaint(attributes = {}) ⇒ Object
122 123 124 |
# File 'lib/mailgunner.rb', line 122 def add_complaint(attributes = {}) post("/v3/#{escape @domain}/complaints", attributes) end |
#add_credentials(attributes) ⇒ Object
86 87 88 |
# File 'lib/mailgunner.rb', line 86 def add_credentials(attributes) post("/v3/domains/#{escape @domain}/credentials", attributes) end |
#add_domain(attributes = {}) ⇒ Object
74 75 76 |
# File 'lib/mailgunner.rb', line 74 def add_domain(attributes = {}) post('/v3/domains', attributes) end |
#add_list(attributes = {}) ⇒ Object
226 227 228 |
# File 'lib/mailgunner.rb', line 226 def add_list(attributes = {}) post('/v3/lists', attributes) end |
#add_list_member(list_address, member_attributes) ⇒ Object
246 247 248 |
# File 'lib/mailgunner.rb', line 246 def add_list_member(list_address, member_attributes) post("/v3/lists/#{escape list_address}/members", member_attributes) end |
#add_route(attributes = {}) ⇒ Object
162 163 164 |
# File 'lib/mailgunner.rb', line 162 def add_route(attributes = {}) post('/v3/routes', attributes) end |
#add_unsubscribe(attributes = {}) ⇒ Object
110 111 112 |
# File 'lib/mailgunner.rb', line 110 def add_unsubscribe(attributes = {}) post("/v3/#{escape @domain}/unsubscribes", attributes) end |
#delete_bounce(address) ⇒ Object
142 143 144 |
# File 'lib/mailgunner.rb', line 142 def delete_bounce(address) delete("/v3/#{escape @domain}/bounces/#{escape address}") end |
#delete_campaign(id) ⇒ Object
190 191 192 |
# File 'lib/mailgunner.rb', line 190 def delete_campaign(id) delete("/v3/#{escape @domain}/campaigns/#{escape id}") end |
#delete_complaint(address) ⇒ Object
126 127 128 |
# File 'lib/mailgunner.rb', line 126 def delete_complaint(address) delete("/v3/#{escape @domain}/complaints/#{escape address}") end |
#delete_credentials(login) ⇒ Object
94 95 96 |
# File 'lib/mailgunner.rb', line 94 def delete_credentials(login) delete("/v3/domains/#{escape @domain}/credentials/#{escape login}") end |
#delete_domain(name) ⇒ Object
78 79 80 |
# File 'lib/mailgunner.rb', line 78 def delete_domain(name) delete("/v3/domains/#{escape name}") end |
#delete_list(address) ⇒ Object
234 235 236 |
# File 'lib/mailgunner.rb', line 234 def delete_list(address) delete("/v3/lists/#{escape address}") end |
#delete_list_member(list_address, member_address) ⇒ Object
254 255 256 |
# File 'lib/mailgunner.rb', line 254 def delete_list_member(list_address, member_address) delete("/v3/lists/#{escape list_address}/members/#{escape member_address}") end |
#delete_message(key) ⇒ Object
62 63 64 |
# File 'lib/mailgunner.rb', line 62 def (key) delete("/v3/domains/#{escape @domain}/messages/#{escape key}") end |
#delete_route(id) ⇒ Object
170 171 172 |
# File 'lib/mailgunner.rb', line 170 def delete_route(id) delete("/v3/routes/#{escape id}") end |
#delete_unsubscribe(address_or_id) ⇒ Object
106 107 108 |
# File 'lib/mailgunner.rb', line 106 def delete_unsubscribe(address_or_id) delete("/v3/#{escape @domain}/unsubscribes/#{escape address_or_id}") end |
#get_bounce(address) ⇒ Object
134 135 136 |
# File 'lib/mailgunner.rb', line 134 def get_bounce(address) get("/v3/#{escape @domain}/bounces/#{escape address}") end |
#get_bounces(params = {}) ⇒ Object
130 131 132 |
# File 'lib/mailgunner.rb', line 130 def get_bounces(params = {}) get("/v3/#{escape @domain}/bounces", params) end |
#get_campaign(id) ⇒ Object
178 179 180 |
# File 'lib/mailgunner.rb', line 178 def get_campaign(id) get("/v3/#{escape @domain}/campaigns/#{escape id}") end |
#get_campaign_clicks(campaign_id, params = {}) ⇒ Object
202 203 204 |
# File 'lib/mailgunner.rb', line 202 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
214 215 216 |
# File 'lib/mailgunner.rb', line 214 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
194 195 196 |
# File 'lib/mailgunner.rb', line 194 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
206 207 208 |
# File 'lib/mailgunner.rb', line 206 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
198 199 200 |
# File 'lib/mailgunner.rb', line 198 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
210 211 212 |
# File 'lib/mailgunner.rb', line 210 def get_campaign_unsubscribes(campaign_id, params = {}) get("/v3/#{escape @domain}/campaigns/#{escape campaign_id}/unsubscribes", params) end |
#get_campaigns(params = {}) ⇒ Object
174 175 176 |
# File 'lib/mailgunner.rb', line 174 def get_campaigns(params = {}) get("/v3/#{escape @domain}/campaigns", params) end |
#get_complaint(address) ⇒ Object
118 119 120 |
# File 'lib/mailgunner.rb', line 118 def get_complaint(address) get("/v3/#{escape @domain}/complaints/#{escape address}") end |
#get_complaints(params = {}) ⇒ Object
114 115 116 |
# File 'lib/mailgunner.rb', line 114 def get_complaints(params = {}) get("/v3/#{escape @domain}/complaints", params) end |
#get_credentials ⇒ Object
82 83 84 |
# File 'lib/mailgunner.rb', line 82 def get_credentials get("/v3/domains/#{escape @domain}/credentials") end |
#get_domain(name) ⇒ Object
70 71 72 |
# File 'lib/mailgunner.rb', line 70 def get_domain(name) get("/v3/domains/#{escape name}") end |
#get_domains(params = {}) ⇒ Object
66 67 68 |
# File 'lib/mailgunner.rb', line 66 def get_domains(params = {}) get('/v3/domains', params) end |
#get_events(params = {}) ⇒ Object
150 151 152 |
# File 'lib/mailgunner.rb', line 150 def get_events(params = {}) get("/v3/#{escape @domain}/events", params) end |
#get_list(address) ⇒ Object
222 223 224 |
# File 'lib/mailgunner.rb', line 222 def get_list(address) get("/v3/lists/#{escape address}") end |
#get_list_member(list_address, member_address) ⇒ Object
242 243 244 |
# File 'lib/mailgunner.rb', line 242 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
238 239 240 |
# File 'lib/mailgunner.rb', line 238 def get_list_members(list_address, params = {}) get("/v3/lists/#{escape list_address}/members", params) end |
#get_list_stats(list_address) ⇒ Object
258 259 260 |
# File 'lib/mailgunner.rb', line 258 def get_list_stats(list_address) get("/v3/lists/#{escape list_address}/stats") end |
#get_lists(params = {}) ⇒ Object
218 219 220 |
# File 'lib/mailgunner.rb', line 218 def get_lists(params = {}) get('/v3/lists', params) end |
#get_message(key) ⇒ Object
42 43 44 |
# File 'lib/mailgunner.rb', line 42 def (key) get("/v3/domains/#{escape @domain}/messages/#{escape key}") end |
#get_mime_message(key) ⇒ Object
46 47 48 |
# File 'lib/mailgunner.rb', line 46 def (key) get("/v3/domains/#{escape @domain}/messages/#{escape key}", {}, {'Accept' => 'message/rfc2822'}) end |
#get_route(id) ⇒ Object
158 159 160 |
# File 'lib/mailgunner.rb', line 158 def get_route(id) get("/v3/routes/#{escape id}") end |
#get_routes(params = {}) ⇒ Object
154 155 156 |
# File 'lib/mailgunner.rb', line 154 def get_routes(params = {}) get('/v3/routes', params) end |
#get_stats(params = {}) ⇒ Object
146 147 148 |
# File 'lib/mailgunner.rb', line 146 def get_stats(params = {}) get("/v3/#{escape @domain}/stats", params) end |
#get_unsubscribe(address) ⇒ Object
102 103 104 |
# File 'lib/mailgunner.rb', line 102 def get_unsubscribe(address) get("/v3/#{escape @domain}/unsubscribes/#{escape address}") end |
#get_unsubscribes(params = {}) ⇒ Object
98 99 100 |
# File 'lib/mailgunner.rb', line 98 def get_unsubscribes(params = {}) get("/v3/#{escape @domain}/unsubscribes", params) end |
#parse_addresses(values) ⇒ Object
38 39 40 |
# File 'lib/mailgunner.rb', line 38 def parse_addresses(values) get('/v3/address/parse', addresses: Array(values).join(',')) end |
#send_message(attributes = {}) ⇒ Object
50 51 52 |
# File 'lib/mailgunner.rb', line 50 def (attributes = {}) post("/v3/#{escape @domain}/messages", attributes) end |
#send_mime(mail) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/mailgunner.rb', line 54 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
186 187 188 |
# File 'lib/mailgunner.rb', line 186 def update_campaign(id, attributes = {}) put("/v3/#{escape @domain}/campaigns/#{escape id}", attributes) end |
#update_credentials(login, attributes) ⇒ Object
90 91 92 |
# File 'lib/mailgunner.rb', line 90 def update_credentials(login, attributes) put("/v3/domains/#{escape @domain}/credentials/#{escape login}", attributes) end |
#update_list(address, attributes = {}) ⇒ Object
230 231 232 |
# File 'lib/mailgunner.rb', line 230 def update_list(address, attributes = {}) put("/v3/lists/#{escape address}", attributes) end |
#update_list_member(list_address, member_address, member_attributes) ⇒ Object
250 251 252 |
# File 'lib/mailgunner.rb', line 250 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
166 167 168 |
# File 'lib/mailgunner.rb', line 166 def update_route(id, attributes = {}) put("/v3/routes/#{escape id}", attributes) end |
#validate_address(value) ⇒ Object
34 35 36 |
# File 'lib/mailgunner.rb', line 34 def validate_address(value) get('/v3/address/validate', address: value) end |