-
-
Save johnrc/11322248 to your computer and use it in GitHub Desktop.
This file contains 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 'mongoid' | |
require 'json' | |
require "sinatra/reloader" if development? | |
Mongoid.load!("mongoid.yml") | |
class Price | |
include Mongoid::Document | |
field :share_id, type: Integer | |
field :date, type: Time | |
field :open, type: Integer | |
field :close, type: Integer | |
field :high, type: Integer | |
field :low, type: Integer | |
field :volume, type: Integer | |
end | |
class Company | |
include Mongoid::Document | |
field :code, type: String | |
field :sector, type: String | |
field :share_id, type: Integer | |
field :jse_code, type: Integer | |
end | |
get '/companies.json' do | |
content_type :json | |
all_companies = Company.all | |
all_companies.to_json | |
end | |
get '/companies/:code/prices.json' do | |
content_type :json | |
company = Company.where(code: params[:code])[0] | |
Price.where('share_id' => company.share_id) | |
.order_by('date', :desc) | |
.to_a | |
.reverse | |
.to_json | |
end |
This file contains 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 './app' | |
run Sinatra::Application |
This file contains 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
Dir["resources/*.rb"].each {|file| load file } |
This file contains 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
development: | |
host: localhost | |
database: cool_demo | |
production: | |
host: prod_host | |
port: 1000 | |
username: main | |
password: blabla | |
database: cool_demo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment