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_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_list(address) ⇒ Object
- #delete_list_member(list_address, member_address) ⇒ 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_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_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_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.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mailgunner.rb', line 11 def initialize( = {}) @domain = .fetch(:domain) { ENV['MAILGUN_SMTP_LOGIN'].to_s.split('@').last } @api_key = .fetch(:api_key) { ENV.fetch('MAILGUN_API_KEY') } if .has_key?(:json) Kernel.warn 'Mailgunner::Client :json option is deprecated' @json = [:json] else @json = JSON end @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.
9 10 11 |
# File 'lib/mailgunner.rb', line 9 def api_key @api_key end |
#domain ⇒ Object
Returns the value of attribute domain.
9 10 11 |
# File 'lib/mailgunner.rb', line 9 def domain @domain end |
#http ⇒ Object
Returns the value of attribute http.
9 10 11 |
# File 'lib/mailgunner.rb', line 9 def http @http end |
Instance Method Details
#add_bounce(attributes = {}) ⇒ Object
101 102 103 |
# File 'lib/mailgunner.rb', line 101 def add_bounce(attributes = {}) post("/v2/#{escape @domain}/bounces", attributes) end |
#add_campaign(attributes = {}) ⇒ Object
145 146 147 |
# File 'lib/mailgunner.rb', line 145 def add_campaign(attributes = {}) post("/v2/#{escape @domain}/campaigns", attributes) end |
#add_complaint(attributes = {}) ⇒ Object
85 86 87 |
# File 'lib/mailgunner.rb', line 85 def add_complaint(attributes = {}) post("/v2/#{escape @domain}/complaints", attributes) end |
#add_domain(attributes = {}) ⇒ Object
57 58 59 |
# File 'lib/mailgunner.rb', line 57 def add_domain(attributes = {}) post('/v2/domains', attributes) end |
#add_list(attributes = {}) ⇒ Object
189 190 191 |
# File 'lib/mailgunner.rb', line 189 def add_list(attributes = {}) post('/v2/lists', attributes) end |
#add_list_member(list_address, member_attributes) ⇒ Object
209 210 211 |
# File 'lib/mailgunner.rb', line 209 def add_list_member(list_address, member_attributes) post("/v2/lists/#{escape list_address}/members", member_attributes) end |
#add_route(attributes = {}) ⇒ Object
125 126 127 |
# File 'lib/mailgunner.rb', line 125 def add_route(attributes = {}) post('/v2/routes', attributes) end |
#add_unsubscribe(attributes = {}) ⇒ Object
73 74 75 |
# File 'lib/mailgunner.rb', line 73 def add_unsubscribe(attributes = {}) post("/v2/#{escape @domain}/unsubscribes", attributes) end |
#delete_bounce(address) ⇒ Object
105 106 107 |
# File 'lib/mailgunner.rb', line 105 def delete_bounce(address) delete("/v2/#{escape @domain}/bounces/#{escape address}") end |
#delete_campaign(id) ⇒ Object
153 154 155 |
# File 'lib/mailgunner.rb', line 153 def delete_campaign(id) delete("/v2/#{escape @domain}/campaigns/#{escape id}") end |
#delete_complaint(address) ⇒ Object
89 90 91 |
# File 'lib/mailgunner.rb', line 89 def delete_complaint(address) delete("/v2/#{escape @domain}/complaints/#{escape address}") end |
#delete_list(address) ⇒ Object
197 198 199 |
# File 'lib/mailgunner.rb', line 197 def delete_list(address) delete("/v2/lists/#{escape address}") end |
#delete_list_member(list_address, member_address) ⇒ Object
217 218 219 |
# File 'lib/mailgunner.rb', line 217 def delete_list_member(list_address, member_address) delete("/v2/lists/#{escape list_address}/members/#{escape member_address}") end |
#delete_route(id) ⇒ Object
133 134 135 |
# File 'lib/mailgunner.rb', line 133 def delete_route(id) delete("/v2/routes/#{escape id}") end |
#delete_unsubscribe(address_or_id) ⇒ Object
69 70 71 |
# File 'lib/mailgunner.rb', line 69 def delete_unsubscribe(address_or_id) delete("/v2/#{escape @domain}/unsubscribes/#{escape address_or_id}") end |
#get_bounce(address) ⇒ Object
97 98 99 |
# File 'lib/mailgunner.rb', line 97 def get_bounce(address) get("/v2/#{escape @domain}/bounces/#{escape address}") end |
#get_bounces(params = {}) ⇒ Object
93 94 95 |
# File 'lib/mailgunner.rb', line 93 def get_bounces(params = {}) get("/v2/#{escape @domain}/bounces", params) end |
#get_campaign(id) ⇒ Object
141 142 143 |
# File 'lib/mailgunner.rb', line 141 def get_campaign(id) get("/v2/#{escape @domain}/campaigns/#{escape id}") end |
#get_campaign_clicks(campaign_id, params = {}) ⇒ Object
165 166 167 |
# File 'lib/mailgunner.rb', line 165 def get_campaign_clicks(campaign_id, params = {}) get("/v2/#{escape @domain}/campaigns/#{escape campaign_id}/clicks", params) end |
#get_campaign_complaints(campaign_id, params = {}) ⇒ Object
177 178 179 |
# File 'lib/mailgunner.rb', line 177 def get_campaign_complaints(campaign_id, params = {}) get("/v2/#{escape @domain}/campaigns/#{escape campaign_id}/complaints", params) end |
#get_campaign_events(campaign_id, params = {}) ⇒ Object
157 158 159 |
# File 'lib/mailgunner.rb', line 157 def get_campaign_events(campaign_id, params = {}) get("/v2/#{escape @domain}/campaigns/#{escape campaign_id}/events", params) end |
#get_campaign_opens(campaign_id, params = {}) ⇒ Object
169 170 171 |
# File 'lib/mailgunner.rb', line 169 def get_campaign_opens(campaign_id, params = {}) get("/v2/#{escape @domain}/campaigns/#{escape campaign_id}/opens", params) end |
#get_campaign_stats(campaign_id, params = {}) ⇒ Object
161 162 163 |
# File 'lib/mailgunner.rb', line 161 def get_campaign_stats(campaign_id, params = {}) get("/v2/#{escape @domain}/campaigns/#{escape campaign_id}/stats", params) end |
#get_campaign_unsubscribes(campaign_id, params = {}) ⇒ Object
173 174 175 |
# File 'lib/mailgunner.rb', line 173 def get_campaign_unsubscribes(campaign_id, params = {}) get("/v2/#{escape @domain}/campaigns/#{escape campaign_id}/unsubscribes", params) end |
#get_campaigns(params = {}) ⇒ Object
137 138 139 |
# File 'lib/mailgunner.rb', line 137 def get_campaigns(params = {}) get("/v2/#{escape @domain}/campaigns", params) end |
#get_complaint(address) ⇒ Object
81 82 83 |
# File 'lib/mailgunner.rb', line 81 def get_complaint(address) get("/v2/#{escape @domain}/complaints/#{escape address}") end |
#get_complaints(params = {}) ⇒ Object
77 78 79 |
# File 'lib/mailgunner.rb', line 77 def get_complaints(params = {}) get("/v2/#{escape @domain}/complaints", params) end |
#get_domain(name) ⇒ Object
53 54 55 |
# File 'lib/mailgunner.rb', line 53 def get_domain(name) get("/v2/domains/#{escape name}") end |
#get_domains(params = {}) ⇒ Object
49 50 51 |
# File 'lib/mailgunner.rb', line 49 def get_domains(params = {}) get('/v2/domains', params) end |
#get_events(params = {}) ⇒ Object
113 114 115 |
# File 'lib/mailgunner.rb', line 113 def get_events(params = {}) get("/v2/#{escape @domain}/events", params) end |
#get_list(address) ⇒ Object
185 186 187 |
# File 'lib/mailgunner.rb', line 185 def get_list(address) get("/v2/lists/#{escape address}") end |
#get_list_member(list_address, member_address) ⇒ Object
205 206 207 |
# File 'lib/mailgunner.rb', line 205 def get_list_member(list_address, member_address) get("/v2/lists/#{escape list_address}/members/#{escape member_address}") end |
#get_list_members(list_address, params = {}) ⇒ Object
201 202 203 |
# File 'lib/mailgunner.rb', line 201 def get_list_members(list_address, params = {}) get("/v2/lists/#{escape list_address}/members", params) end |
#get_list_stats(list_address) ⇒ Object
221 222 223 |
# File 'lib/mailgunner.rb', line 221 def get_list_stats(list_address) get("/v2/lists/#{escape list_address}/stats") end |
#get_lists(params = {}) ⇒ Object
181 182 183 |
# File 'lib/mailgunner.rb', line 181 def get_lists(params = {}) get('/v2/lists', params) end |
#get_route(id) ⇒ Object
121 122 123 |
# File 'lib/mailgunner.rb', line 121 def get_route(id) get("/v2/routes/#{escape id}") end |
#get_routes(params = {}) ⇒ Object
117 118 119 |
# File 'lib/mailgunner.rb', line 117 def get_routes(params = {}) get('/v2/routes', params) end |
#get_stats(params = {}) ⇒ Object
109 110 111 |
# File 'lib/mailgunner.rb', line 109 def get_stats(params = {}) get("/v2/#{escape @domain}/stats", params) end |
#get_unsubscribe(address) ⇒ Object
65 66 67 |
# File 'lib/mailgunner.rb', line 65 def get_unsubscribe(address) get("/v2/#{escape @domain}/unsubscribes/#{escape address}") end |
#get_unsubscribes(params = {}) ⇒ Object
61 62 63 |
# File 'lib/mailgunner.rb', line 61 def get_unsubscribes(params = {}) get("/v2/#{escape @domain}/unsubscribes", params) end |
#parse_addresses(values) ⇒ Object
33 34 35 |
# File 'lib/mailgunner.rb', line 33 def parse_addresses(values) get('/v2/address/parse', addresses: Array(values).join(',')) end |
#send_message(attributes = {}) ⇒ Object
37 38 39 |
# File 'lib/mailgunner.rb', line 37 def (attributes = {}) post("/v2/#{escape @domain}/messages", attributes) end |
#send_mime(mail) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/mailgunner.rb', line 41 def send_mime(mail) to = ['to', Array(mail.to).join(',')] = ['message', mail.encoded, {filename: 'message.mime'}] multipart_post("/v2/#{escape @domain}/messages.mime", [to, ]) end |
#update_campaign(id, attributes = {}) ⇒ Object
149 150 151 |
# File 'lib/mailgunner.rb', line 149 def update_campaign(id, attributes = {}) put("/v2/#{escape @domain}/campaigns/#{escape id}", attributes) end |
#update_list(address, attributes = {}) ⇒ Object
193 194 195 |
# File 'lib/mailgunner.rb', line 193 def update_list(address, attributes = {}) put("/v2/lists/#{escape address}", attributes) end |
#update_list_member(list_address, member_address, member_attributes) ⇒ Object
213 214 215 |
# File 'lib/mailgunner.rb', line 213 def update_list_member(list_address, member_address, member_attributes) put("/v2/lists/#{escape list_address}/members/#{escape member_address}", member_attributes) end |
#update_route(id, attributes = {}) ⇒ Object
129 130 131 |
# File 'lib/mailgunner.rb', line 129 def update_route(id, attributes = {}) put("/v2/routes/#{escape id}", attributes) end |
#validate_address(value) ⇒ Object
29 30 31 |
# File 'lib/mailgunner.rb', line 29 def validate_address(value) get('/v2/address/validate', address: value) end |