class Mandrill::API
Constants
- API_URL
- API_VERSION
Mandrill
API
Documentation: mandrillapp.com/api/docs- AUTH_URL
Public Class Methods
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