Created
July 20, 2012 21:20
-
-
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
This file contains hidden or 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
# -*- 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 |
This file contains hidden or 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 "./app" | |
run Sinatra::Application |
This file contains hidden or 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
source :rubygems | |
gem "sinatra" | |
gem "rack-contrib" |
This file contains hidden or 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
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