Sha256: 9cef35c47365c396e98b75f4f9b51e45ca47230895b35dd486d239cd47c691f8

Contents?: true

Size: 916 Bytes

Versions: 10

Compression:

Stored size: 916 Bytes

Contents

module Twilio
  module REST
    module Utils

      def twilify(something)
        if something.is_a? Hash
          Hash[*something.to_a.map {|a| [twilify(a[0]).to_sym, a[1]]}.flatten]
        else
          something.to_s.split('_').map do |s|
            [s[0,1].capitalize, s[1..-1]].join
          end.join
        end
      end

      def detwilify(something)
        if something.is_a? Hash
          Hash[*something.to_a.map {|pair| [detwilify(pair[0]).to_sym, pair[1]]}.flatten]
        else
          something.to_s.gsub(/[A-Z][a-z]*/) {|s| "_#{s.downcase}"}.gsub(/^_/, '')
        end
      end

      def self.validate(auth_token, signature, url, params={})
        data = url + params.sort.to_s
        digest = OpenSSL::Digest::Digest.new('sha1')
        expected = Base64.encode64(OpenSSL::HMAC.digest(digest, auth_token, data)).strip
        return expected == signature
      end

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
twilio-ruby-0.4.0 lib/twilio-ruby/rest/utils.rb
twilio-ruby-0.3.3 lib/twilio-ruby/rest/utils.rb
twilio-ruby-0.3.2 lib/twilio-ruby/rest/utils.rb
twilio-ruby-0.3.1 lib/twilio-ruby/rest/utils.rb
twilio-ruby-0.3.0 lib/twilio-ruby/rest/utils.rb
twilio-ruby-0.2.1 lib/twilio-ruby/rest/utils.rb
twilio-ruby-0.2.0 lib/twilio-ruby/rest/utils.rb
twilio-ruby-0.1.2 lib/twilio-ruby/rest/utils.rb
twilio-ruby-0.1.1 lib/twilio-ruby/rest/utils.rb
twilio-ruby-0.1.0 lib/twilio-ruby/rest/utils.rb