【发布时间】:2012-03-12 11:33:48
【问题描述】:
我正在尝试使用 ActiveResource 从 Unfuddle API 获取帐户信息
网址是http://mydomain.unfuddle.com/api/v1/account
这是我的 ActiveResource 类
class Account < ActiveResource::Base
self.collection_name = "account"
self.site = "https://mydomain.unfuddle.com/api/v1"
self.user = "me"
self.password = "pass"
end
如果我尝试使用 Account.all 获取我的帐户信息,我将得到一个空数组,但如果我尝试这样做
require 'net/https'
UNFUDDLE_SETTINGS = {
:subdomain => 'mydomain',
:username => 'me',
:password => 'pass',
:ssl => true
}
http = Net::HTTP.new("#{UNFUDDLE_SETTINGS[:subdomain]}.unfuddle.com",UNFUDDLE_SETTINGS[:ssl] ? 443 : 80)
if UNFUDDLE_SETTINGS[:ssl]
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
begin
request = Net::HTTP::Get.new('/api/v1/account')
request.basic_auth UNFUDDLE_SETTINGS[:username], UNFUDDLE_SETTINGS[:password]
response = http.request(request)
if response.code == "200"
puts response.body
else
puts "HTTP Status Code: #{response.code}."
end
rescue => e
puts e.message
end
我得到了我的帐户信息,有什么想法为什么 ActiveResource 方法不起作用?
**更新
我忘了说明我遇到了这个问题https://github.com/rails/rails/issues/2318,我使用了 erikkallens hack。
【问题讨论】:
标签: ruby-on-rails ruby activeresource unfuddle