从 ActiveResource 请求中删除 .xml 扩展名 [英] Remove .xml extension from ActiveResource request

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

问题描述

我正在尝试使用 ActiveResource 来使用来自第三方 API 的 xml 数据.我可以使用 RESTClient 应用程序成功进行身份验证并发出请求.我编写了我的应用程序,当我提出请求时,我收到了 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 方法.

You probably need to override the element_path method in your model.

根据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天全站免登陆