Class: Twilio::Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/twiliolib.rb

Overview

Twilio Utility function and Request Validation class

Instance Method Summary collapse

Constructor Details

#initialize(id, token) ⇒ Object

initialize a twilio utils abject

Parameters:

  • Your (String, String)

    Twilio Acount SID/ID and Auth Token



373
374
375
376
# File 'lib/twiliolib.rb', line 373

def initialize(id, token)
  @id = id
  @token = token
end

Instance Method Details

#validateRequest(signature, url, params = {}) ⇒ Object



378
379
380
381
382
383
384
385
386
387
# File 'lib/twiliolib.rb', line 378

def validateRequest(signature, url, params = {})  
  sorted_post_params = params.sort
  data = url
  sorted_post_params.each do |pkey|
    data = data + pkey[0]+pkey[1]
  end
  digest = OpenSSL::Digest::Digest.new('sha1')
  expected = Base64.encode64(OpenSSL::HMAC.digest(digest, @token, data)).strip
  return expected == signature
end