class Mandrill::API

Constants

API_URL
API_VERSION

Mandrill API Documentation: mandrillapp.com/api/docs

AUTH_URL

Public Class Methods

authorization_url(app_id, redirect_url) click to toggle source

Generate a Mandrill authorization_url. Returns a URL to redirect users to so that they will be prompted to enter their Mandrill username and password to authorize a connection between your application and their Mandrill account.

If authorized successfully, a POST request will be sent to the redirect_url with a “key” parameter containing the API key for that user's Mandrill account. Be sure to store this key somewhere, as you will need it to run API requests later.

If authorization fails for some reason, an “error” parameter will be present in the POST request, containing an error message.

Example

redirect_to Mandrill::API.authorization_url(“12345”,“example.com/callback”)

# File lib/mandrill/api.rb, line 30
def self.authorization_url(app_id, redirect_url)
  "#{AUTH_URL}?id=#{app_id}&redirect_url=#{URI.escape(redirect_url, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}"
end
new(api_key, config = {}) click to toggle source

Initialize

# File lib/mandrill/api.rb, line 35
def initialize(api_key, config = {})
  defaults = {
    :api_version => API_VERSION,
    :format => 'json'
  }
  @config = defaults.merge(config).freeze
  @api_key = api_key
end

Public Instance Methods

call(api_method, *args) click to toggle source

Call the API

# File lib/mandrill/api.rb, line 67
def call(api_method, *args)
  req_endpoint = "#{API_URL}/#{@config[:api_version]}/#{api_method.to_s}/#{args.first.to_s}.#{@config[:format]}"
  req_body = {:key => @api_key}
  req_body.merge!(args.last) if args.last.is_a?(Hash)
  #ensure request is in json format if required
  if @config[:format] == "json"
    req_body = req_body.to_json
  end
  @response = HTTPI.post(req_endpoint, req_body.to_json.to_s)
end