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.
精彩评论