Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed merge errors

  • Loading branch information...
commit 8312ed2bb52cedbdc19f160ce2a2ffeb7a73fff3 2 parents 9ccf152 + 62b1d4c
Stafford Brooke authored
View
26 README.markdown
@@ -13,10 +13,27 @@ A paid MailChimp account, MailChimp API key, and Amazon AWS account with SES rea
##Usage
+<<<<<<< HEAD
Configure your app with your API key:
Uakari.apikey = 'your-api-key'
+=======
+There are a few ways to use Uakari.
+
+You can create an instance of the API wrapper:
+
+ u = Uakari.new("your_api_key")
+
+You can set your api_key globally and call class methods:
+
+ Uakari.api_key = "your_api_key"
+ Uakari.send_email(...)
+
+You can also set the environment variable 'MC_API_KEY' and Uakari will use it when you create an instance:
+
+ u = Uakari.new
+>>>>>>> 62b1d4c994213af3b4f313c5f48338527488b37a
### Sending a message
@@ -45,7 +62,15 @@ You can tell ActionMailer to send mail using Mailchimp STS by adding the follow
config.action_mailer.delivery_method = :uakari
config.action_mailer.uakari_settings = {
+<<<<<<< HEAD
:from_name => "From name"
+=======
+ :api_key => "your_mailchimp_apikey",
+ :track_clicks => true,
+ :track_opens => true,
+ :from_name => "Change Me"
+ :tags => ["awesome", "tags", "here"] #optional STS tags
+>>>>>>> 62b1d4c994213af3b4f313c5f48338527488b37a
}
These setting will allow you to use ActionMailer as you normally would, any calls to mail() will be sent using Mailchimp STS
@@ -66,6 +91,7 @@ Uakari defaults to a 30 second timeout. You can optionally set your own timeout
* [Loren Norman](https://github.com/lorennorman)
* [Andy Lindeman](https://github.com/alindeman)
* [Ali Faiz](https://github.com/alif)
+* [Calvin Yu](https://github.com/cyu)
* Rails for camelize gsub
##Copyrights
View
2  VERSION
@@ -1 +1 @@
-0.2.2
+0.2.3
View
50 lib/handlers/uakari_delivery_handler.rb
@@ -1,24 +1,30 @@
-module Uakari
- class DeliveryHandler
- attr_accessor :settings
-
- def initialize options
- self.settings = {:track_opens => true, :track_clicks => true, :tags => nil}.merge(options)
- end
- def deliver! message
- Uakari.send_email({
- :track_opens => Uakari.options[:track_opens],
- :track_clicks => Uakari.options[:track_clicks],
- :message => {
- :subject => message.subject,
- :html => message.text_part.body,
- :text => message.html_part.body,
- :from_name => settings[:from_name],
- :from_email => message.from.first,
- :to_email => message.to
- }
- })
- end
+require 'action_mailer'
+
+class UakariDeliveryHandler
+ attr_accessor :settings
+
+ def initialize options
+ self.settings = {:track_opens => true, :track_clicks => true}.merge(options)
end
+
+ def deliver! message
+ message_payload = {
+ :track_opens => settings[:track_opens],
+ :track_clicks => settings[:track_clicks],
+ :message => {
+ :subject => message.subject,
+ :html => message.html_part.body,
+ :text => message.text_part.body,
+ :from_name => settings[:from_name],
+ :from_email => message.from.first,
+ :to_email => message.to
+ }
+ }
+
+ message_payload[:tags] = settings[:tags] if settings[:tags]
+
+ Uakari.new(settings[:api_key]).send_email(message_payload)
+ end
+
end
-ActionMailer::Base.add_delivery_method :uakari, Uakari::DeliveryHandler
+ActionMailer::Base.add_delivery_method :uakari, UakariDeliveryHandler
View
85 lib/uakari.rb
@@ -5,49 +5,58 @@
require File.join(File.dirname(__FILE__), 'handlers', 'uakari_delivery_handler')
end
-module Uakari
+class Uakari
include HTTParty
default_timeout 30
-
- class << self
- attr_accessor :apikey, :timeout, :options
-
- def base_api_url
- dc = self.apikey.blank? ? '' : "#{self.apikey.split("-").last}."
- "https://#{dc}sts.mailchimp.com/1.0/"
- end
- def call(method, params = {})
- url = "#{base_api_url}#{method}"
- params = self.default_params.merge(params)
- response = self.post(url, :body => params, :timeout => self.timeout)
- begin
- response = JSON.parse(response.body)
- rescue
- response = response.body
- end
- response
- end
-
- def default_params(extra_params = {})
- {
- :apikey => self.apikey,
- :options => {
- :track_opens => true,
- :track_clicks => true
- }
- }.merge(extra_params)
- end
+ attr_accessor :api_key, :timeout, :options
- def method_missing(method, *args)
- method = method.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } #Thanks for the gsub, Rails
- args = {} unless args.length > 0
- args = args[0] if (args.class.to_s == "Array")
- call(method, args)
+ def initialize(api_key = nil, extra_params = {})
+ @api_key = api_key || ENV['MC_API_KEY'] || self.class.api_key
+ @default_params = {
+ :apikey => @api_key,
+ :options => {
+ :track_opens => true,
+ :track_clicks => true
+ }
+ }.merge(extra_params)
+ end
+
+ def api_key=(value)
+ @api_key = value
+ @default_params = @default_params.merge({:apikey => @api_key})
+ end
+
+ def base_api_url
+ dc = @api_key.blank? ? '' : "#{@api_key.split("-").last}."
+ "https://#{dc}sts.mailchimp.com/1.0/"
+ end
+
+ def call(method, params = {})
+ url = "#{base_api_url}#{method}"
+ params = @default_params.merge(params)
+ response = self.class.post(url, :body => params, :timeout => @timeout)
+
+ begin
+ response = JSON.parse(response.body)
+ rescue
+ response = response.body
end
-
- def options
- @options ||= {:track_opens => true, :track_clicks => true}
+ response
+ end
+
+ def method_missing(method, *args)
+ method = method.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } #Thanks for the gsub, Rails
+ args = {} unless args.length > 0
+ args = args[0] if (args.class.to_s == "Array")
+ call(method, args)
+ end
+
+ class << self
+ attr_accessor :api_key
+
+ def method_missing(sym, *args, &block)
+ new(self.api_key).send(sym, *args, &block)
end
end
end
View
4 uakari.gemspec
@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{uakari}
- s.version = "0.2.2"
+ s.version = "0.2.3"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = [%q{Amro Mousa}]
- s.date = %q{2011-08-29}
+ s.date = %q{2011-09-02}
s.description = %q{Uakari a API wrapper for the MailChimp STS API (1.0), which wraps Amazon SES.}
s.email = %q{amromousa@gmail.com}
s.extra_rdoc_files = [
Please sign in to comment.
Something went wrong with that request. Please try again.