Interacting with APIs

APIs have a variety of structures to interact with their peers.

StackExchange API

  1. require 'http'
  2. json_res = JSON.parse(Net::HTTP.get(URI.parse "http://api.stackexchange.com/2.2/questions?site=stackoverflow"))

IPify API

  1. require 'open-uri'
  2. require 'json'
  3. JSON.parse(open('https://api.ipify.org?format=json').read)["ip"]