Skip to content

Instantly share code, notes, and snippets.

@mehdicopter
Last active August 8, 2017 08:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mehdicopter/a2396a5166f831cbba84d2120bc92942 to your computer and use it in GitHub Desktop.
Save mehdicopter/a2396a5166f831cbba84d2120bc92942 to your computer and use it in GitHub Desktop.

Preview

Preview

Description

Displays the number of Bluecars available from an Autolib' station.

Dependencies

The following dependencies are required. Please add them to your dashing gemfile.

gem 'httparty'

Run bundle install

Usage

To install this widget into you dashboard, just run this command :

dashing install a2396a5166f831cbba84d2120bc92942

Insert the HTML code in your erb file like this :

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
  <div data-id="autolib" data-view="Autolib"></div>
</li>

Settings

License

This widget is released under the MIT License.

NB

Feel free to leave comments for any improvements.

class Dashing.Autolib extends Dashing.Widget
ready: ->
onData: (data) ->
if data.bluecar == '0' and data.status == 'ok'
$(@node).css('background-color', '#FF9933') #orange
else if data.status == 'ok'
$(@node).css('background-color', '#00CC33') #green
else if data.status == 'closed'
$(@node).css('background-color', '#FF0055 ') #red
<h1 class="title" data-bind="name"></h1>
<h2 class="bluecar" data-bind="bluecar"></h2>
<p class="more-info">STATUS : <span data-bind="status"></span></p>
<p class="updated-at" data-bind="updatedAtMessage"></p>
require 'httparty'
API_KEY = ENV["AUTOLIB_API_KEY"]
STATION_ID = '1894' #Paris/Madame/18
url = "http://apixha.ixxi.net/APIX?keyapp=#{API_KEY}&cmd=searchPoiById&id=#{STATION_ID}&apixFormat=json"
SCHEDULER.every '2m', :first_in => 0 do |job|
response = HTTParty.get(url)
data = response.parsed_response
status = data['pointOfInterest'][0]['status'] # 'ok' or 'closed'
nbre_bluecar = data['pointOfInterest'][0]['keyList'][1]['value']
nom_station = data['pointOfInterest'][0]['name']
send_event('autolib', { name: nom_station, bluecar: nbre_bluecar, status: status })
end
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$title-color: rgba(255, 255, 255, 0.7);
$moreinfo-color: rgba(255, 255, 255, 0.7);
$updatedat-color: rgba(0, 0, 0, 0.3);
// ----------------------------------------------------------------------------
// Widget-number styles
// ----------------------------------------------------------------------------
.widget-autolib {
.title {
color: $title-color;
font-size: 25px;
}
.more-info{
color: $moreinfo-color;
}
.updated-at {
color: $updatedat-color;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment