开发者

Wrap a foreign API into a Ruby class

I use HTTParty to consume a foreign API, but how can I convert the response into a Rub开发者_Python百科y class or Rails model?


It is going to depend on the output of your API. If the output is JSON, you can use the built-in Rails JSON parsing. If the output is XML in a Rails-friendly format, you may be able to use the built-in object-to-xml conversion tools. Otherwise, you may need to create your mapping explicitly.


If the response is XML Nokogiri or ROXML come in handy. An alternative to ROXML would be Happymapper.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜