Skip to content

Instantly share code, notes, and snippets.

@JayCuthrell
Created September 27, 2010 06:05
Show Gist options
  • Save JayCuthrell/598684 to your computer and use it in GitHub Desktop.
Save JayCuthrell/598684 to your computer and use it in GitHub Desktop.
require 'open-uri'
require 'digest/md5'
# Get your external IP address from IP Chicken to send to the Quova service request URL below
ip_address = (open("http://ipchicken.com") {|f|f.read.scan(/([0-9]{1,3}\.){3}[0-9]{1,3}/);$~})
# Your API credentials from http://developer.quova.com/apps/mykeys
API_KEY = 'yougottagetyourownforthispartrighthere'
SHARED_SECRET = 'yespleasegetyourown'
# Example code from http://developer.quova.com/docs#sample_ruby
# API version and location
API_VERSION = 'v1'
PRODUCTION_ENDPOINT = 'api.quova.com'
PRODUCTION_PORT = 80
# Create your digital signature to send to the Quova service request URL below
current_time = Time.now
timestamp = Time.now.to_i.to_s
sig = Digest::MD5.hexdigest( API_KEY+SHARED_SECRET+timestamp )
# Quora API service request URL
request_url = "/#{API_VERSION}/ipinfo/#{ip_address}?apikey=#{API_KEY}&sig=#{sig}"
# Let's do this thing
http = Net::HTTP.new( PRODUCTION_ENDPOINT , PRODUCTION_PORT )
http.start do |http|
req = Net::HTTP::Get.new(request_url)
resp, data = http.request(req)
print data
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment