grape-gen 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/bin/grape-gen +5 -0
- data/grape-scaffold.gemspec +24 -0
- data/lib/grape/generate/version.rb +5 -0
- data/lib/grape/generate.rb +91 -0
- data/template/Gemfile.tt +95 -0
- data/template/Guardfile +20 -0
- data/template/abilities/api_ability.rb +15 -0
- data/template/api/api_app.rb +85 -0
- data/template/api/mounts/auth.rb.tt +42 -0
- data/template/api/mounts/profile.rb.tt +24 -0
- data/template/config/application.yml.tt +33 -0
- data/template/config/boot.rb.tt +85 -0
- data/template/config/boot_faye.rb +22 -0
- data/template/config/boot_sidekiq.rb.tt +33 -0
- data/template/config/boot_spec.rb.tt +85 -0
- data/template/config/database.rb.tt +6 -0
- data/template/config/database.yml.tt +21 -0
- data/template/config/initializers/carrierwave.rb +3 -0
- data/template/config/initializers/core_ext.rb +14 -0
- data/template/config/initializers/em-patches/carrierwave.rb +13 -0
- data/template/config/initializers/em-patches/faye.rb +4 -0
- data/template/config/initializers/em-patches/lazy_evaluated_pool.rb +35 -0
- data/template/config/initializers/em-patches/mandrill.rb +45 -0
- data/template/config/initializers/em-patches/redis.rb +13 -0
- data/template/config/initializers/em-patches/redis_lazy_evaluated_pool.rb +19 -0
- data/template/config/initializers/em-patches/sidekiq.rb +46 -0
- data/template/config/initializers/em-patches/tire.rb +8 -0
- data/template/config/initializers/faye.rb +3 -0
- data/template/config/initializers/grape.rb +11 -0
- data/template/config/initializers/logging.rb +38 -0
- data/template/config/initializers/mandrill.rb +1 -0
- data/template/config/initializers/patches/redis_namespace.rb +96 -0
- data/template/config/initializers/sidekiq.rb +15 -0
- data/template/config/initializers/tire.rb +6 -0
- data/template/config/initializers/workflow.rb +31 -0
- data/template/config/logging.yml.tt +39 -0
- data/template/config/settings.rb +24 -0
- data/template/config/sidekiq.yml.tt +22 -0
- data/template/config.ru.tt +8 -0
- data/template/faye.ru +55 -0
- data/template/jobs/pong_time.rb +11 -0
- data/template/lib/faye_auth_extension.rb +61 -0
- data/template/lib/faye_publisher.rb +63 -0
- data/template/lib/mongoid/tire_plugin.rb +17 -0
- data/template/lib/warden/token_strategy.rb +18 -0
- data/template/mailers/registration_mailer.rb +17 -0
- data/template/models/user.rb.tt +75 -0
- data/template/public/faye.html +36 -0
- data/template/search_indexes/search_index.rb +60 -0
- data/template/search_indexes/user_index.rb +20 -0
- data/template/spec/api/mounts/auth_spec.rb.tt +37 -0
- data/template/spec/factories/user.rb +8 -0
- data/template/spec/spec_helper.rb.tt +132 -0
- data/template/uploaders/avatar_uploader.rb +23 -0
- data/template/views/v1/user/profile.json.jbuilder.tt +4 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d7f28bfcaadc1cb321a828f7c4894eff2962b043
|
4
|
+
data.tar.gz: b33f27008effe93350e091eb781156bbecb5f426
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f8140102fd00109d2e5f58084e38ed08c70cea5d5df9b7b0d61e80e7bca6b652132f49b978247766681d8ca90988d28a53c73999e09a107cb655dd420baad188
|
7
|
+
data.tar.gz: 5f49879d8caae93ffbcfa9c25ed5d0eb2b4b43b72b5969bf036e38ba66de434bd84183951ec0a24431a40ddf5736073c838690f97eb6f8067d99379d6f18afb2
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 AMar4enko
|
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,31 @@
|
|
1
|
+
# Grape::Scaffold
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'grape-scaffold'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install grape-scaffold
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/grape-scaffold/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/grape-gen
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'grape/generate/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'grape-gen'
|
8
|
+
spec.version = Grape::Generate::VERSION
|
9
|
+
spec.authors = ['AMar4enko']
|
10
|
+
spec.email = ['amar4enko@gmail.com']
|
11
|
+
spec.summary = %q{Grape-powered rack application generator with batteries included}
|
12
|
+
spec.homepage = 'https://github.com/AlexYankee/grape-gen'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_runtime_dependency 'thor', '~> 0.19.1'
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'grape/generate/version'
|
2
|
+
require 'bundler/vendor/thor'
|
3
|
+
|
4
|
+
module Grape
|
5
|
+
module Generate
|
6
|
+
BATTERIES = %w{sidekiq carrierwave mandrill es faye}
|
7
|
+
class CLI < Thor
|
8
|
+
include Thor::Actions
|
9
|
+
|
10
|
+
source_root File.expand_path('../../template', File.dirname(__FILE__))
|
11
|
+
|
12
|
+
desc 'app APP_NAME', 'Guides you through Grape app scaffolding process'
|
13
|
+
option :path
|
14
|
+
option :orm, default: 'mongoid'
|
15
|
+
option :batteries,
|
16
|
+
type: :array,
|
17
|
+
default: Generate::BATTERIES,
|
18
|
+
desc: 'Batteries to include'
|
19
|
+
|
20
|
+
option :'use-grape-rackbuilder', type: :boolean, default: true
|
21
|
+
|
22
|
+
attr_accessor *Generate::BATTERIES
|
23
|
+
|
24
|
+
def app(app_name)
|
25
|
+
Generate::BATTERIES.each do |v|
|
26
|
+
send("#{v}=", options[:batteries].include?(v))
|
27
|
+
end
|
28
|
+
|
29
|
+
@app_name = app_name
|
30
|
+
|
31
|
+
@orm = options[:orm]
|
32
|
+
@dev_reload = options[:'use-grape-rackbuilder']
|
33
|
+
|
34
|
+
begin
|
35
|
+
FileUtils.rm_r(options[:path] || app_name.downcase)
|
36
|
+
rescue
|
37
|
+
end
|
38
|
+
|
39
|
+
self.destination_root = options[:path] || app_name.downcase
|
40
|
+
@redis = true
|
41
|
+
@faye_secret = Digest::MD5.hexdigest('%s-%s'%[app_name,Time.now.to_s])
|
42
|
+
|
43
|
+
directory './', exclude_pattern: /(sidekiq|carrierwave|faye|mandrill|tire|elastic_search|search_indexes|mailers|uploaders|jobs)/
|
44
|
+
|
45
|
+
directory './log'
|
46
|
+
directory './tmp/pids'
|
47
|
+
|
48
|
+
@redis ||= @sidekiq || @faye
|
49
|
+
|
50
|
+
if @faye
|
51
|
+
template './faye.ru'
|
52
|
+
copy_file './config/boot_faye.rb'
|
53
|
+
copy_file './config/initializers/faye.rb'
|
54
|
+
copy_file './config/initializers/em-patches/faye.rb'
|
55
|
+
copy_file './public/faye.html'
|
56
|
+
copy_file './lib/faye_auth_extension.rb'
|
57
|
+
copy_file './lib/faye_publisher.rb'
|
58
|
+
end
|
59
|
+
|
60
|
+
if @sidekiq
|
61
|
+
if @faye
|
62
|
+
copy_file './jobs/pong_time.rb'
|
63
|
+
end
|
64
|
+
copy_file './config/initializers/sidekiq.rb'
|
65
|
+
copy_file './config/initializers/em-patches/sidekiq.rb'
|
66
|
+
template './config/sidekiq.yml'
|
67
|
+
template './config/boot_sidekiq.rb'
|
68
|
+
end
|
69
|
+
|
70
|
+
if @mandrill
|
71
|
+
copy_file './config/initializers/mandrill.rb'
|
72
|
+
copy_file './config/initializers/em-patches/mandrill.rb'
|
73
|
+
directory './mailers'
|
74
|
+
end
|
75
|
+
|
76
|
+
if @es
|
77
|
+
template './config/initializers/tire.rb'
|
78
|
+
copy_file './config/initializers/em-patches/tire.rb'
|
79
|
+
copy_file './lib/mongoid/tire_plugin.rb'
|
80
|
+
directory './search_indexes'
|
81
|
+
end
|
82
|
+
|
83
|
+
if @carrierwave
|
84
|
+
copy_file './config/initializers/em-patches/carrierwave.rb'
|
85
|
+
copy_file './config/initializers/carrierwave.rb'
|
86
|
+
directory './uploaders'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/template/Gemfile.tt
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Web frameworks related
|
4
|
+
group :framework do
|
5
|
+
gem 'grape', '~> 0.10'
|
6
|
+
<%- if @dev_reload -%>
|
7
|
+
gem 'grape-reload', github: 'AlexYankee/grape-reload'
|
8
|
+
<%- end -%>
|
9
|
+
gem 'warden', '~> 1.2.3'
|
10
|
+
gem 'grape-jbuilder', '~> 0.2.0'
|
11
|
+
gem 'jbuilder', '~> 2.2.5'
|
12
|
+
gem 'rack-cors', '~> 0.2.9'
|
13
|
+
end
|
14
|
+
# ORM
|
15
|
+
group :db do
|
16
|
+
<%- case @orm
|
17
|
+
when 'mongoid' -%>
|
18
|
+
gem 'mongoid', '~> 4.0.0'
|
19
|
+
gem 'mongoid-paranoia', '~> 1.0.0'
|
20
|
+
<%- if @carrierwave -%>
|
21
|
+
gem 'carrierwave-mongoid', '~> 0.7.1'
|
22
|
+
<%- end -%>
|
23
|
+
<%- else -%>
|
24
|
+
<%- end -%>
|
25
|
+
<%- if @carrierwave -%>
|
26
|
+
gem 'carrierwave', '~> 0.10.0'
|
27
|
+
gem 'mini_magick', '~> 4.0.2'
|
28
|
+
<%- end -%>
|
29
|
+
gem 'workflow', '~> 1.2.0'
|
30
|
+
end
|
31
|
+
<% if @sidekiq -%>
|
32
|
+
# Background job
|
33
|
+
group :sidekiq do
|
34
|
+
gem 'sidekiq', '~> 3.2.6'
|
35
|
+
gem 'sidekiq-middleware', '~> 0.3.0'
|
36
|
+
gem 'sidekiq-scheduler', github: 'preplay/sidekiq-scheduler', ref: '4b8abd1f256ff3e577a666c181437bd5f4590438'
|
37
|
+
end
|
38
|
+
<% end -%>
|
39
|
+
<%- if @mandrill -%>
|
40
|
+
# Mailing
|
41
|
+
group :mailer do
|
42
|
+
gem 'mandrill_mailer', '~> 0.5.1'
|
43
|
+
end
|
44
|
+
<%- end -%>
|
45
|
+
# Utils
|
46
|
+
group :utils do
|
47
|
+
gem 'settingslogic', '~> 2.0.9'
|
48
|
+
gem 'logging', '~> 1.8.2'
|
49
|
+
gem 'bcrypt', '~> 3.1.7'
|
50
|
+
gem 'cancancan', '~> 1.9.2'
|
51
|
+
gem 'hashie', '~> 3.3.2'
|
52
|
+
gem 'activesupport', '~> 4.2'
|
53
|
+
gem 'multi_json', '~> 1.10.1'
|
54
|
+
gem 'oj', '~> 2.11.2'
|
55
|
+
end
|
56
|
+
<%- if @es -%>
|
57
|
+
# ElasticSearch
|
58
|
+
group :elastic_search do
|
59
|
+
gem 'tire', '~> 0.6.2'
|
60
|
+
gem 'faraday', '~> 0.9.1'
|
61
|
+
end
|
62
|
+
<%- end -%>
|
63
|
+
group :eventmachine do
|
64
|
+
<%- if @redis -%>
|
65
|
+
gem 'em-hiredis'
|
66
|
+
<%- end -%>
|
67
|
+
gem 'em-synchrony', github: 'igrigorik/em-synchrony'
|
68
|
+
end
|
69
|
+
<%- if @faye -%>
|
70
|
+
group :faye do
|
71
|
+
gem 'faye', '~> 1.0.1'
|
72
|
+
<%- if @redis -%>
|
73
|
+
gem 'faye-redis'
|
74
|
+
<%- end -%>
|
75
|
+
end
|
76
|
+
<%- end -%>
|
77
|
+
# Server
|
78
|
+
group :rack_server do
|
79
|
+
gem 'thin', '~> 1.6.3'
|
80
|
+
gem 'rake', '~> 10.3.2'
|
81
|
+
gem 'rack-fiber_pool', '~> 0.9.1'
|
82
|
+
end
|
83
|
+
group :test do
|
84
|
+
gem 'rack-test', '~> 0.6.3'
|
85
|
+
gem 'database_cleaner', '~> 1.3.0'
|
86
|
+
gem 'faker', '~> 1.4.3'
|
87
|
+
gem 'factory_girl', '~> 4.5.0'
|
88
|
+
gem 'guard', '~> 2.6.1'
|
89
|
+
gem 'guard-spork', '~> 1.5.1'
|
90
|
+
gem 'guard-rspec', '~> 4.3.1'
|
91
|
+
gem 'rspec', '~> 3.1.0'
|
92
|
+
gem 'spork', github: 'manafire/spork', branch: 'rspec3_runner'
|
93
|
+
gem 'terminal-notifier-guard', '~> 1.5.3'
|
94
|
+
gem 'rspec_api_documentation', '~> 4.3.0'
|
95
|
+
end
|
data/template/Guardfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
notification :terminal_notifier
|
2
|
+
|
3
|
+
guard 'spork', rspec_env: { 'RACK_ENV' => 'test' } do
|
4
|
+
watch('config/.+\.rb')
|
5
|
+
watch('Gemfile.lock')
|
6
|
+
watch(%r{^spec/factories/.+\.rb$})
|
7
|
+
watch('spec/spec_helper.rb') { :rspec }
|
8
|
+
end
|
9
|
+
|
10
|
+
guard :rspec, cmd: 'bundle exec rspec --drb --color --format progress' do
|
11
|
+
watch(%r{^spec/.+_spec\.rb$})
|
12
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
13
|
+
watch('spec/spec_helper.rb') { "spec" }
|
14
|
+
|
15
|
+
watch(%r{^api/mounts/(.+)\.rb$}) { |m| "spec/api/mounts/#{m[1]}_spec.rb" }
|
16
|
+
watch(%r{^models/(.+)\.rb$}) { |m| "spec/models/#{m[1]}_spec.rb" }
|
17
|
+
watch(%r{^abilities/(.+)\.rb$}) { |m| "spec/abilities/#{m[1]}_spec.rb" }
|
18
|
+
watch(%r{^views/(v[^/]+)/\.rb$}) { |m| "spec/api/**/*.rb" }
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class ApiAbility
|
2
|
+
include CanCan::Ability
|
3
|
+
def initialize(user)
|
4
|
+
return unless user
|
5
|
+
alias_action :view, :create, :update, :delete, to: :crud
|
6
|
+
|
7
|
+
can :update_profile, user
|
8
|
+
can :view, Models::User
|
9
|
+
can :update, Models::User, { id: user.id }
|
10
|
+
|
11
|
+
if user.role == :admin
|
12
|
+
can :crud, :all
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module API
|
2
|
+
class Application < Grape::API
|
3
|
+
format :json
|
4
|
+
formatter :json, Grape::Formatter::Jbuilder
|
5
|
+
|
6
|
+
logger Logging.logger[:api]
|
7
|
+
|
8
|
+
helpers do
|
9
|
+
def logger; API::Application.logger end
|
10
|
+
|
11
|
+
def ability
|
12
|
+
@_ability ||= ApiAbility.new(current_user)
|
13
|
+
end
|
14
|
+
|
15
|
+
def authorize!(*args)
|
16
|
+
error! :unauthorized, 401 unless ability.can?(*args)
|
17
|
+
end
|
18
|
+
def current_user
|
19
|
+
warden.authenticate(:access_token)
|
20
|
+
end
|
21
|
+
|
22
|
+
def warden; env['warden'] end
|
23
|
+
|
24
|
+
def error!(msg, error = 400)
|
25
|
+
super(msg, error, header)
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_locals(locals_hash)
|
29
|
+
env['api.tilt.locals'] = locals_hash
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_locals(locals_hash)
|
33
|
+
env['api.tilt.locals'] = (env['api.tilt.locals'] || {}).merge(locals_hash)
|
34
|
+
end
|
35
|
+
|
36
|
+
def redis
|
37
|
+
REDIS_CONNECTION
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
route [:get, :post, :put, :patch], :unauthenticated do
|
42
|
+
error! :unauthenticated, 401
|
43
|
+
end
|
44
|
+
|
45
|
+
before do
|
46
|
+
header('Access-Control-Allow-Origin', '*')
|
47
|
+
header('Access-Control-Allow-Methods', '*')
|
48
|
+
header('Access-Control-Allow-Headers', 'Content-Type,Accept-Version,X-Authorize')
|
49
|
+
end
|
50
|
+
|
51
|
+
rescue_from Mongoid::Errors::DocumentNotFound do
|
52
|
+
Rack::Response.new(['Not found'], 404, env['api.endpoint'].header).finish
|
53
|
+
end
|
54
|
+
|
55
|
+
rescue_from :all do |exception|
|
56
|
+
API::Application.logger.error exception
|
57
|
+
Rack::Response.new(['Error'], 500, env['api.endpoint'].header).finish
|
58
|
+
end
|
59
|
+
|
60
|
+
rescue_from Grape::Exceptions::ValidationErrors do |exception|
|
61
|
+
body = [MultiJson.dump(validation: exception.errors.map{|params, errors| Hash[params.zip([errors.first.to_s] * params.length)]}.inject({},&:merge))]
|
62
|
+
Rack::Response.new(body, 400, env['api.endpoint'].header).finish
|
63
|
+
end
|
64
|
+
|
65
|
+
rescue_from Mongoid::Errors::Validations do |exception|
|
66
|
+
body = [MultiJson.dump(validation: exception.document.errors.messages.map{|attr, errors| {attr => errors.first}}.inject({},&:merge))]
|
67
|
+
Rack::Response.new(body, 400, env['api.endpoint'].header).finish
|
68
|
+
end
|
69
|
+
|
70
|
+
mount Mounts::Auth => '/auth'
|
71
|
+
mount Mounts::Profile => '/profile'
|
72
|
+
|
73
|
+
get :ping do
|
74
|
+
{pong: true}
|
75
|
+
end
|
76
|
+
|
77
|
+
post :redis_write do
|
78
|
+
{result: redis.set('redis_key', Time.now.to_s)}
|
79
|
+
end
|
80
|
+
|
81
|
+
get :redis_read do
|
82
|
+
{result: redis.get('redis_key')}
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module API
|
2
|
+
module Mounts
|
3
|
+
class Auth < Grape::API
|
4
|
+
params do
|
5
|
+
requires :display_name, type: String
|
6
|
+
requires :email, type: String
|
7
|
+
end
|
8
|
+
post :register do
|
9
|
+
params[:email] = params[:email].downcase
|
10
|
+
user = Models::User.where(email: params[:email]).first
|
11
|
+
if user
|
12
|
+
error! :waiting_for_approvement if user.registered?
|
13
|
+
error! :already_exists, 400
|
14
|
+
end
|
15
|
+
|
16
|
+
user = Models::User.register(declared(params, include_missing: false))
|
17
|
+
|
18
|
+
<%- if @mandrill -%>
|
19
|
+
begin
|
20
|
+
RegistrationMailer.registered(user).deliver
|
21
|
+
rescue
|
22
|
+
logger.error $!
|
23
|
+
end
|
24
|
+
<%- end -%>
|
25
|
+
end
|
26
|
+
|
27
|
+
params do
|
28
|
+
requires :email, type: String
|
29
|
+
requires :email_approvement_code, type: String
|
30
|
+
end
|
31
|
+
post :approve_email, jbuilder: 'v1/user/profile.json' do
|
32
|
+
@user = Models::User.find_by(email: params[:email].downcase, email_approvement_code: params[:email_approvement_code])
|
33
|
+
@user.email_approved!
|
34
|
+
@user.save
|
35
|
+
header['X-Authorize'] = @user.token
|
36
|
+
<% if @faye %>
|
37
|
+
FayePublisher.publish('/user/registered', {display_name: @user.display_name})
|
38
|
+
<% end %>
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module API
|
2
|
+
module Mounts
|
3
|
+
class Profile < Grape::API
|
4
|
+
before {
|
5
|
+
@user = current_user
|
6
|
+
authorize! :update_profile, @user
|
7
|
+
}
|
8
|
+
params do
|
9
|
+
optional :display_name
|
10
|
+
<% if @carrierwave %>
|
11
|
+
optional :avatar
|
12
|
+
optional :remove_avatar
|
13
|
+
mutually_exclusive :avatar, :remove_avatar
|
14
|
+
<% end %>
|
15
|
+
end
|
16
|
+
put jbuilder: 'v1/user/profile.json' do
|
17
|
+
declared(params, include_missing: false).each {|k,v| @user.send("#{k}=", v) }
|
18
|
+
@user.save!
|
19
|
+
end
|
20
|
+
|
21
|
+
get jbuilder: 'v1/user/profile.json'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
development: &dev
|
2
|
+
api_root: http://localhost:9292/api
|
3
|
+
<% if @redis -%>
|
4
|
+
redis:
|
5
|
+
url: redis://localhost:6379/0
|
6
|
+
size: 20
|
7
|
+
<% end -%>
|
8
|
+
<% if @mandrill -%>
|
9
|
+
mandrill:
|
10
|
+
api_key: your_mandrill_key
|
11
|
+
<% end -%>
|
12
|
+
<% if @es -%>
|
13
|
+
elasticsearch:
|
14
|
+
url: http://localhost:9200
|
15
|
+
<% end -%>
|
16
|
+
<% if @faye -%>
|
17
|
+
faye:
|
18
|
+
server_secret: <%= @faye_secret %>
|
19
|
+
redis:
|
20
|
+
url: redis://localhost:6379/0
|
21
|
+
namespace: faye
|
22
|
+
size: 20 # Pool size
|
23
|
+
<% end -%>
|
24
|
+
<% if @sidekiq %>
|
25
|
+
sidekiq:
|
26
|
+
redis:
|
27
|
+
url: redis://localhost:6379/0
|
28
|
+
size: 20 # Pool size
|
29
|
+
<% end %>
|
30
|
+
|
31
|
+
production: *dev
|
32
|
+
test:
|
33
|
+
api_root: http://localhost/api
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# Defines our constants
|
2
|
+
RACK_ENV = ENV['RACK_ENV'] || 'development' unless defined?(RACK_ENV)
|
3
|
+
APP_ROOT = File.expand_path('../..', __FILE__) unless defined?(APP_ROOT)
|
4
|
+
|
5
|
+
# Load our dependencies
|
6
|
+
require 'rubygems' unless defined?(Gem)
|
7
|
+
require 'bundler/setup'
|
8
|
+
require 'yaml'
|
9
|
+
|
10
|
+
# Load initializers
|
11
|
+
Bundler.require(
|
12
|
+
:framework,
|
13
|
+
:db,
|
14
|
+
<% if @sidekiq -%>
|
15
|
+
:sidekiq,
|
16
|
+
<% end -%>
|
17
|
+
<% if @mandrill -%>
|
18
|
+
:mailer,
|
19
|
+
<% end -%>
|
20
|
+
:utils,
|
21
|
+
<% if @es -%>
|
22
|
+
:elastic_search,
|
23
|
+
<% end -%>
|
24
|
+
:eventmachine,
|
25
|
+
:rack_server,
|
26
|
+
RACK_ENV
|
27
|
+
)
|
28
|
+
|
29
|
+
require_relative 'settings'
|
30
|
+
|
31
|
+
ApplicationSettings.source File.expand_path('config/application.yml', APP_ROOT)
|
32
|
+
ApplicationSettings.root = APP_ROOT
|
33
|
+
|
34
|
+
require_relative 'database'
|
35
|
+
|
36
|
+
Dir[ApplicationSettings.root('config/initializers/em-patches/*.rb')].each {|initializer| require initializer}
|
37
|
+
Dir[ApplicationSettings.root('config/initializers/*.rb')].each {|initializer| require initializer}
|
38
|
+
|
39
|
+
|
40
|
+
REDIS_CONNECTION = RedisLazyEvaluatedPool.pool_with_config(ApplicationSettings.redis)
|
41
|
+
|
42
|
+
<% if @dev_reload %>
|
43
|
+
RACK_APPLICATION = Grape::RackBuilder.setup do
|
44
|
+
%w{api models lib uploaders models abilities jobs search_indexes mailers}.each do |path|
|
45
|
+
add_source_path ApplicationSettings.root("#{path}/**/*.rb")
|
46
|
+
add_source_path ApplicationSettings.root("#{path}/*.rb")
|
47
|
+
end
|
48
|
+
|
49
|
+
use Warden::Manager do |config|
|
50
|
+
config.strategies.add(:access_token, TokenStrategy)
|
51
|
+
config.default_strategies :access_token
|
52
|
+
config.failure_app = API::Application
|
53
|
+
config.intercept_401 = false
|
54
|
+
end
|
55
|
+
|
56
|
+
use Rack::Config do |env|
|
57
|
+
env['api.tilt.root'] = ApplicationSettings.root('views')
|
58
|
+
end
|
59
|
+
|
60
|
+
mount 'API::Application', to: '/api'
|
61
|
+
|
62
|
+
logger Logging.logger[:rackbuilder]
|
63
|
+
end.boot!.application
|
64
|
+
<% else %>
|
65
|
+
%w{lib models uploaders models abilities jobs search_indexes mailers api}.each do |path|
|
66
|
+
Dir[ApplicationSettings.root("#{path}/**/*.rb")].each {|f| require f}
|
67
|
+
end
|
68
|
+
|
69
|
+
RACK_APPLICATION = Rack::Builder.new do
|
70
|
+
use Warden::Manager do |config|
|
71
|
+
config.strategies.add(:access_token, TokenStrategy)
|
72
|
+
config.default_strategies :access_token
|
73
|
+
config.failure_app = API::Application
|
74
|
+
config.intercept_401 = false
|
75
|
+
end
|
76
|
+
|
77
|
+
use Rack::Config do |env|
|
78
|
+
env['api.tilt.root'] = ApplicationSettings.root('views')
|
79
|
+
end
|
80
|
+
|
81
|
+
map '/api' do
|
82
|
+
run API::Application
|
83
|
+
end
|
84
|
+
end
|
85
|
+
<% end %>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Defines our constants
|
2
|
+
RACK_ENV = :production
|
3
|
+
APP_ROOT = File.expand_path('../..', __FILE__) unless defined?(APP_ROOT)
|
4
|
+
|
5
|
+
# Load our dependencies
|
6
|
+
require 'rubygems' unless defined?(Gem)
|
7
|
+
require 'bundler/setup'
|
8
|
+
# Load initializers
|
9
|
+
Bundler.require(:faye, RACK_ENV)
|
10
|
+
require 'warden'
|
11
|
+
require 'active_support/core_ext/hash/keys'
|
12
|
+
require 'hashie/mash'
|
13
|
+
require 'redis-namespace'
|
14
|
+
require_relative 'initializers/patches/redis_namespace'
|
15
|
+
require_relative 'settings'
|
16
|
+
|
17
|
+
ApplicationSettings.source File.expand_path('config/application.yml', APP_ROOT)
|
18
|
+
ApplicationSettings.root = APP_ROOT
|
19
|
+
|
20
|
+
require_relative 'initializers/logging'
|
21
|
+
require_relative '../lib/faye_auth_extension'
|
22
|
+
require_relative '../lib/faye_publisher'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Load our dependencies
|
2
|
+
require 'rubygems' unless defined?(Gem)
|
3
|
+
require 'bundler/setup'
|
4
|
+
|
5
|
+
Bundler.require(:utils, :db)
|
6
|
+
Bundler.require(
|
7
|
+
:sidekiq,
|
8
|
+
<% if @mandrill -%>
|
9
|
+
:mailer,
|
10
|
+
<% end -%>
|
11
|
+
<% if @es -%>
|
12
|
+
:elastic_search,
|
13
|
+
<% end -%>
|
14
|
+
)
|
15
|
+
|
16
|
+
# Defines our constants
|
17
|
+
RACK_ENV = Sidekiq.options[:environment] || ENV['RACK_ENV'] || :development
|
18
|
+
APP_ROOT = File.expand_path('../..', __FILE__) unless defined?(APP_ROOT)
|
19
|
+
Bundler.require(RACK_ENV)
|
20
|
+
|
21
|
+
require 'warden'
|
22
|
+
|
23
|
+
require_relative 'settings'
|
24
|
+
|
25
|
+
ApplicationSettings.source File.expand_path('config/application.yml', APP_ROOT)
|
26
|
+
ApplicationSettings.root = APP_ROOT
|
27
|
+
|
28
|
+
# Load initializers
|
29
|
+
Dir[ApplicationSettings.root('config/initializers/*.rb')].each {|file_name| require file_name}
|
30
|
+
|
31
|
+
%w{lib jobs uploaders models search_indexes}.each do |path|
|
32
|
+
Dir[ApplicationSettings.root("#{path}/**/*.rb")].each {|f| require f}
|
33
|
+
end
|