Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4631

How to get API and manipulate it

$
0
0

With Ruby, no Rails, how can I call an API such as http://api.anapi.com/, and later get a value and check if it is greater than 5?

If it contains an array called anarray which contains hashes, in one of those hashes I want to get to the value of the key key.

Right now I use:

require "net/https"require "uri"uri = URI.parse("http://api.cryptocoincharts.info/tradingPair/eth_btc")http = Net::HTTP.new(uri.host, uri.port)request = Net::HTTP::Get.new(uri.request_uri)response = http.request(request)puts response.body

And I get: #<StringIO:0x2cadb90>

Figured it out:

# http://ruby-doc.org/stdlib-2.0.0/libdoc/open-uri/rdoc/OpenURI.html require 'open-uri'# https://github.com/flori/jsonrequire 'json'# http://stackoverflow.com/questions/9008847/what-is-difference-between-p-and-pprequire 'pp'buffer = open('http://api.cryptocoincharts.info/tradingPair/eth_btc').read# api_key = "FtHwuH8w1RDjQpOr0y0gF3AWm8sRsRzncK3hHh9"result = JSON.parse(buffer)puts result["markets"]# result.each do |user|#   puts "#{user['id']}\t#{user['name']}\t#{user['email']}"#   puts "Registered: #{user['created_at']}\n\n"# end# my_hash = JSON.parse('{"hello": "goodbye"}')# puts my_hash["hello"] => "goodbye"

Viewing all articles
Browse latest Browse all 4631

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>