bullet_train-api 1.0.2 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/api/v1/teams_endpoint.rb +5 -75
- data/app/controllers/api.rb +6 -3
- data/app/controllers/concerns/api/v1/base.rb +30 -0
- data/app/controllers/concerns/api/v1/teams/endpoint_base.rb +87 -0
- data/config/routes.rb +2 -0
- data/lib/bullet_train/api/engine.rb +6 -0
- data/lib/bullet_train/api/version.rb +1 -1
- data/lib/bullet_train/api.rb +1 -1
- metadata +4 -3
- data/app/controllers/api/v1/root.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 032d9344239258c4279f3a04e1aecbce98a4ef7f7a74a2c568047b64b348f2f0
|
4
|
+
data.tar.gz: a1d2970d2d64dab6a2e3fd192afda710e150ea7524f1f2635868864b9ccd8025
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a58f1503b3d11a2c7c46552d91a4e0c40bb9b258945501f4eb8146af4185f97d3ad73d05c729514319e0ad85d28eef71cf3d83024256a59389dfd79ed8d47e1
|
7
|
+
data.tar.gz: 7f44279ae68331a9513bcd4c54572da1ea3a14483ef54e9dccf9b393b30bc80eb73a96e87fb71ded864db3cf55df12eda712c91a80203410fd722cf26b65ec37
|
@@ -1,79 +1,9 @@
|
|
1
1
|
class Api::V1::TeamsEndpoint < Api::V1::Root
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
params :team do
|
8
|
-
optional :name, type: String, allow_blank: false, desc: Api.heading(:name)
|
9
|
-
optional :locale, type: String, desc: Api.heading(:locale)
|
10
|
-
# 🚅 super scaffolding will insert new fields above this line.
|
11
|
-
# 🚅 super scaffolding will insert new arrays above this line.
|
12
|
-
|
13
|
-
# 🚅 super scaffolding will insert processing for new fields above this line.
|
14
|
-
end
|
2
|
+
PARAMS = proc do
|
3
|
+
# 🚅 super scaffolding will insert new fields above this line.
|
4
|
+
# 🚅 super scaffolding will insert new arrays above this line.
|
5
|
+
# 🚅 super scaffolding will insert processing for new fields above this line.
|
15
6
|
end
|
16
7
|
|
17
|
-
|
18
|
-
after_validation do
|
19
|
-
load_and_authorize_api_resource Team
|
20
|
-
end
|
21
|
-
|
22
|
-
desc Api.title(:index), &Api.index_desc
|
23
|
-
oauth2
|
24
|
-
paginate per_page: 100
|
25
|
-
get "/" do
|
26
|
-
@paginated_teams = paginate @teams
|
27
|
-
render @paginated_teams, serializer: Api.serializer, adapter: :attributes
|
28
|
-
end
|
29
|
-
|
30
|
-
desc Api.title(:show), &Api.show_desc
|
31
|
-
params do
|
32
|
-
use :id
|
33
|
-
end
|
34
|
-
oauth2
|
35
|
-
route_param :id do
|
36
|
-
get do
|
37
|
-
render @team, serializer: Api.serializer
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
desc Api.title(:create), &Api.create_desc
|
42
|
-
params do
|
43
|
-
use :team
|
44
|
-
end
|
45
|
-
route_setting :api_resource_options, permission: :create
|
46
|
-
oauth2 "write"
|
47
|
-
post "/" do
|
48
|
-
if @team.save
|
49
|
-
# sets the team creator as the default admin
|
50
|
-
@team.memberships.create(user: current_user, roles: [Role.admin])
|
51
|
-
|
52
|
-
current_user.current_team = @team
|
53
|
-
current_user.former_user = false
|
54
|
-
current_user.save
|
55
|
-
|
56
|
-
render @team, serializer: Api.serializer
|
57
|
-
else
|
58
|
-
record_not_saved @team
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
desc Api.title(:update), &Api.update_desc
|
63
|
-
params do
|
64
|
-
use :id
|
65
|
-
use :team
|
66
|
-
end
|
67
|
-
route_setting :api_resource_options, permission: :update
|
68
|
-
oauth2 "write"
|
69
|
-
route_param :id do
|
70
|
-
put do
|
71
|
-
if @team.update(declared(params, include_missing: false))
|
72
|
-
render @team, serializer: Api.serializer
|
73
|
-
else
|
74
|
-
record_not_saved @team
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
8
|
+
include Api::V1::Teams::EndpointBase
|
79
9
|
end
|
data/app/controllers/api.rb
CHANGED
@@ -6,9 +6,12 @@
|
|
6
6
|
|
7
7
|
module Api
|
8
8
|
def self.topic
|
9
|
-
path = caller.find { |path| path.include?("controllers/api") && !path.include?("app/controllers/api.rb") }
|
10
|
-
path.
|
11
|
-
|
9
|
+
path = caller.find { |path| (path.include?("controllers/api") || path.include?("app/controllers/concerns/api")) && !path.include?("app/controllers/api.rb") && !path.include?("app/controllers/api/v1/root.rb") && !path.include?("app/controllers/api/base.rb") }
|
10
|
+
if path.include?("controllers/api")
|
11
|
+
path.split(/\/app\/controllers\/api\/v\d+\//).last.split("_endpoint.").first
|
12
|
+
elsif path.include?("app/controllers/concerns/api")
|
13
|
+
path.split(/\/app\/controllers\/concerns\/api\/v\d+\//).last.split("/endpoint_base.").first
|
14
|
+
end
|
12
15
|
end
|
13
16
|
|
14
17
|
def self.serializer
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Api::V1::Base
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
include Api::V1::Defaults
|
6
|
+
include Api::V1::LoadsAndAuthorizesApiResource
|
7
|
+
|
8
|
+
version "v1"
|
9
|
+
use ::WineBouncer::OAuth2
|
10
|
+
|
11
|
+
rescue_from :all do |error|
|
12
|
+
handle_api_error(error)
|
13
|
+
end
|
14
|
+
|
15
|
+
BulletTrain::Api.endpoints.each do |endpoint_class|
|
16
|
+
mount endpoint_class.constantize
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class_methods do
|
21
|
+
# TODO I actually don't know of any way to make this work. This was supposed to be run after all other endpoints
|
22
|
+
# are registered, but I don't know of a way to know when we're done running `initializer` blocks from the engines
|
23
|
+
# a user may have included.
|
24
|
+
def handle_not_found
|
25
|
+
route :any, "*path" do
|
26
|
+
raise StandardError, "Unable to find API endpoint"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module Api::V1::Teams::EndpointBase
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
helpers do
|
6
|
+
params :id do
|
7
|
+
requires :id, type: Integer, allow_blank: false, desc: Api.heading(:id)
|
8
|
+
end
|
9
|
+
|
10
|
+
params :team do
|
11
|
+
optional :name, type: String, allow_blank: false, desc: Api.heading(:name)
|
12
|
+
optional :locale, type: String, desc: Api.heading(:locale)
|
13
|
+
|
14
|
+
# TODO I don't like this, but I can't figure out a better way to accomplish the same thing. I'm open to any
|
15
|
+
# suggestions on this. I don't know why `@api.class` returns `Class` but `@api.to_s` returns e.g.
|
16
|
+
# `Api::V1::TeamsEndpoint`, but since we can get the latter, we'll use that to fetch whatever proc is defined
|
17
|
+
# in ADDITIONAL_PARAMS.
|
18
|
+
if defined?(@api.to_s.constantize::PARAMS)
|
19
|
+
instance_eval &@api.to_s.constantize::PARAMS
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
resource :teams, desc: Api.title(:actions) do
|
25
|
+
after_validation do
|
26
|
+
load_and_authorize_api_resource Team
|
27
|
+
end
|
28
|
+
|
29
|
+
desc Api.title(:index), &Api.index_desc
|
30
|
+
oauth2
|
31
|
+
paginate per_page: 100
|
32
|
+
get "/" do
|
33
|
+
@paginated_teams = paginate @teams
|
34
|
+
render @paginated_teams, serializer: Api.serializer, adapter: :attributes
|
35
|
+
end
|
36
|
+
|
37
|
+
desc Api.title(:show), &Api.show_desc
|
38
|
+
params do
|
39
|
+
use :id
|
40
|
+
end
|
41
|
+
oauth2
|
42
|
+
route_param :id do
|
43
|
+
get do
|
44
|
+
render @team, serializer: Api.serializer
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
desc Api.title(:create), &Api.create_desc
|
49
|
+
params do
|
50
|
+
use :team
|
51
|
+
end
|
52
|
+
route_setting :api_resource_options, permission: :create
|
53
|
+
oauth2 "write"
|
54
|
+
post "/" do
|
55
|
+
if @team.save
|
56
|
+
# sets the team creator as the default admin
|
57
|
+
@team.memberships.create(user: current_user, roles: [Role.admin])
|
58
|
+
|
59
|
+
current_user.current_team = @team
|
60
|
+
current_user.former_user = false
|
61
|
+
current_user.save
|
62
|
+
|
63
|
+
render @team, serializer: Api.serializer
|
64
|
+
else
|
65
|
+
record_not_saved @team
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
desc Api.title(:update), &Api.update_desc
|
70
|
+
params do
|
71
|
+
use :id
|
72
|
+
use :team
|
73
|
+
end
|
74
|
+
route_setting :api_resource_options, permission: :update
|
75
|
+
oauth2 "write"
|
76
|
+
route_param :id do
|
77
|
+
put do
|
78
|
+
if @team.update(declared(params, include_missing: false))
|
79
|
+
render @team, serializer: Api.serializer
|
80
|
+
else
|
81
|
+
record_not_saved @team
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/config/routes.rb
CHANGED
@@ -11,6 +11,12 @@ require "rack/cors"
|
|
11
11
|
module BulletTrain
|
12
12
|
module Api
|
13
13
|
class Engine < ::Rails::Engine
|
14
|
+
initializer "bullet_train.api.register_api_endpoints" do |app|
|
15
|
+
if BulletTrain::Api
|
16
|
+
BulletTrain::Api.endpoints << "Api::V1::MeEndpoint"
|
17
|
+
BulletTrain::Api.endpoints << "Api::V1::TeamsEndpoint"
|
18
|
+
end
|
19
|
+
end
|
14
20
|
end
|
15
21
|
end
|
16
22
|
end
|
data/lib/bullet_train/api.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bullet_train-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Culver
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -169,8 +169,9 @@ files:
|
|
169
169
|
- app/controllers/api/v1/exceptions_handler.rb
|
170
170
|
- app/controllers/api/v1/loads_and_authorizes_api_resource.rb
|
171
171
|
- app/controllers/api/v1/me_endpoint.rb
|
172
|
-
- app/controllers/api/v1/root.rb
|
173
172
|
- app/controllers/api/v1/teams_endpoint.rb
|
173
|
+
- app/controllers/concerns/api/v1/base.rb
|
174
|
+
- app/controllers/concerns/api/v1/teams/endpoint_base.rb
|
174
175
|
- app/models/platform/application.rb
|
175
176
|
- app/views/account/platform/applications/_application.json.jbuilder
|
176
177
|
- app/views/account/platform/applications/_breadcrumbs.html.erb
|
@@ -1,27 +0,0 @@
|
|
1
|
-
class Api::V1::Root < Api::Base
|
2
|
-
include Api::V1::Defaults
|
3
|
-
include Api::V1::LoadsAndAuthorizesApiResource
|
4
|
-
|
5
|
-
version "v1"
|
6
|
-
use ::WineBouncer::OAuth2
|
7
|
-
|
8
|
-
rescue_from :all do |error|
|
9
|
-
handle_api_error(error)
|
10
|
-
end
|
11
|
-
|
12
|
-
unless scaffolding_things_disabled?
|
13
|
-
mount Api::V1::Scaffolding::AbsolutelyAbstract::CreativeConceptsEndpoint
|
14
|
-
mount Api::V1::Scaffolding::CompletelyConcrete::TangibleThingsEndpoint
|
15
|
-
end
|
16
|
-
|
17
|
-
mount Api::V1::MeEndpoint
|
18
|
-
mount Api::V1::TeamsEndpoint
|
19
|
-
mount Api::V1::Webhooks::Outgoing::EndpointsEndpoint
|
20
|
-
mount Api::V1::Webhooks::Outgoing::DeliveriesEndpoint
|
21
|
-
mount Api::V1::Webhooks::Outgoing::DeliveryAttemptsEndpoint
|
22
|
-
# 🚅 super scaffolding will mount new endpoints above this line.
|
23
|
-
|
24
|
-
route :any, "*path" do
|
25
|
-
raise StandardError, "Unable to find API endpoint"
|
26
|
-
end
|
27
|
-
end
|