bullet_train-api 1.0.3 → 1.0.7
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 +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/app/serializers/api/v1/invitation_serializer.rb +8 -0
- data/app/serializers/api/v1/membership_serializer.rb +8 -0
- data/app/serializers/api/v1/team_serializer.rb +8 -0
- data/app/serializers/api/v1/user_serializer.rb +8 -0
- data/app/serializers/concerns/api/v1/invitations/serializer_base.rb +17 -0
- data/app/serializers/concerns/api/v1/memberships/serializer_base.rb +24 -0
- data/app/serializers/concerns/api/v1/teams/serializer_base.rb +16 -0
- data/app/serializers/concerns/api/v1/users/serializer_base.rb +22 -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 +12 -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: 892999078661fe5c970b56d9718403df7fe909748b0764b31f8da8ff5f3ae166
|
4
|
+
data.tar.gz: 8cd26976c5abdbb57a838503f11b046364eae8d5165c1c94ff4bae231886230f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a8290f40a81d4dd0ca8dded910b8a2907a96bd0e6c9ca03f339b310ac2d95ce62af5fc468a13266daffdcf84c06a5f3afcd97e3e2959aff340b43d6875c7307
|
7
|
+
data.tar.gz: 4029a5b7cc6d41141d280e2b55be9e638b45bac86cc3f8360c6a9eeba404d92df17aab8d89da4119768263f4006b1fe052d6534c853146f200a45e6cd82d5c72
|
@@ -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
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class Api::V1::InvitationSerializer < Api::V1::ApplicationSerializer
|
2
|
+
include Api::V1::Invitations::SerializerBase
|
3
|
+
|
4
|
+
# The `:id` entries are redundant, but for the moment they help us generate valid code.
|
5
|
+
attributes :id,
|
6
|
+
# 🚅 super scaffolding will insert new fields above this line.
|
7
|
+
:id
|
8
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class Api::V1::MembershipSerializer < Api::V1::ApplicationSerializer
|
2
|
+
include Api::V1::Memberships::SerializerBase
|
3
|
+
|
4
|
+
# The `:id` entries are redundant, but for the moment they help us generate valid code.
|
5
|
+
attributes :id,
|
6
|
+
# 🚅 super scaffolding will insert new fields above this line.
|
7
|
+
:id
|
8
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class Api::V1::TeamSerializer < Api::V1::ApplicationSerializer
|
2
|
+
include Api::V1::Teams::SerializerBase
|
3
|
+
|
4
|
+
# The `:id` entries are redundant, but for the moment they help us generate valid code.
|
5
|
+
attributes :id,
|
6
|
+
# 🚅 super scaffolding will insert new fields above this line.
|
7
|
+
:id
|
8
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class Api::V1::UserSerializer < Api::V1::ApplicationSerializer
|
2
|
+
include Api::V1::Users::SerializerBase
|
3
|
+
|
4
|
+
# The `:id` entries are redundant, but for the moment they help us generate valid code.
|
5
|
+
attributes :id,
|
6
|
+
# 🚅 super scaffolding will insert new fields above this line.
|
7
|
+
:id
|
8
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Api::V1::Invitations::SerializerBase
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
set_type "invitation"
|
6
|
+
|
7
|
+
attributes :id,
|
8
|
+
:team_id,
|
9
|
+
:email,
|
10
|
+
:from_membership_id,
|
11
|
+
:created_at,
|
12
|
+
:updated_at
|
13
|
+
|
14
|
+
belongs_to :from_membership, serializer: Api::V1::MembershipSerializer
|
15
|
+
has_one :membership, serializer: Api::V1::MembershipSerializer
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Api::V1::Memberships::SerializerBase
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
set_type "membership"
|
6
|
+
|
7
|
+
attributes :id,
|
8
|
+
:team_id,
|
9
|
+
:user_id,
|
10
|
+
:invitation_id,
|
11
|
+
:user_first_name,
|
12
|
+
:user_last_name,
|
13
|
+
:user_profile_photo_id,
|
14
|
+
:user_email,
|
15
|
+
:added_by_id,
|
16
|
+
:created_at,
|
17
|
+
:updated_at
|
18
|
+
|
19
|
+
belongs_to :user, serializer: Api::V1::UserSerializer
|
20
|
+
belongs_to :team, serializer: Api::V1::TeamSerializer
|
21
|
+
belongs_to :invitation, serializer: Api::V1::InvitationSerializer
|
22
|
+
belongs_to :added_by, serializer: Api::V1::MembershipSerializer
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Api::V1::Teams::SerializerBase
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
set_type "team"
|
6
|
+
|
7
|
+
attributes :id,
|
8
|
+
:name,
|
9
|
+
:time_zone,
|
10
|
+
:locale,
|
11
|
+
:created_at,
|
12
|
+
:updated_at
|
13
|
+
|
14
|
+
has_many :scaffolding_absolutely_abstract_creative_concepts, serializer: Api::V1::Scaffolding::AbsolutelyAbstract::CreativeConceptSerializer
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Api::V1::Users::SerializerBase
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
set_type "user"
|
6
|
+
|
7
|
+
attributes :id,
|
8
|
+
:email,
|
9
|
+
:first_name,
|
10
|
+
:last_name,
|
11
|
+
:time_zone,
|
12
|
+
:profile_photo_id,
|
13
|
+
:former_user,
|
14
|
+
:locale,
|
15
|
+
:platform_agent_of_id,
|
16
|
+
:created_at,
|
17
|
+
:updated_at
|
18
|
+
|
19
|
+
has_many :teams, serializer: Api::V1::TeamSerializer
|
20
|
+
has_many :memberships, serializer: Api::V1::MembershipSerializer
|
21
|
+
end
|
22
|
+
end
|
@@ -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.7
|
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-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -169,9 +169,18 @@ 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
|
176
|
+
- app/serializers/api/v1/invitation_serializer.rb
|
177
|
+
- app/serializers/api/v1/membership_serializer.rb
|
178
|
+
- app/serializers/api/v1/team_serializer.rb
|
179
|
+
- app/serializers/api/v1/user_serializer.rb
|
180
|
+
- app/serializers/concerns/api/v1/invitations/serializer_base.rb
|
181
|
+
- app/serializers/concerns/api/v1/memberships/serializer_base.rb
|
182
|
+
- app/serializers/concerns/api/v1/teams/serializer_base.rb
|
183
|
+
- app/serializers/concerns/api/v1/users/serializer_base.rb
|
175
184
|
- app/views/account/platform/applications/_application.json.jbuilder
|
176
185
|
- app/views/account/platform/applications/_breadcrumbs.html.erb
|
177
186
|
- app/views/account/platform/applications/_form.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
|