├── Procfile ├── Gemfile ├── app.json ├── Gemfile.lock ├── README.md ├── public ├── js │ └── example.js └── index.html └── web.rb /Procfile: -------------------------------------------------------------------------------- 1 | web: bundle exec ruby web.rb -p $PORT 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | ruby "2.2.1" 3 | gem 'sinatra', '1.1.0' 4 | gem 'stsplatform', '0.0.1' 5 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "stsplatform-skeleton-sinatra", 3 | "description": "A Sinatra skeleton app using the STS Platform", 4 | "repository": "https://github.com/SenseTecnic/stsplatform-skeleton-app-sinatra", 5 | "keywords": ["ruby", "sinatra", "stsplatform"] 6 | } 7 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | json (1.8.1) 5 | rack (1.6.4) 6 | sinatra (1.1.0) 7 | rack (~> 1.1) 8 | tilt (~> 1.1) 9 | stsplatform (0.0.1) 10 | json (~> 1.8) 11 | tilt (1.4.1) 12 | 13 | PLATFORMS 14 | ruby 15 | 16 | DEPENDENCIES 17 | sinatra (= 1.1.0) 18 | stsplatform (= 0.0.1) 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | A Skeleton Sinatra and STS Platform App 2 | ======================================= 3 | 4 | This is a skeleton application written in Ruby and using the Sinatra micro-framework. 5 | 6 | ## Quick Deploy on Heroku: 7 | 8 | [![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy) 9 | 10 | ## What this application has: 11 | 12 | This bare-bones application will bootstrap your application development by providing a pre-configured simple application with: 13 | 14 | * A Sinatra application setup 15 | * Bootstrap styling 16 | * The stsplatform library 17 | 18 | For more information and support visit [http://developers.sensetecnic.com](http://developers.sensetecnic.com) 19 | -------------------------------------------------------------------------------- /public/js/example.js: -------------------------------------------------------------------------------- 1 | jQuery(function($) { 2 | $('form[data-async]').on('submit', function(event) { 3 | 4 | var $form = $(this); 5 | var $target = $($form.attr('data-target')); 6 | var button_method = $form.find('button[clicked=true]').attr('data-method'); 7 | $.ajax({ 8 | method: button_method !== undefined ? button_method : $form.attr('method'), 9 | url: $form.attr('action'), 10 | data: $form.serialize(), 11 | 12 | success: function(data, status) { 13 | $target.html(data); 14 | } 15 | }); 16 | event.preventDefault(); 17 | 18 | if ($form.attr('data-modal') === "true") { 19 | $('#credentialsModal').modal('hide'); //In the case of the modal, close it. 20 | } 21 | 22 | }); 23 | 24 | $("form button[type=submit]").click(function() { 25 | $("button[type=submit]", $(this).parents("form")).removeAttr("clicked"); 26 | $(this).attr("clicked", "true"); 27 | }); 28 | 29 | }); 30 | -------------------------------------------------------------------------------- /web.rb: -------------------------------------------------------------------------------- 1 | require 'sinatra' 2 | require 'stsplatform' 3 | require 'json' 4 | 5 | set :public_folder, 'public' 6 | enable :sessions 7 | set :logging, :true 8 | 9 | get '/' do 10 | redirect '/index.html' 11 | end 12 | 13 | get '/data' do 14 | return "You must set your credentials" unless session.has_key?("key_id") 15 | response = sts_data_resource.get({'beforeE':1}).data 16 | return response.to_json 17 | end 18 | 19 | post '/data' do 20 | return "You must set your credentials" unless session.has_key?("key_id") 21 | code = sts_data_resource.post({'value':params['value']}).code 22 | return "Value #{params['value']} sent to wotkit, received code #{code}" 23 | end 24 | 25 | post '/auth' do 26 | session['key_id'] = params['key_id'] 27 | session['key_password'] = params['key_password'] 28 | session['sensor_name'] = params['sensor_name'] 29 | return "Credentials Set" 30 | end 31 | 32 | private 33 | 34 | def sts_data_resource 35 | client = STSPlatform::Client.new( 36 | {auth:{ 37 | key_id:session['key_id'], 38 | key_password:session['key_password'] 39 | } 40 | } 41 | ) 42 | sensor = STSPlatform::Sensors.new(client,session['sensor_name']) 43 | return STSPlatform::Data.new(sensor) 44 | end 45 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | WoTKit Application Template 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | 22 | 23 |
24 | 25 | 26 |

WoTKit App

27 | 28 | 29 | 32 |

33 | 34 | 35 |
36 | 37 | 38 |
39 |

Send/Retrieve Data

40 |
41 |
42 | 43 | 44 | 45 | 46 | 47 |
48 |
49 |
50 | 51 | 52 |
53 |

Server response

54 |

 55 |         
56 | 57 |
58 | 59 | 60 | 61 | 91 | 92 |
93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | --------------------------------------------------------------------------------