0

我正在努力将 UserVoice Single Single On 与我的 rails 应用程序集成。他们为 ruby​​ 提供了以下类:

require 'rubygems'
require 'ezcrypto'
require 'json'
require 'cgi'
require 'base64'

module Uservoice
  class Token
    attr_accessor :data

    USERVOICE_SUBDOMAIN = "FILL IN"
    USERVOICE_SSO_KEY = "FILL IN"

    def initialize(options = {})
      options.merge!({:expires => (Time.zone.now.utc + 5 * 60).to_s})

      key = EzCrypto::Key.with_password USERVOICE_SUBDOMAIN, USERVOICE_SSO_KEY
      encrypted = key.encrypt(options.to_json)
      @data = Base64.encode64(encrypted).gsub(/\n/,'') # Remove line returns where are annoyingly placed every 60 characters
    end

    def to_s
      @data
    end
  end
end

我不知道如何使用它。我将此文件添加到我的 lib 目录并使用 Rails 控制台运行。我试过了:

1.9.3-p125 :013 > Uservoice::Token
 => Uservoice::Token 

但不能让它真正返回选项:

Uservoice::Token.new(:guid => 1, :display_name => "jeff goldmen", :email => "jeff@google.com")

任何想法如何实际使用它?谢谢

4

1 回答 1

2

查看代码,初始化程序(调用时运行的程序)似乎不会new只采用哈希值。方法定义如下所示:

def initialize(key, api_key, data)

它似乎将data变量视为哈希。您可能只需要在实例化 Token 时添加key和值。api_key所以调用看起来像这样:

Uservoice::Token.new(KEY, API_KEY, {guid:1, display_name:'foo', email:'f@b.com'})
于 2013-03-11T00:49:08.057 回答