Skip to content

Instantly share code, notes, and snippets.

@alexisrobert
Last active January 11, 2016 17:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexisrobert/cfdb32371db7a240263c to your computer and use it in GitHub Desktop.
Save alexisrobert/cfdb32371db7a240263c to your computer and use it in GitHub Desktop.
Dashing plugin for Santander Bikes (ex Barclays Bikes) realtime availability

Santander Bikes (ex Barclays Bikes) realtime availability

This widget fetchs the availability of Santander Bikes (ex Barclays Bikes) in realtime using TfL's API.

To install, just type dashing install cfdb32371db7a240263c

Don't forget to add httparty in you Gemfile like this :

    gem 'httparty'

Just update your latitude and longitude in santanderbikes.rb, and include it in your template using the List widget like this :

    <div data-id="bikes" data-view="List" data-unordered="true"
    data-title="Bikes availability" data-moreinfo="Available bikes / Free docks"></div>
require 'httparty'
lat = 51.500987
lon = -0.14178851
radius = 300
SCHEDULER.every '1m' do
puts "bikes"
statuses = Array.new
result = HTTParty.get("http://api.tfl.gov.uk/BikePoint?lat=#{lat}&lon=#{lon}&radius=#{radius}&app_id=&app_key=")
raw_info = result.parsed_response["places"]
raw_info.each do |station|
docks_free = nil
docks_bikes = nil
station["additionalProperties"].each do |property|
if property["key"] == "NbBikes"
docks_bikes = property["value"].to_i
elsif property["key"] == "NbEmptyDocks"
docks_free = property["value"].to_i
end
end
statuses.push({label: station["commonName"].split(',')[0], value: "#{docks_bikes}/#{docks_free}"})
end
send_event('bikes', { items: statuses })
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment