Class: Plivo::XPlivoSignature

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(signature, uri, post_params, auth_token) ⇒ XPlivoSignature

Returns a new instance of XPlivoSignature.



16
17
18
19
20
21
# File 'lib/plivo.rb', line 16

def initialize(signature, uri, post_params, auth_token)
    @signature = signature
    @uri = uri
    @post_params = post_params
    @auth_token = auth_token
end

Instance Attribute Details

#auth_tokenObject

Returns the value of attribute auth_token.



14
15
16
# File 'lib/plivo.rb', line 14

def auth_token
  @auth_token
end

#post_paramsObject

Returns the value of attribute post_params.



14
15
16
# File 'lib/plivo.rb', line 14

def post_params
  @post_params
end

#signatureObject

Returns the value of attribute signature.



14
15
16
# File 'lib/plivo.rb', line 14

def signature
  @signature
end

#uriObject

Returns the value of attribute uri.



14
15
16
# File 'lib/plivo.rb', line 14

def uri
  @uri
end

Instance Method Details

#is_valid?Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'lib/plivo.rb', line 23

def is_valid?
    uri = @post_params.sort.reduce(@uri) {|_, (key, val)| _ += key + val}
    return Base64.encode64(OpenSSL::HMAC.digest('sha1', @auth_token, uri)).chomp.eql? @signature
end