lib/mailstro.rb in mailstro-0.0.6 vs lib/mailstro.rb in mailstro-0.0.7
- old
+ new
@@ -1,36 +1,70 @@
+require 'faraday'
+
require_relative "mailstro/version"
require_relative "mailstro/configuration"
-require_relative "mailstro/resource"
require_relative "mailstro/error"
+require_relative "mailstro/resource"
require_relative "mailstro/delivery"
require_relative "mailstro/list_delivery"
require_relative "mailstro/list_subscribe"
require_relative "mailstro/list_unsubscribe"
module Mailstro
+
+ # Allows us to remove default behaviour during testing.
+ class RealStrategy
+ class << self
+ def deliver(options)
+ Delivery.new(options).deliver
+ end
+ def list_deliver(options)
+ ListDelivery.new(options).deliver
+ end
+ def subscribe(contact_email, list_type, list_name)
+ ListSubscribe.new(contact_email, list_type, list_name).deliver
+ end
+ def unsubscribe(contact_email, list_type, list_name)
+ ListUnsubscribe.new(contact_email, list_type, list_name).deliver
+ end
+ end
+ end
+
class << self
- attr_accessor :configuration
+ attr_accessor :configuration, :strategy
end
+ @strategy = RealStrategy
+ @configuration = Configuration.new
+
def self.configure
- self.configuration ||= Configuration.new
- yield(configuration)
- configuration.validate!
+ yield(@configuration) && @configuration.validate!
end
- def self.deliver(template_name, contact_email, data = {})
- Delivery.deliver(template_name, contact_email, data)
+ def self.deliver(options)
+ if options[:to].is_a?(Array)
+ @strategy.list_deliver(options)
+ else
+ @strategy.deliver(options)
+ end
end
- def self.list_deliver(template_name, list, data = {})
- ListDelivery.deliver(template_name, list, data)
+ def self.subscribe(contact_email, list_type, list_name)
+ @strategy.subscribe(contact_email, list_type, list_name)
end
- def self.list_subscribe(list_name, contact_email)
- ListSubscribe.subscribe(list_name, contact_email)
+ def self.unsubscribe(contact_email, list_type, list_name)
+ @strategy.unsubscribe(contact_email, list_type, list_name)
end
- def self.list_unsubscribe(list_name, contact_email)
- ListUnsubscribe.unsubscribe(list_name, contact_email)
+ def self.has_delivered?(template_name)
+ TestStrategy.has_delivered?(template_name)
+ end
+
+ def self.has_subscribed?(contact_email, list_type, list_name)
+ TestStrategy.has_subscribed?(contact_email, list_type, list_name)
+ end
+
+ def self.has_unsubscribed?(contact_email, list_type, list_name)
+ TestStrategy.has_unsubscribed?(contact_email, list_type, list_name)
end
end