Class: MailsocioQA::TestClient
- Inherits:
-
Object
- Object
- MailsocioQA::TestClient
- Defined in:
- lib/mailsocio_qa/test_client.rb
Instance Attribute Summary collapse
-
#account_id ⇒ Object
Returns the value of attribute account_id.
-
#custom_tracking_domain ⇒ Object
Returns the value of attribute custom_tracking_domain.
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
- #accounts_url(account_id = nil) ⇒ Object
- #app_url(path) ⇒ Object
- #clean_messages(user = 'john') ⇒ Object
- #create_account(attrs = {}) ⇒ Object
- #deliver(fields = {}, &block) ⇒ Object
-
#initialize(settings) ⇒ TestClient
constructor
A new instance of TestClient.
- #newsletter_statistics(newsletter_id) ⇒ Object
- #newsletter_statistics_url(newsletter_id) ⇒ Object
- #read_account ⇒ Object
- #read_message(user = 'john') ⇒ Object
- #retriever(user) ⇒ Object
Constructor Details
#initialize(settings) ⇒ TestClient
Returns a new instance of TestClient.
8 9 10 |
# File 'lib/mailsocio_qa/test_client.rb', line 8 def initialize(settings) self.settings = settings end |
Instance Attribute Details
#account_id ⇒ Object
Returns the value of attribute account_id.
5 6 7 |
# File 'lib/mailsocio_qa/test_client.rb', line 5 def account_id @account_id end |
#custom_tracking_domain ⇒ Object
Returns the value of attribute custom_tracking_domain.
5 6 7 |
# File 'lib/mailsocio_qa/test_client.rb', line 5 def custom_tracking_domain @custom_tracking_domain end |
#settings ⇒ Object
Returns the value of attribute settings.
6 7 8 |
# File 'lib/mailsocio_qa/test_client.rb', line 6 def settings @settings end |
Instance Method Details
#accounts_url(account_id = nil) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/mailsocio_qa/test_client.rb', line 76 def accounts_url(account_id = nil) if account_id.blank? app_url('/api/accounts') else app_url("/api/accounts/#{account_id}") end end |
#app_url(path) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/mailsocio_qa/test_client.rb', line 88 def app_url(path) if custom_tracking_domain.blank? "http://app.#{settings.mailsocio.base_domain}#{path}" else "http://#{self.custom_tracking_domain}#{path}" end end |
#clean_messages(user = 'john') ⇒ Object
63 64 65 |
# File 'lib/mailsocio_qa/test_client.rb', line 63 def (user = 'john') retriever(user).delete_all end |
#create_account(attrs = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/mailsocio_qa/test_client.rb', line 12 def create_account(attrs = {}) attrs.reverse_merge!(api_key: settings.mailsocio.api_key) response = HTTPI.post(accounts_url, { account: attrs}.to_query) raise "Could not create account:\n#{response.body}" if response.error? JSON.parse(response.body).tap do |json| self.account_id = json['id'] end end |
#deliver(fields = {}, &block) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/mailsocio_qa/test_client.rb', line 36 def deliver(fields = {}, &block) config = settings.mailsocio.mail fields.reverse_merge!( 'X-Account-Id' => account_id, 'X-Api-Key' => settings.mailsocio.api_key ) fields.reverse_merge!(config.) Mail::Message.new(fields, &block).tap do |mail| mail.subject ||= 'Good news, everyone!' delivery = config.delivery mail.delivery_method(delivery.method.to_sym, delivery.settings.symbolize_keys) mail.deliver end end |
#newsletter_statistics(newsletter_id) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/mailsocio_qa/test_client.rb', line 29 def () response = HTTPI.get(()) raise "Could not get newsletter statistics:\n#{response.body}" if response.error? JSON.parse(response.body) end |
#newsletter_statistics_url(newsletter_id) ⇒ Object
84 85 86 |
# File 'lib/mailsocio_qa/test_client.rb', line 84 def () app_url("/api/accounts/#{account_id}/newsletters/#{}/statistics") end |
#read_account ⇒ Object
22 23 24 25 26 27 |
# File 'lib/mailsocio_qa/test_client.rb', line 22 def read_account response = HTTPI.get(accounts_url(self.account_id)) raise "Could not read account:\n#{response.body}" if response.error? JSON.parse(response.body) end |
#read_message(user = 'john') ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/mailsocio_qa/test_client.rb', line 52 def (user = 'john') 10.times do = retriever(user).first(:delete_after_find => true) return if .present? sleep 10 end raise 'Could not read message' end |
#retriever(user) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/mailsocio_qa/test_client.rb', line 67 def retriever(user) address = settings.trap.addresses[user] server = settings.trap.server settings = server.settings.symbolize_keys settings.merge!(user_name: address) Mail::Configuration.instance.retriever_method(server.method.to_sym, settings) end |