取消混淆API获取帐户信息 [英] Unfuddle API get accounts info
问题描述
我正在尝试使用ActiveResource从Unfuddle API获取帐户信息
I'm trying to get the account info from Unfuddle API using ActiveResource
网址为http://mydomain.unfuddle.com/api/v1/account
这是我的ActiveResource类
this is my ActiveResource class
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获取我的帐户信息,我会得到一个空数组,但如果尝试这样做
if I try getting my account info with Account.all I'll get an empty array but if I try this
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方法不起作用有任何想法吗?
I get my account information , any ideas why the ActiveResource approach isn't working ?
**更新
我忘记指定我有此问题 https://github.com/rails/rails/issues/2318 ,然后使用 erikkallens hack.
I forgot to specify that I had this issue https://github.com/rails/rails/issues/2318 and I use erikkallens hack .
推荐答案
似乎是这个问题 https://github.com/rails/rails/issues/2318 ,我尝试了 vaskas 解决方案,但默认情况下它不起作用,我不得不对其进行修改.
It seems to be this issue https://github.com/rails/rails/issues/2318 , I tried vaskas solution but it didn't work by default I had to modify it.
class Account < ActiveResource::Base
self.collection_name = "account"
self.site = "https://mydomain.unfuddle.com/api/v1"
self.user = "me"
self.password = "pass"
self.format = AccountXMLFormatter.new
end
class AccountXMLFormatter
include ActiveResource::Formats::XmlFormat
def decode(xml)
[account: ActiveResource::Formats::XmlFormat.decode(xml)]
end
end
这篇关于取消混淆API获取帐户信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!