拆下的ActiveResource请求.xml扩展 [英] Remove .xml extension from ActiveResource request

查看:195
本文介绍了拆下的ActiveResource请求.xml扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用的ActiveResource从第三方API使用XML数据。我可以使用RESTClient实现应用成功验证,并请求。我codeD我的应用程序,当我提出要求,我得到一个404错误。我说:

I am trying to use ActiveResource to consume xml data from a third party API. I can use the RESTClient app to successfully authenticate and make requests. I coded my app and when I make a request I get a 404 error. I added:

ActiveResource::Base.logger = Logger.new(STDERR) 

我development.rb文件,想通了这个问题。该API使用XML数据中不XML结束请求响应。 EG,这部作品在RESTClient实现:

to my development.rb file and figured out the problem. The API responds with xml data to requests that do NOT end in xml. EG, this works in RESTClient:

https://api.example.com/contacts

不过是的ActiveResource而不是发送该请求

but ActiveResource is sending this request instead

https://api.example.com/contacts.xml

反正是有好的方式剥离从请求通过的ActiveResource正在生成扩展?

Is there anyway "nice" way to strip the extension from the request being generated by ActiveResource?

感谢

推荐答案

您可能需要重写 element_path在模型中方法。

根据API,目前确定指标如下:

According to the API, the current defintion looks like this:

def element_path(id, prefix_options = {}, query_options = nil)
  prefix_options, query_options = split_options(prefix_options) if query_options.nil?  
  "#{prefix(prefix_options)}#{collection_name}/#{id}.#{format.extension}#{query_string(query_options)}"
end

删除。#{} format.extension部分可能做你的需要。

Removing the .#{format.extension} part might do what you need.

这篇关于拆下的ActiveResource请求.xml扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆