Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 59509ad02de0a9320f53758df9d283310600ed36 @mattetti committed Jan 10, 2012
20 Gemfile
@@ -0,0 +1,20 @@
+source "http://rubygems.org"
+
+# web engine
+gem "sinatra", "1.3.2"
+# service DSL
+gem "wsdsl", "0.5.0"
+#
+gem "redis", "~> 2.2.2"
+gem 'mysql2', '0.3.11'
+gem 'activerecord', '3.1.3'
+gem 'sinatra-activerecord', '0.1.3'
+gem 'email_veracity', '0.6.0'
+# gem "hiredis", "~> 0.4.1"
+# gem 'rest-client', '~> 1.6.7'
+
+if ENV['RACK_ENV'] != "production"
+ gem "rack-test", "0.6.1"
+ gem "foreman", "~> 0.26.1"
+ gem "puma", "~> 0.9.3"
+end
@@ -0,0 +1 @@
+app: bundle exec puma
0 README
No changes.
@@ -0,0 +1,54 @@
+# Sinatra + WSDSL + ActiveRecord Example app
+
+## App Usage
+
+To start the server:
+
+ $ rackup
+
+Or
+ $ foreman start
+
+if you have foreman installed.
+
+To use the command line:
+
+ $ irb -Ilib -rbootloader.rb
+ > Bootloader.start
+
+## Dependencies
+
+* A Database (set the connection settings in config/database.yml)
+* Ruby
+* Bundler
+
+## Organization
+
+Models live under the models folder, APIs in the API folder.
+The database.yml file in the config folder contains the db info per
+environment.
+
+By default all environments share the same settings, but you can drop a
+custom environment file in the config/environments folder named after
+the env you want to target.
+
+Migrations are simple ActiveRecord migrations and a seed.rb file is
+available to pre seed the DB.
+
+Files in the lib folder aren't automatically required.
+
+## Tests
+
+The app test suite uses a series of helpers wrapping rack/test to test
+a request going through the stack but without the overhead of actually
+doing a real HTTP request.
+
+
+## TODO:
+
+* Test under Ruby 1.8, JRuby and Rubinius.
+* Add test suite for the Sinatra + WSDSL integration.
+* Documentation task to generate an HTML (PDF?) version of the offered services.
+* Make the ORM configurable.
+* Generators for blank APIs and migrations.
+* Provide Rack Client as a test alternative to make real HTTP calls.
@@ -0,0 +1,32 @@
+require 'rbconfig'
+require 'rake/testtask'
+require File.join(File.dirname(__FILE__), 'lib', 'bootloader')
+
+Rake::TestTask.new do |t|
+ t.libs << "."
+ t.libs << 'test'
+ t.pattern = "test/**.rb"
+end
+
+# boot the app
+task :setup_app do
+ ENV['DONT_CONNECT'] = 'true'
+ Bootloader.start
+end
+
+task :environment do
+ ENV['DONT_CONNECT'] = nil
+ Bootloader.start
+end
+
+desc "Run the test suite by resting the DB first"
+task :clean_test_suite do
+ ENV['RACK_ENV'] ||= 'test'
+ Rake::Task["db:drop"].invoke
+ Rake::Task["db:create"].invoke
+ Rake::Task["db:setup"].invoke
+ Rake::Task["test"].invoke
+end
+
+Bootloader.set_loadpath
+load File.join('tasks', 'db.rake')
@@ -0,0 +1,25 @@
+describe_service "hello_world" do |service|
+ service.formats :json
+ service.http_verb :get
+ service.disable_auth # on by default
+
+ service.param.string :name, :default => 'World'
+
+ service.response do |response|
+ response.object do |obj|
+ obj.string :message, :doc => "The greeting message sent back. Defaults to 'World'"
+ obj.datetime :at, :doc => "The timestamp of when the message was dispatched"
+ end
+ end
+
+ service.documentation do |doc|
+ doc.overall "This service provides a simple hello world implementation example."
+ doc.param :name, "The name of the person to greet."
+ doc.example "<code>http://localhost:9292/hello_world?name=Matt</code>"
+ end
+
+ service.implementation do
+ {:message => "Hello #{params[:name]}", :at => Time.now}.to_json
+ end
+
+end
@@ -0,0 +1,3 @@
+require File.join( File.dirname(__FILE__), 'lib', 'bootloader')
+Bootloader.start
+run Sinatra::Application
@@ -0,0 +1,29 @@
+development:
+ adapter: mysql2
+ encoding: utf8
+ reconnect: true
+ database: example_dev
+ pool: 5
+ username: root
+ password:
+ socket: /tmp/mysql.sock
+
+test:
+ adapter: mysql2
+ encoding: utf8
+ reconnect: true
+ database: example_test
+ pool: 5
+ username: root
+ password:
+ socket: /tmp/mysql.sock
+
+production:
+ adapter: mysql2
+ encoding: utf8
+ reconnect: true
+ database: example_prod
+ pool: 5
+ username: root
+ password:
+ socket: /tmp/mysql.sock
@@ -0,0 +1,3 @@
+# This is the default environment setup.
+# It can be overwritten or extended by a custom environment file.
+LOGGER.level = Logger::INFO
No changes.
@@ -0,0 +1,13 @@
+class CreateMessages < ActiveRecord::Migration
+ def self.up
+ create_table :messages do |t|
+ t.string :from
+ t.string :to
+ t.string :text
+ t.timestamps
+ end
+ end
+
+ def self.down
+ end
+end
@@ -0,0 +1,66 @@
+# encoding: UTF-8
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 20120103225834) do
+
+ create_table "external_people", :force => true do |t|
+ t.string "first_name"
+ t.string "last_name"
+ t.string "gender", :limit => 16
+ t.date "birthday"
+ t.integer "age"
+ t.string "crypted_password", :limit => 40
+ t.string "salt", :limit => 40
+ t.integer "person_id", :null => false
+ t.boolean "tos", :default => false
+ t.datetime "email_verified_at"
+ t.string "zip"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ add_index "external_people", ["person_id"], :name => "index_external_people_on_person_id"
+
+ create_table "facebook_people", :force => true do |t|
+ t.integer "person_id", :null => false
+ t.integer "uid", :null => false
+ t.datetime "last_fetched"
+ t.string "first_name"
+ t.string "last_name"
+ t.integer "birth_year"
+ t.integer "birth_day"
+ t.integer "birth_month"
+ t.integer "age"
+ t.string "gender"
+ t.string "friend_checksum"
+ t.datetime "stream_publish_access_at"
+ t.integer "stream_publish_city_id"
+ t.datetime "stream_publish_ok_at"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ add_index "facebook_people", ["person_id"], :name => "index_facebook_people_on_person_id"
+ add_index "facebook_people", ["uid"], :name => "index_facebook_people_on_uid"
+
+ create_table "people", :force => true do |t|
+ t.integer "origin_city_id"
+ t.string "ref"
+ t.string "email"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ add_index "people", ["email"], :name => "index_people_on_email"
+
+end
No changes.
Oops, something went wrong.

0 comments on commit 59509ad

Please sign in to comment.