Module: UserVoice

Defined in:
lib/uservoice/client.rb,
lib/uservoice/version.rb,
lib/uservoice/collection.rb,
lib/uservoice/user_voice.rb

Defined Under Namespace

Classes: APIError, Client, Collection

Constant Summary collapse

VERSION =
"0.0.11"
EMAIL_FORMAT =
%r{^(\w[-+.\w!\#\$%&'\*\+\-/=\?\^_`\{\|\}~]*@([-\w]*\.)+[a-zA-Z]{2,9})$}
DEFAULT_HEADERS =
{ 'Content-Type'=> 'application/json', 'Accept'=> 'application/json', 'API-Client' => "uservoice-ruby-#{UserVoice::VERSION}" }
Unauthorized =
Class.new(APIError)
NotFound =
Class.new(APIError)
ApplicationError =
Class.new(APIError)

Class Method Summary collapse

Class Method Details

.decrypt_sso_token(subdomain_key, sso_key, encoded) ⇒ Object



41
42
43
44
# File 'lib/uservoice/user_voice.rb', line 41

def self.decrypt_sso_token(subdomain_key, sso_key, encoded)
  encrypted = Base64.decode64(CGI.unescape(encoded))
  return JSON.parse(EzCrypto::Key.with_password(subdomain_key, sso_key).decrypt(encrypted))
end

.generate_sso_token(subdomain_key, sso_key, user_hash, valid_for = 5 * 60) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/uservoice/user_voice.rb', line 21

def self.generate_sso_token(subdomain_key, sso_key, user_hash, valid_for = 5 * 60)
  expiration_key = user_hash['expires'].nil? ? :expires : 'expires'
  user_hash[expiration_key] ||= (Time.now.utc + valid_for).to_s unless valid_for.nil?
  email = (user_hash[:email] || user_hash['email'])

  unless email.to_s.match(EMAIL_FORMAT)
    raise Unauthorized.new("'#{email}' is not a valid email address")
  end

  unless sso_key.to_s.length > 1
    raise Unauthorized.new("Please specify your SSO key")
  end

  key = EzCrypto::Key.with_password(subdomain_key, sso_key)
  encrypted = key.encrypt(user_hash.to_json)
  encoded = Base64.encode64(encrypted).gsub(/\n/,'')

  return CGI.escape(encoded)
end