Class: Mailtrain::Client
- Inherits:
-
Object
- Object
- Mailtrain::Client
- Defined in:
- lib/mailtrain/client.rb
Instance Method Summary collapse
-
#blacklist(start = 0, limit = 10000, search = '') ⇒ Object
Get list of blacklisted emails.
-
#block(email) ⇒ Object
Add email to blacklist.
- #data ⇒ Object
- #error ⇒ Object
-
#initialize(host_url, access_token = nil) ⇒ Client
constructor
A new instance of Client.
-
#subscribe(list_id, email, first_name = nil, last_name = nil, timezone = nil, force_subscribe = true) ⇒ Object
Add subscription.
- #success? ⇒ Boolean
-
#unblock(email) ⇒ Object
delete email to blacklist.
- #unsubscribe(list_id, email) ⇒ Object
Constructor Details
#initialize(host_url, access_token = nil) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 |
# File 'lib/mailtrain/client.rb', line 8 def initialize(host_url, access_token = nil) @url = host_url @access_token = access_token || ENV['MAILTRAIN_ACCESS_TOKEN'] @response = nil end |
Instance Method Details
#blacklist(start = 0, limit = 10000, search = '') ⇒ Object
Get list of blacklisted emails
33 34 35 36 37 38 |
# File 'lib/mailtrain/client.rb', line 33 def blacklist(start=0, limit=10000, search='') response = connection.get "/api/blacklist/get?access_token=#{@access_token}&start=#{start}&limit=#{limit}&search=#{search}" @response = Response.new response.body data end |
#block(email) ⇒ Object
Add email to blacklist
41 42 43 44 45 46 |
# File 'lib/mailtrain/client.rb', line 41 def block(email) response = connection.post "/api/blacklist/add?access_token=#{@access_token}", {email: email} @response = Response.new response.body success? end |
#data ⇒ Object
64 65 66 |
# File 'lib/mailtrain/client.rb', line 64 def data @response.data end |
#error ⇒ Object
60 61 62 |
# File 'lib/mailtrain/client.rb', line 60 def error @response. end |
#subscribe(list_id, email, first_name = nil, last_name = nil, timezone = nil, force_subscribe = true) ⇒ Object
Add subscription
15 16 17 18 19 20 21 22 23 |
# File 'lib/mailtrain/client.rb', line 15 def subscribe(list_id, email, first_name = nil, last_name = nil, timezone = nil, force_subscribe = true) response = connection.post "/api/subscribe/#{list_id}?access_token=#{@access_token}" do |req| params = {email: email, first_name: first_name, last_name: last_name, timezone: timezone, force_subscribe: force_subscribe}.select { |_, value| !value.nil? } req.body = params end @response = Response.new response.body success? end |
#success? ⇒ Boolean
56 57 58 |
# File 'lib/mailtrain/client.rb', line 56 def success? @response.respond_to?(:success?) ? @response.success? : false end |
#unblock(email) ⇒ Object
delete email to blacklist
49 50 51 52 53 54 |
# File 'lib/mailtrain/client.rb', line 49 def unblock(email) response = connection.post "/api/blacklist/delete?access_token=#{@access_token}", {email: email} @response = Response.new response.body success? end |
#unsubscribe(list_id, email) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/mailtrain/client.rb', line 25 def unsubscribe(list_id, email) response = connection.post "/api/unsubscribe/#{list_id}?access_token=#{@access_token}", {list: list_id, email: email} @response = Response.new response.body success? end |