Skip to content

Instantly share code, notes, and snippets.

@kaochenlong
Created May 26, 2016 08:30
Show Gist options
  • Save kaochenlong/351af35b065909f78814b444026005fa to your computer and use it in GitHub Desktop.
Save kaochenlong/351af35b065909f78814b444026005fa to your computer and use it in GitHub Desktop.
require 'net/http'
require 'json'
require 'erb'
class Webpage
def call(env)
locations = get_ubike
content = ERB.new(File.read("map.html"))
[200, {'Content-Type' => 'text/html'}, [content.result(binding)]]
end
private
def get_ubike
url = URI("http://data.ntpc.gov.tw/api/v1/rest/datastore/382000000A-000352-001")
raw_data = Net::HTTP.get(url)
JSON.parse(raw_data)["result"]["records"].map do |raw|
[ raw["sna"], raw["lat"].to_f, raw["lng"].to_f ]
end.to_s
end
end
run Webpage.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment