Last active
August 29, 2015 14:18
-
-
Save AlSquire/5b29d5c0ddbddac6e502 to your computer and use it in GitHub Desktop.
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
/** | |
* Welcome to Pebble.js! | |
* | |
* This is where you write your app. | |
*/ | |
var UI = require('ui'); | |
var ajax = require('ajax'); | |
function fetchJSON(url) { | |
ajax( | |
{ | |
url: url, | |
type: 'json' | |
}, function(data, status, request) { | |
displayJSON(data); | |
}, function(error, status, request) { | |
var card = UI.Card({ | |
title: "Error", | |
body: status | |
}); | |
card.show(); | |
} | |
); | |
} | |
function displayJSON (json) { | |
if (json.hasOwnProperty('menu')) { | |
var menu = new UI.Menu(json.menu); | |
menu.on('select', function(e) { | |
if (e.item.hasOwnProperty('url')) { | |
fetchJSON(e.item.url); | |
} | |
}); | |
menu.show(); | |
} else if (json.hasOwnProperty('card')) { | |
var card = new UI.Card(json.card); | |
card.show(); | |
} | |
} | |
var menuUrl = "https://gist.githubusercontent.com/AlSquire/5b29d5c0ddbddac6e502/raw/menu.json"; | |
fetchJSON(menuUrl); |
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
{ | |
"card": { | |
"title": "Hey", | |
"body": "Tralala\nAll right!" | |
} | |
} |
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
{ | |
"menu": { | |
"sections": [{ | |
"items": [ | |
{ | |
"title": "Friandises chat" | |
}, { | |
"title": "Dentifrice" | |
}, { | |
"title": "Steak" | |
} | |
] | |
}] | |
} | |
} |
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 'sinatra' | |
require 'json' | |
require 'net/http' | |
get '/' do | |
"Hello World" | |
end | |
get '/velib.json' do | |
stations = { | |
2021 => 'OMTS', | |
4013 => 'Home', | |
4014 => 'Archives', | |
3008 => 'Perle', | |
4103 => 'BHV', | |
4015 => 'Pont Louis', | |
4012 => 'Ecouffes' | |
} | |
url = "http://opendata.paris.fr/api/records/1.0/search?dataset=stations-velib-disponibilites-en-temps-reel&q=" | |
url += 'number%3A' + stations.keys.join('+OR+number%3A') | |
json = JSON.parse(Net::HTTP.get(URI(url))) | |
body = stations.map do |key, val| | |
fields = json['records'].detect { |r| r['fields']['number'] == key }['fields'] | |
"#{val}: #{fields['available_bikes']}/#{fields['available_bike_stands']}" | |
end | |
content_type :json | |
{ | |
card: { | |
title: "Velib", | |
body: body.join("\n") | |
} | |
}.to_json | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment