Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit eec5ff3218400e1119145d24e0ca41d723a40390 @mikesea mikesea committed Jul 13, 2012
Showing with 13,495 additions and 0 deletions.
  1. +21 −0 Gemfile
  2. +38 −0 Gemfile.lock
  3. +13 −0 Guardfile
  4. +32 −0 Rakefile
  5. +59 −0 Thorfile
  6. +29 −0 api/hello_world.rb
  7. +7 −0 bin/console
  8. +5 −0 config.ru
  9. +16 −0 config/airbrake.yml.sample
  10. +3 −0 config/environments/default.rb
  11. +3 −0 config/environments/production.rb
  12. +3 −0 config/environments/test.rb
  13. +16 −0 config/middleware.rb
  14. +18 −0 config/sinatra_config.rb
  15. +24 −0 lib/app.rb
  16. +24 −0 lib/body_parser.rb
  17. +91 −0 lib/hooks.rb
  18. +66 −0 lib/newrelic_instrumentation.rb
  19. +39 −0 lib/tasks/doc.rake
  20. +4 −0 lib/tasks/doc_generator/bootstrap/.gitignore
  21. +176 −0 lib/tasks/doc_generator/bootstrap/LICENSE
  22. +47 −0 lib/tasks/doc_generator/bootstrap/Makefile
  23. +105 −0 lib/tasks/doc_generator/bootstrap/README.md
  24. +2,467 −0 lib/tasks/doc_generator/bootstrap/bootstrap.css
  25. +356 −0 lib/tasks/doc_generator/bootstrap/bootstrap.min.css
  26. +317 −0 lib/tasks/doc_generator/bootstrap/docs/assets/css/docs.css
  27. BIN lib/tasks/doc_generator/bootstrap/docs/assets/ico/bootstrap-apple-114x114.png
  28. BIN lib/tasks/doc_generator/bootstrap/docs/assets/ico/bootstrap-apple-57x57.png
  29. BIN lib/tasks/doc_generator/bootstrap/docs/assets/ico/bootstrap-apple-72x72.png
  30. BIN lib/tasks/doc_generator/bootstrap/docs/assets/ico/favicon.ico
  31. BIN lib/tasks/doc_generator/bootstrap/docs/assets/img/bird.png
  32. BIN lib/tasks/doc_generator/bootstrap/docs/assets/img/browsers.png
  33. BIN lib/tasks/doc_generator/bootstrap/docs/assets/img/example-diagram-01.png
  34. BIN lib/tasks/doc_generator/bootstrap/docs/assets/img/example-diagram-02.png
  35. BIN lib/tasks/doc_generator/bootstrap/docs/assets/img/example-diagram-03.png
  36. BIN lib/tasks/doc_generator/bootstrap/docs/assets/img/grid-18px.png
  37. BIN lib/tasks/doc_generator/bootstrap/docs/assets/img/twitter-logo-no-bird.png
  38. +52 −0 lib/tasks/doc_generator/bootstrap/docs/assets/js/application.js
  39. +94 −0 lib/tasks/doc_generator/bootstrap/docs/assets/js/google-code-prettify/prettify.css
  40. +28 −0 lib/tasks/doc_generator/bootstrap/docs/assets/js/google-code-prettify/prettify.js
  41. +2,037 −0 lib/tasks/doc_generator/bootstrap/docs/index.html
  42. +798 −0 lib/tasks/doc_generator/bootstrap/docs/javascript.html
  43. +119 −0 lib/tasks/doc_generator/bootstrap/examples/container-app.html
  44. +122 −0 lib/tasks/doc_generator/bootstrap/examples/fluid.html
  45. +79 −0 lib/tasks/doc_generator/bootstrap/examples/hero.html
  46. +124 −0 lib/tasks/doc_generator/bootstrap/js/bootstrap-alerts.js
  47. +64 −0 lib/tasks/doc_generator/bootstrap/js/bootstrap-buttons.js
  48. +55 −0 lib/tasks/doc_generator/bootstrap/js/bootstrap-dropdown.js
  49. +260 −0 lib/tasks/doc_generator/bootstrap/js/bootstrap-modal.js
  50. +90 −0 lib/tasks/doc_generator/bootstrap/js/bootstrap-popover.js
  51. +107 −0 lib/tasks/doc_generator/bootstrap/js/bootstrap-scrollspy.js
  52. +80 −0 lib/tasks/doc_generator/bootstrap/js/bootstrap-tabs.js
  53. +321 −0 lib/tasks/doc_generator/bootstrap/js/bootstrap-twipsy.js
  54. +40 −0 lib/tasks/doc_generator/bootstrap/js/tests/index.html
  55. +41 −0 lib/tasks/doc_generator/bootstrap/js/tests/unit/bootstrap-alerts.js
  56. +42 −0 lib/tasks/doc_generator/bootstrap/js/tests/unit/bootstrap-buttons.js
  57. +52 −0 lib/tasks/doc_generator/bootstrap/js/tests/unit/bootstrap-dropdown.js
  58. +151 −0 lib/tasks/doc_generator/bootstrap/js/tests/unit/bootstrap-modal.js
  59. +76 −0 lib/tasks/doc_generator/bootstrap/js/tests/unit/bootstrap-popover.js
  60. +31 −0 lib/tasks/doc_generator/bootstrap/js/tests/unit/bootstrap-scrollspy.js
  61. +77 −0 lib/tasks/doc_generator/bootstrap/js/tests/unit/bootstrap-tabs.js
  62. +81 −0 lib/tasks/doc_generator/bootstrap/js/tests/unit/bootstrap-twipsy.js
  63. +232 −0 lib/tasks/doc_generator/bootstrap/js/tests/vendor/qunit.css
  64. +1,510 −0 lib/tasks/doc_generator/bootstrap/js/tests/vendor/qunit.js
  65. +26 −0 lib/tasks/doc_generator/bootstrap/lib/bootstrap.less
  66. +479 −0 lib/tasks/doc_generator/bootstrap/lib/forms.less
  67. +222 −0 lib/tasks/doc_generator/bootstrap/lib/mixins.less
  68. +1,060 −0 lib/tasks/doc_generator/bootstrap/lib/patterns.less
  69. +141 −0 lib/tasks/doc_generator/bootstrap/lib/reset.less
  70. +139 −0 lib/tasks/doc_generator/bootstrap/lib/scaffolding.less
  71. +224 −0 lib/tasks/doc_generator/bootstrap/lib/tables.less
  72. +187 −0 lib/tasks/doc_generator/bootstrap/lib/type.less
  73. +60 −0 lib/tasks/doc_generator/bootstrap/lib/variables.less
  74. +156 −0 lib/tasks/doc_generator/template.erb
  75. BIN public/favicon.ico
  76. +19 −0 test/integration/hello_world_test.rb
  77. +40 −0 test/test_helpers.rb
@@ -0,0 +1,21 @@
+source "http://rubygems.org"
+
+# web engine
+gem "sinatra", "1.3.2"
+# service DSL
+gem "weasel_diesel"
+gem "wd_sinatra"
+gem "thor"
+
+gem 'backports', '2.3.0', :platform => 'ruby_18'
+gem 'json', :platform => 'ruby_18'
+
+group :development, :test do
+ gem "rack-test", "0.6.1"
+ # gem "foreman"
+ # gem "puma"
+ gem "minitest"
+ # gem "guard-puma"
+ # gem "guard-minitest"
+ gem "rake"
+end
@@ -0,0 +1,38 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ backports (2.3.0)
+ json (1.7.3)
+ minitest (3.2.0)
+ rack (1.4.1)
+ rack-protection (1.2.0)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rake (0.9.2.2)
+ sinatra (1.3.2)
+ rack (~> 1.3, >= 1.3.6)
+ rack-protection (~> 1.2)
+ tilt (~> 1.3, >= 1.3.3)
+ thor (0.15.4)
+ tilt (1.3.3)
+ wd_sinatra (0.3.1)
+ thor
+ weasel_diesel
+ weasel_diesel (1.0.4)
+ backports
+ json
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ backports (= 2.3.0)
+ json
+ minitest
+ rack-test (= 0.6.1)
+ rake
+ sinatra (= 1.3.2)
+ thor
+ wd_sinatra
+ weasel_diesel
@@ -0,0 +1,13 @@
+# A sample Guardfile
+# More info at https://github.com/guard/guard#readme
+
+guard 'puma' do
+ watch('Gemfile.lock')
+ watch(%r{^config|lib|api/.*})
+end
+
+guard 'minitest', :test_file_patterns => '*_test.rb' do
+ watch(%r|^test/(.*)_test\.rb|)
+ watch(%r{^api/(.*/)?([^/]+)\.rb$}) { |m| "test/api/#{m[1]}#{m[2]}_test.rb" }
+ watch(%r|^test/test_helper\.rb|) { "test" }
+end
@@ -0,0 +1,32 @@
+require 'rbconfig'
+require 'rake/testtask'
+require 'rubygems'
+require 'bundler'
+Bundler.setup
+require 'wd_sinatra/app_loader'
+
+root = File.expand_path(File.dirname(__FILE__))
+
+Rake::TestTask.new do |t|
+ t.libs << "."
+ t.libs << 'test'
+ t.pattern = "test/**/*_test.rb"
+end
+
+task :default => :test
+
+# boot the app
+task :setup_app do
+ ENV['DONT_CONNECT'] = 'true'
+ WDSinatra::AppLoader.server(root)
+end
+
+task :environment do
+ ENV['DONT_CONNECT'] = nil
+ WDSinatra::AppLoader.server(root)
+end
+
+WDSinatra::AppLoader.set_loadpath(root)
+Dir.glob("lib/tasks/**/*.rake").each do |task_file|
+ load task_file
+end
@@ -0,0 +1,59 @@
+# encoding: utf-8
+$:.unshift File.expand_path("../lib", __FILE__)
+require 'bundler'
+require 'active_support/inflector'
+
+class Default < Thor
+ include Thor::Actions
+
+ desc "service VERB URI FILENAME", "Generate scaffolding for a new service"
+ def service(verb, route, path)
+ route = route.gsub(/^\//, "") # strip leading forward slash
+ path_without_suffix = path.gsub(/\.rb$/, "")
+ create_file(File.join("api", "#{path_without_suffix}.rb")) do
+ <<-RUBY.gsub(/^\s{6}/, '')
+ describe_service "#{route}" do |service|
+ service.formats :json
+ service.http_verb :#{verb.downcase}
+ service.disable_auth # on by default
+
+ # INPUT
+ service.param.string :name, :default => 'World', :doc => "The name of the person to greet."
+
+ # OUTPUT
+ 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
+
+ # DOCUMENTATION
+ service.documentation do |doc|
+ doc.overall "This service provides a simple hello world implementation example."
+ doc.example "<code>curl -I 'http://localhost:9292/hello_world?name=Matt'</code>"
+ end
+
+ # ACTION/IMPLEMENTATION
+ service.implementation do
+ halt 501, "Not Implemented, which is a pity, I'm sure"
+ end
+ end
+ RUBY
+ end
+
+ class_name = path_without_suffix.classify.gsub(/::/, '') # strip modules; just want a unique class name for spec
+ create_file(File.join("test", "integration", "#{path_without_suffix}_test.rb")) do
+ <<-RUBY.gsub(/^\s{6}/, '')
+ require 'test_helpers'
+
+ class #{class_name}Spec < MiniTest::Spec
+ it "performs request" do
+ TestApi.#{verb} "/#{route}", {}
+ assert_api_response
+ end
+ end
+ RUBY
+ end
+ end
+end
@@ -0,0 +1,29 @@
+describe_service "hello_world" do |service|
+ service.formats :json
+ service.http_verb :get
+ service.disable_auth # on by default
+
+ # INPUT
+ service.param.string :name, :default => 'World'
+
+ # OUTPUT
+ 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
+
+ # DOCUMENTATION
+ 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>curl -I 'http://localhost:9292/hello_world?name=Matt'</code>"
+ end
+
+ # ACTION/IMPLEMENTATION
+ service.implementation do
+ {:message => "Hello #{params[:name]}", :at => Time.now}.to_json
+ end
+
+end
@@ -0,0 +1,7 @@
+#!/usr/bin/env ruby
+require 'irb'
+require 'rubygems'
+require 'wd_sinatra/app_loader'
+root = File.expand_path('..', File.dirname(__FILE__))
+WDSinatra::AppLoader.console(root)
+IRB.start(__FILE__)
@@ -0,0 +1,5 @@
+require 'rubygems'
+require 'wd_sinatra/app_loader'
+root = File.expand_path(File.dirname(__FILE__))
+WDSinatra::AppLoader.server(root)
+run Sinatra::Application
@@ -0,0 +1,16 @@
+common: &default_settings
+ api_key: 'replace me'
+ params_filters:
+ - password
+ host: 'api.airbrake.io'
+ enabled: false
+
+development:
+ <<: *default_settings
+
+test:
+ <<: *default_settings
+
+production:
+ <<: *default_settings
+ enabled: true
@@ -0,0 +1,3 @@
+# This is the default environment setup.
+# It can be overwritten or extended by a custom environment file.
+# Note: the LOGGER constant isn't yet defined and shouldn't be defined here.
@@ -0,0 +1,3 @@
+require 'logger'
+LOGGER = Logger.new($stdout)
+LOGGER.level = Logger::INFO
@@ -0,0 +1,3 @@
+require 'logger'
+LOGGER = Logger.new($stdout)
+LOGGER.level = Logger::FATAL
@@ -0,0 +1,16 @@
+if defined?(NewRelic)
+ if RACK_ENV == 'development'
+ require 'new_relic/rack/developer_mode'
+ use NewRelic::Rack::DeveloperMode
+ end
+ if NewRelic::Control.instance.agent_enabled?
+ LOGGER.info "New Relic monitoring enabled App name: '#{NewRelic::Control.instance['app_name']}', Mode: '#{NewRelic::Control.instance.app}'"
+ end
+end
+
+# Use this middleware with AR to avoid threading issues.
+# require 'active_record'
+# use ActiveRecord::ConnectionAdapters::ConnectionManagement
+
+use Airbrake::Rack if defined?(Airbrake)
+use Rack::ContentLength
@@ -0,0 +1,18 @@
+set :environment, RACK_ENV
+set :root, WDSinatra::AppLoader.root_path
+set :app_file, __FILE__
+set :public_folder, File.join(WDSinatra::AppLoader.root_path, "public")
+# Checks on static files before dispatching calls
+enable :static
+# enable rack session
+enable :session
+set :raise_errors, false
+# enable that option to run by calling this file automatically (without using the config.ru file)
+# enable :run
+use Rack::ContentLength
+
+# Store the caught exception in the rack env so it can be used
+# by 3rd party apps like airbrake.
+error(::Exception) do |exception|
+ @env['rack.exception'] = exception
+end
@@ -0,0 +1,24 @@
+# called after the environment is setup and the basic dependencies are loaded
+# but before the models are loaded.
+#
+# Here you want to load your dependencies and maybe set your
+# datastore.
+
+
+############### AIRBRAKE ###############
+airbrake_config_file = File.join(WDSinatra::AppLoader.root_path, 'config', 'airbrake.yml')
+if File.exist?(airbrake_config_file)
+ airbrake_config = YAML.load_file(airbrake_config_file)[RACK_ENV]
+ if airbrake_config && airbrake_config['enabled']
+ require 'airbrake'
+ Airbrake.configure do |config|
+ config.api_key = airbrake_config['api_key']
+ (airbrake_config['params_filters'] - config.params_filters).each do |param|
+ config.params_filters << param
+ end
+ config.environment_name = RACK_ENV
+ config.host = airbrake_config['host'] if airbrake_config['host']
+ config.logger = LOGGER
+ end
+ end
+end
@@ -0,0 +1,24 @@
+module BodyParser
+ module_function
+
+ JSON_TYPE = "application/json"
+
+ # Parses the body
+ def parse(params, body, content_type)
+ case content_type
+ when JSON_TYPE
+ params.merge(json_parser.parse(body.read))
+ else
+ params
+ end
+ end
+
+ def json_parser=(parser_klass)
+ @json_parser = parser_klass
+ end
+
+ def json_parser
+ @json_parser
+ end
+
+end
Oops, something went wrong. Retry.

0 comments on commit eec5ff3

Please sign in to comment.