Skip to content

Instantly share code, notes, and snippets.

@pjaspers
Created July 20, 2012 21:20
Show Gist options
  • Save pjaspers/3153308 to your computer and use it in GitHub Desktop.
Save pjaspers/3153308 to your computer and use it in GitHub Desktop.
Simple Sinatra app that uses the buienradar.nl api's and returns json(p) results
# -*- coding: utf-8 -*-
require "rubygems"
require 'sinatra'
require "json"
require "net/http"
require 'rack/contrib/jsonp'
use Rack::JSONP
class Drache
before do
content_type :json
end
helpers do
def curl(latitude, longitude)
Net::HTTP.get('gps.buienradar.nl',"/getrr.php?lat=#{latitude}&lon=#{longitude}").split("\r\n").collect{|s| s.split("|")}.inject({}) {|r, a| r[a.last] = a.first; r}
end
end
get "/" do
latitude = params[:latitude]
longitude = params[:longitude]
return {}.to_json unless latitude && longitude
curl(latitude, longitude).to_json
end
end
require "./app"
run Sinatra::Application
source :rubygems
gem "sinatra"
gem "rack-contrib"
if (!navigator.geolocation) return;
navigator.geolocation.getCurrentPosition(function(pos) {
var latitude = pos.coords.latitude;
var longitude = pos.coords.longitude;
$.ajax({
type: 'get',
url: 'http://drache.herokuapp.com/?latitude=5.123456&longitude=4',
dataType: 'jsonp',
success: function(data) {
alert(JSON.stringify(data));
}
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment