开发者

Preventing YQL from URL encoding a key

I am wondering if it is possible to prevent YQL from URL encoding a key for a datatable?

Example:

The current guardian API works with IDs like this:

item_id = "environment/2010/oct/29/biodiversity-talks-ministers-nagoya-strategy"

The problem with these IDs is that they contain slashes (/) and these characters should not be URL encoded in the API call but instead stay as they are.

So If I now have this query

SELECT * FROM guardian.content.item WHERE item_id='environment/2010/oct/29/biodive开发者_如何转开发rsity-talks-ministers-nagoya-strategy'

while using the following url defintion in my datatable

<url>http://content.guardianapis.com/{item_id}</url>

then this results in this API call

http://content.guardianapis.com/environment%2F2010%2Foct%2F29%2Fbiodiversity-talks-ministers-nagoya-strategy?format=xml&order-by=newest&show-fields=all

Instead the guardian API expects the call to look like this:

http://content.guardianapis.com/environment/2010/oct/29/biodiversity-talks-ministers-nagoya-strategy?format=xml&order-by=newest&show-fields=all

So the problem is really just that the / characters gets encoded as %2F which I don't want to happen in this case.

Any ideas on how this can be achieved?

You can also check the full datatable I am using:

http://github.com/spier/yql-tables/blob/master/guardian/guardian.content.item.xml


The URI-template expansions in YQL (e.g. {item_id}) only follow the version 3 spec. With version 4 it would be possible to simply (only slightly) change the expansion to do what you want, but alas not currently with YQL.

So, a solution. You could bring a very, very basic <execute> block into play: one which adds the item_id value to the path as needed.

<execute><![CDATA[
    response.object = request.path(item_id).get().response;
]]></execute>

Finally, see the diff against your table (with a few other, minor tweaks to allow the above to work).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜