Created
February 7, 2012 01:57
-
-
Save xentek/1756582 to your computer and use it in GitHub Desktop.
HTTParty with XML example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'httparty' | |
response = HTTParty.get('http://www.google.com/ig/api?weather=Chicago') | |
data = response.parsed_response | |
puts data['xml_api_reply']['weather']['current_conditions']['condition']['data'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'httparty' | |
response = HTTParty.get('http://www.google.com/ig/api?weather=Chicago') | |
forecast_conditions = response.parsed_response['xml_api_reply']['weather']['forecast_conditions'] | |
forecast_conditions.each do |condition| | |
puts "The forecast for #{condition['day_of_week']['data']} with a high of #{condition['high']['data']}, and a low of #{condition['low']['data']}. It will be #{condition['condition']['data']}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For a use case I would like to edit the XML response and make another post request.
What is the best way to go about this?
Which would be the better approach?