require 'faraday' require_relative "mailstro/version" require_relative "mailstro/configuration" 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, :strategy end @strategy = RealStrategy @configuration = Configuration.new def self.configure yield(@configuration) && @configuration.validate! end def self.deliver(options) if options[:to].is_a?(Array) @strategy.list_deliver(options) else @strategy.deliver(options) end end def self.subscribe(contact_email, list_type, list_name) @strategy.subscribe(contact_email, list_type, list_name) end def self.unsubscribe(contact_email, list_type, list_name) @strategy.unsubscribe(contact_email, list_type, list_name) end 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