Module: Mailgun

Defined in:
lib/mailgun/secure.rb,
lib/mailgun/log.rb,
lib/mailgun/base.rb,
lib/mailgun/list.rb,
lib/mailgun/route.rb,
lib/mailgun/bounce.rb,
lib/mailgun/client.rb,
lib/mailgun/client.rb,
lib/mailgun/domain.rb,
lib/mailgun/address.rb,
lib/mailgun/mailbox.rb,
lib/mailgun/message.rb,
lib/mailgun/webhook.rb,
lib/mailgun/complaint.rb,
lib/mailgun/list/member.rb,
lib/mailgun/unsubscribe.rb,
lib/mailgun/mailgun_error.rb

Overview

verifySignature: function(timestamp, token, signature, minutes_offset)

var offset = Math.round((new Date()).getTime() / 1000) - (minutes_offset || 5) * 60;
if(timestamp < offset)
  return false;

var hmac = crypto.createHmac('sha256', api_key);
hmac.update(timestamp + token);
return signature == hmac.digest('hex');

,

Defined Under Namespace

Classes: Address, BadRequest, Base, Bounce, Client, ClientError, Complaint, Domain, Error, ErrorBase, Log, Mailbox, MailingList, Message, NotFound, ResquestFailed, Route, Secure, ServerError, Unauthorized, Unsubscribe, Webhook

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_keyObject

Returns the value of attribute api_key.



117
118
119
# File 'lib/mailgun/base.rb', line 117

def api_key
  @api_key
end

.api_versionObject

Returns the value of attribute api_version.



117
118
119
# File 'lib/mailgun/base.rb', line 117

def api_version
  @api_version
end

.domainObject

Returns the value of attribute domain.



117
118
119
# File 'lib/mailgun/base.rb', line 117

def domain
  @domain
end

.mailgun_hostObject

Returns the value of attribute mailgun_host.



117
118
119
# File 'lib/mailgun/base.rb', line 117

def mailgun_host
  @mailgun_host
end

.protocolObject

Returns the value of attribute protocol.



117
118
119
# File 'lib/mailgun/base.rb', line 117

def protocol
  @protocol
end

.public_api_keyObject

Returns the value of attribute public_api_key.



117
118
119
# File 'lib/mailgun/base.rb', line 117

def public_api_key
  @public_api_key
end

.test_modeObject

Returns the value of attribute test_mode.



117
118
119
# File 'lib/mailgun/base.rb', line 117

def test_mode
  @test_mode
end

.webhook_urlObject

Returns the value of attribute webhook_url.



117
118
119
# File 'lib/mailgun/base.rb', line 117

def webhook_url
  @webhook_url
end

Class Method Details

.configure {|_self| ... } ⇒ Object Also known as: config

Yields:

  • (_self)

Yield Parameters:

  • _self (Mailgun)

    the object that the method was called on



126
127
128
129
# File 'lib/mailgun/base.rb', line 126

def configure
  yield self
  true
end

.submit(method, url, parameters = {}) ⇒ Object

Submits the API call to the Mailgun server



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/mailgun/base.rb', line 91

def self.submit(method, url, parameters={})
  begin
    JSON.parse(Client.new(url).send(method, parameters))
  rescue => e
    error_code = e.http_code
    error_message = begin
      JSON(e.http_body)["message"]
    rescue JSON::ParserError
      ''
    end
    error = Mailgun::Error.new(
      :code => error_code || nil,
      :message => error_message || nil
    )
    if error.handle.kind_of? Mailgun::ErrorBase
      raise error.handle
    else
      raise error
    end
  end
end