Sha256: 2c04241e866af840fea16dae119b523fdbbe342ebd4c63ecc8f6c33cb54e148c

Contents?: true

Size: 1020 Bytes

Versions: 2

Compression:

Stored size: 1020 Bytes

Contents

module GmapPlotter

  class Server < Sinatra::Base
    helpers Sinatra::ContentFor

    # make defaults explicit
    set :public_folder, File.dirname(__FILE__) + '/public'
    set :views, settings.root + '/views'

    get '/' do
      erb :main_layout do
        erb :main
      end
    end

    post '/upload' do
      content_type :json
      begin
        a_hash = if params['file']
                   tmp_file = params['file'][:tempfile]
                   content = tmp_file.read
                   points = JSON.parse(content)
                   {
                       :'plot-type' => params['plot-type'],
                       :points => points
                   }
                 else
                   {
                       :'plot-type' => 'path',
                       :points => []
                   }
                 end
        json a_hash
      rescue
        a_hash =  {
            :'plot-type' => 'path',
            :points => []
        }
        json a_hash
      end
    end

  end


end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gmap_plotter-0.0.2 lib/gmap_plotter/server.rb
gmap_plotter-0.0.1 lib/gmap_plotter/server.rb