simple_sinatra_api 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +21 -0
- data/Rakefile +2 -0
- data/bin/simple_sinatra_api +15 -0
- data/lib/simple_sinatra_api.rb +6 -0
- data/lib/simple_sinatra_api/cli.rb +34 -0
- data/lib/simple_sinatra_api/version.rb +3 -0
- data/simple_sinatra_api.gemspec +27 -0
- data/templates/new_app/.env +1 -0
- data/templates/new_app/Gemfile +30 -0
- data/templates/new_app/Procfile +1 -0
- data/templates/new_app/README.md.tt +3 -0
- data/templates/new_app/app.rb.tt +38 -0
- data/templates/new_app/app/extensions.rb.tt +5 -0
- data/templates/new_app/app/extensions/api.rb.tt +18 -0
- data/templates/new_app/app/routes.rb.tt +8 -0
- data/templates/new_app/app/routes/api.rb.tt +24 -0
- data/templates/new_app/app/routes/error.rb.tt +35 -0
- data/templates/new_app/app/routes/sample.rb.tt +12 -0
- data/templates/new_app/config.ru.tt +3 -0
- data/templates/new_app/config/unicorn.rb +21 -0
- data/templates/new_app/development.db +0 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 98c0aee95907097b2bc015fa6ae7a410557aaf57
|
4
|
+
data.tar.gz: 8d918bfa8c24fc44d5144d3dccb6290489799a78
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 09ad3c11b0dfd03d36915d66e6529d07411db3e03b9c798421d344d471b1cb3789e9a9ebd7c89d29c79268cd0b058beace9103f28df2fc6955da097e56483bd0
|
7
|
+
data.tar.gz: be1a6e44e1a3056f7f866549c23299329828b8551a347dc2a51e9a0a442d6d69baa1d049c059fbf4bec97326c59678d6708c093863374095dc2af9d661bdba6d
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Dinesh Vasudevan
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# SimpleSinatraApi
|
2
|
+
|
3
|
+
Generate an opinionated Simple Sinatra Application for API Backend
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install simple_sinatra_api
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
Start by creating an application with a basic template
|
12
|
+
|
13
|
+
simple_sinatra_api next_best_api
|
14
|
+
|
15
|
+
## Contributing
|
16
|
+
|
17
|
+
1. Fork it ( https://github.com/[my-github-username]/simple_sinatra_api/fork )
|
18
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
19
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
20
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
21
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'simple_sinatra_api'
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'simple_sinatra_api/cli'
|
9
|
+
SimpleSinatraApi::CLI.start
|
10
|
+
rescue Interrupt => e
|
11
|
+
puts "\nQuitting..."
|
12
|
+
exit 1
|
13
|
+
rescue SystemExit => e
|
14
|
+
exit e.status
|
15
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'thor/group'
|
3
|
+
# https://github.com/rails/rails/issues/14664#issuecomment-40191673
|
4
|
+
require 'active_support'
|
5
|
+
require 'active_support/core_ext'
|
6
|
+
|
7
|
+
module SimpleSinatraApi
|
8
|
+
class CLI < Thor::Group
|
9
|
+
include Thor::Actions
|
10
|
+
|
11
|
+
def self.source_root
|
12
|
+
File.expand_path('../../../templates', __FILE__)
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Creates a new Sinatra API Application"
|
16
|
+
argument :name, type: :string, desc: "The name of the New Application"
|
17
|
+
|
18
|
+
def create_app
|
19
|
+
directory 'new_app', name.underscore
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize_git_repo
|
23
|
+
inside(name.underscore) do
|
24
|
+
run('git init .')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def install_dependencies
|
29
|
+
inside(name.underscore) do
|
30
|
+
run('bundle')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'simple_sinatra_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "simple_sinatra_api"
|
8
|
+
spec.version = SimpleSinatraApi::VERSION
|
9
|
+
spec.authors = ["Dinesh Vasudevan"]
|
10
|
+
spec.email = ["dinesh.vasudevan@gmail.com"]
|
11
|
+
spec.summary = %q{ Generate an opinionated Simple Sinatra Application for API Backend }
|
12
|
+
spec.description = %q{ Generate an opinionated Simple Sinatra Application for API Backend }
|
13
|
+
spec.homepage = "https://github.com/dinks/simple_sinatra_api"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
spec.required_ruby_version = "~> 2.1"
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
|
25
|
+
spec.add_dependency "thor", "~> 0.19"
|
26
|
+
spec.add_dependency "activesupport", "~> 4.2"
|
27
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
SESSION_SECRET=djkahsjdhKy#378362kjhkjsppq
|
@@ -0,0 +1,30 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
ruby '2.1.2'
|
3
|
+
|
4
|
+
gem 'sinatra', require: 'sinatra/base'
|
5
|
+
|
6
|
+
gem 'dotenv'
|
7
|
+
|
8
|
+
gem 'json'
|
9
|
+
|
10
|
+
gem 'omniauth'
|
11
|
+
gem 'ruby-openid'
|
12
|
+
|
13
|
+
# DB
|
14
|
+
gem 'sequel'
|
15
|
+
gem 'sinatra-sequel'
|
16
|
+
|
17
|
+
# Support utility methods like years
|
18
|
+
gem 'activesupport', '~> 4.1.1'
|
19
|
+
|
20
|
+
group :development do
|
21
|
+
gem 'thin'
|
22
|
+
gem 'byebug'
|
23
|
+
|
24
|
+
gem 'sqlite3'
|
25
|
+
end
|
26
|
+
|
27
|
+
group :production do
|
28
|
+
gem 'sequel_postgresql_triggers'
|
29
|
+
gem 'pg'
|
30
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
web: bundle exec unicorn -c ./config/unicorn.rb
|
@@ -0,0 +1,38 @@
|
|
1
|
+
$: << File.expand_path('../', __FILE__)
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
Bundler.require
|
5
|
+
|
6
|
+
require 'dotenv'
|
7
|
+
Dotenv.load
|
8
|
+
|
9
|
+
require 'active_support/core_ext'
|
10
|
+
|
11
|
+
require 'app/routes'
|
12
|
+
require 'app/extensions'
|
13
|
+
|
14
|
+
module <%= name.camelize %>
|
15
|
+
class App < Sinatra::Application
|
16
|
+
|
17
|
+
configure do
|
18
|
+
set :database, ENV['DATABASE_URL'] || "sqlite://#{Dir.pwd}/development.sqlite"
|
19
|
+
|
20
|
+
set :protection, except: :session_hijacking
|
21
|
+
|
22
|
+
set :sessions,
|
23
|
+
httponly: true,
|
24
|
+
secure: false,
|
25
|
+
expire_after: 1.years,
|
26
|
+
secret: ENV['SESSION_SECRET']
|
27
|
+
end
|
28
|
+
|
29
|
+
use Rack::Deflater
|
30
|
+
|
31
|
+
use Routes::API
|
32
|
+
# Sample Route Added. Please replace with yours!
|
33
|
+
use Routes::Sample
|
34
|
+
|
35
|
+
use Routes::Error
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module <%= name.camelize %>
|
2
|
+
module Extensions
|
3
|
+
module API extend self
|
4
|
+
|
5
|
+
module Helpers
|
6
|
+
def json(value, options = {})
|
7
|
+
content_type :json
|
8
|
+
value.to_json({ a: 'test' }.merge(options))
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.registered(app)
|
13
|
+
app.helpers Helpers
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module <%= name.camelize %>
|
2
|
+
module Routes
|
3
|
+
class API < Sinatra::Application
|
4
|
+
configure do
|
5
|
+
disable :static
|
6
|
+
|
7
|
+
set :show_exceptions, false
|
8
|
+
end
|
9
|
+
|
10
|
+
before do
|
11
|
+
content_type :json
|
12
|
+
end
|
13
|
+
|
14
|
+
error do
|
15
|
+
halt 500, json({
|
16
|
+
code: 500,
|
17
|
+
message: request.env['sinatra.error'].to_s
|
18
|
+
})
|
19
|
+
end
|
20
|
+
|
21
|
+
register Extensions::API
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module <%= name.camelize %>
|
2
|
+
module Routes
|
3
|
+
class Error < Sinatra::Application
|
4
|
+
|
5
|
+
def error_404
|
6
|
+
halt 404, json({
|
7
|
+
code: 404,
|
8
|
+
message: "Page not found"
|
9
|
+
})
|
10
|
+
end
|
11
|
+
|
12
|
+
get "/*" do
|
13
|
+
error_404
|
14
|
+
end
|
15
|
+
|
16
|
+
post "/*" do
|
17
|
+
error_404
|
18
|
+
end
|
19
|
+
|
20
|
+
put "/*" do
|
21
|
+
error_404
|
22
|
+
end
|
23
|
+
|
24
|
+
patch "/*" do
|
25
|
+
error_404
|
26
|
+
end
|
27
|
+
|
28
|
+
delete "/*" do
|
29
|
+
error_404
|
30
|
+
end
|
31
|
+
|
32
|
+
register Extensions::API
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
worker_processes Integer(ENV['UNICORN_WORKERS'] || 4)
|
2
|
+
timeout 30
|
3
|
+
preload_app true
|
4
|
+
listen(ENV['PORT'] || 3000, backlog: Integer(ENV['UNICORN_BACKLOG'] || 200))
|
5
|
+
|
6
|
+
before_fork do |server, worker|
|
7
|
+
Signal.trap 'TERM' do
|
8
|
+
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
|
9
|
+
Process.kill 'QUIT', Process.pid
|
10
|
+
end
|
11
|
+
|
12
|
+
if defined?(Sequel::Model)
|
13
|
+
Sequel::DATABASES.each{ |db| db.disconnect }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
after_fork do |server, worker|
|
18
|
+
Signal.trap 'TERM' do
|
19
|
+
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to sent QUIT'
|
20
|
+
end
|
21
|
+
end
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_sinatra_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dinesh Vasudevan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.19'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.19'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.2'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.2'
|
69
|
+
description: " Generate an opinionated Simple Sinatra Application for API Backend "
|
70
|
+
email:
|
71
|
+
- dinesh.vasudevan@gmail.com
|
72
|
+
executables:
|
73
|
+
- simple_sinatra_api
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/simple_sinatra_api
|
83
|
+
- lib/simple_sinatra_api.rb
|
84
|
+
- lib/simple_sinatra_api/cli.rb
|
85
|
+
- lib/simple_sinatra_api/version.rb
|
86
|
+
- simple_sinatra_api.gemspec
|
87
|
+
- templates/new_app/.env
|
88
|
+
- templates/new_app/Gemfile
|
89
|
+
- templates/new_app/Procfile
|
90
|
+
- templates/new_app/README.md.tt
|
91
|
+
- templates/new_app/app.rb.tt
|
92
|
+
- templates/new_app/app/extensions.rb.tt
|
93
|
+
- templates/new_app/app/extensions/api.rb.tt
|
94
|
+
- templates/new_app/app/routes.rb.tt
|
95
|
+
- templates/new_app/app/routes/api.rb.tt
|
96
|
+
- templates/new_app/app/routes/error.rb.tt
|
97
|
+
- templates/new_app/app/routes/sample.rb.tt
|
98
|
+
- templates/new_app/config.ru.tt
|
99
|
+
- templates/new_app/config/unicorn.rb
|
100
|
+
- templates/new_app/development.db
|
101
|
+
homepage: https://github.com/dinks/simple_sinatra_api
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - "~>"
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '2.1'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.2.2
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Generate an opinionated Simple Sinatra Application for API Backend
|
125
|
+
test_files: []
|
126
|
+
has_rdoc:
|