voyage 1.44.0.10 → 1.44.0.11
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 020e914efdb3905ba6138a7f6254f4ca6b892875
|
4
|
+
data.tar.gz: 58588a11cad7bca57d36901847880b429ed67750
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f17b95dc22165a70acb1332c15735d3e3af887ce2e51da50fcabf79ef724168c0a9a938b64efbba9432c1e6aa7150f928265ae94c98e4c84c5600eb4e29c59b2
|
7
|
+
data.tar.gz: f4cff42782862f62f952b1e94727dea3457e62e376dbdd53ef0db9f6dd82ef60d87ae045d2a9d911e71ee4228b38fd7bfa0d513aeecb9315b31d80935e210db9
|
data/lib/voyage/app_builder.rb
CHANGED
@@ -555,6 +555,26 @@ module Suspenders
|
|
555
555
|
template '../templates/specs/support/request_spec_helper.rb', 'spec/support/request_spec_helper.rb', force: true
|
556
556
|
end
|
557
557
|
|
558
|
+
def add_api_foundation
|
559
|
+
# Create /app/api/base_api_controller.rb
|
560
|
+
template '../templates/api_base_controller.rb', 'app/controllers/api/base_api_controller.rb', force: true
|
561
|
+
|
562
|
+
# Create /app/api/v1/users_controller.rb
|
563
|
+
template '../templates/api_users_controller.rb', 'app/controllers/api/v1/users_controller.rb', force: true
|
564
|
+
|
565
|
+
# Update routes to include namespaced API
|
566
|
+
inject_into_file 'config/routes.rb', before: /^end/ do <<-RUBY.gsub(/^ {6}/, '')
|
567
|
+
|
568
|
+
# API-specific routes
|
569
|
+
namespace 'api' do
|
570
|
+
namespace 'v1' do
|
571
|
+
resources :users, except: [:new, :edit]
|
572
|
+
end
|
573
|
+
end
|
574
|
+
RUBY
|
575
|
+
end
|
576
|
+
end
|
577
|
+
|
558
578
|
def customize_application_js
|
559
579
|
template '../templates/application.js', 'app/assets/javascripts/application.js', force: true
|
560
580
|
|
@@ -48,6 +48,7 @@ module Suspenders
|
|
48
48
|
|
49
49
|
|
50
50
|
# Do these last
|
51
|
+
invoke :add_api_foundation
|
51
52
|
invoke :rake_db_setup
|
52
53
|
invoke :configure_rvm_prepend_bin_to_path
|
53
54
|
invoke :run_rubocop_auto_correct
|
@@ -151,6 +152,10 @@ module Suspenders
|
|
151
152
|
build :spin_up_webpacker
|
152
153
|
end
|
153
154
|
|
155
|
+
def add_api_foundation
|
156
|
+
build :add_api_foundation
|
157
|
+
end
|
158
|
+
|
154
159
|
def rake_db_setup
|
155
160
|
build :rake_db_setup
|
156
161
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Api
|
2
|
+
class BaseApiController < ApplicationController
|
3
|
+
# Disable CSRF protection for API calls
|
4
|
+
protect_from_forgery with: :null_session
|
5
|
+
|
6
|
+
# Disable cookie usage
|
7
|
+
before_action :destroy_session
|
8
|
+
|
9
|
+
# Handle objects that aren't found
|
10
|
+
rescue_from ActiveRecord::RecordNotFound, with: :not_found
|
11
|
+
|
12
|
+
def respond_with_errors(object)
|
13
|
+
serialized_errors = object.errors.messages.map do |field, errors|
|
14
|
+
errors.map do |error_message|
|
15
|
+
{
|
16
|
+
status: 422,
|
17
|
+
source: { pointer: "/data/attributes/#{field}" },
|
18
|
+
detail: error_message,
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end.flatten
|
22
|
+
|
23
|
+
render json: { errors: serialized_errors },
|
24
|
+
status: :unprocessable_entity
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def destroy_session
|
30
|
+
request.session_options[:skip] = true
|
31
|
+
end
|
32
|
+
|
33
|
+
def not_found
|
34
|
+
render json: { errors: 'Not found' },
|
35
|
+
status: 404
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Api
|
2
|
+
module V1
|
3
|
+
class UsersController < BaseApiController
|
4
|
+
authorize_resource
|
5
|
+
respond_to :json
|
6
|
+
|
7
|
+
def index
|
8
|
+
respond_with(User.all)
|
9
|
+
end
|
10
|
+
|
11
|
+
def show
|
12
|
+
@user = User.find(params[:id])
|
13
|
+
respond_with(@user)
|
14
|
+
end
|
15
|
+
|
16
|
+
def create
|
17
|
+
@user = User.new(user_params)
|
18
|
+
|
19
|
+
if @user.save
|
20
|
+
respond_with @user do |format|
|
21
|
+
format.json { render json: @user, status: :created }
|
22
|
+
end
|
23
|
+
else
|
24
|
+
respond_with_errors(@user)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def update
|
29
|
+
@user = User.find(params[:id])
|
30
|
+
|
31
|
+
if @user.update_attributes(user_params)
|
32
|
+
respond_with(@user)
|
33
|
+
else
|
34
|
+
respond_with_errors(@user)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def destroy
|
39
|
+
user = User.find(params[:id])
|
40
|
+
|
41
|
+
if user.destroy
|
42
|
+
render json: {}, status: 204
|
43
|
+
else
|
44
|
+
render json: {}, status: 500
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def user_params
|
51
|
+
params.require(:user).permit(:first_name, :last_name, :email,
|
52
|
+
:password, :password_confirmation)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/voyage/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: voyage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.44.0.
|
4
|
+
version: 1.44.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thoughtbot, headway
|
@@ -114,6 +114,8 @@ files:
|
|
114
114
|
- lib/voyage/templates/analytics_alias.html.erb.erb
|
115
115
|
- lib/voyage/templates/analytics_identify.html.erb.erb
|
116
116
|
- lib/voyage/templates/analytics_ruby_initializer.rb
|
117
|
+
- lib/voyage/templates/api_base_controller.rb
|
118
|
+
- lib/voyage/templates/api_users_controller.rb
|
117
119
|
- lib/voyage/templates/application.js
|
118
120
|
- lib/voyage/templates/application_mailer.rb.erb
|
119
121
|
- lib/voyage/templates/auto_annotate_models.rake
|