bullet_train-api 1.0.4 → 1.0.8
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 -2
- 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 +26 -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: a68d08813f7429b8be31aa20cf1eaaaa1294ed3f66fd04e54165d0426bb7df43
|
4
|
+
data.tar.gz: d849b06fd396ad5e466b80493195b337992dd32f649de6e24779c8d142042758
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a556c8c605e9c2fc8935aeb682d206c6e34908e27a5b140060cf4ddeedd82a8f029c19418b92844c7490af9ee4db878139d196e42361f99ee14ddf5ef65e96a
|
7
|
+
data.tar.gz: 0e101b006c7831c8bb47edc562536e4fab741ac5f656ddef27a1a3c5d9452e6180db96b78e268d6c7677f67dd7466dc7c32de2743e07dc7a1e03d12f37500d96
|
@@ -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,8 +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.
|
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
|
11
15
|
end
|
12
16
|
|
13
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.8
|
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-02-
|
11
|
+
date: 2022-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -150,6 +150,20 @@ dependencies:
|
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: jsonapi-serializer
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
153
167
|
description: Bullet Train API
|
154
168
|
email:
|
155
169
|
- andrew.culver@gmail.com
|
@@ -169,9 +183,18 @@ files:
|
|
169
183
|
- app/controllers/api/v1/exceptions_handler.rb
|
170
184
|
- app/controllers/api/v1/loads_and_authorizes_api_resource.rb
|
171
185
|
- app/controllers/api/v1/me_endpoint.rb
|
172
|
-
- app/controllers/api/v1/root.rb
|
173
186
|
- app/controllers/api/v1/teams_endpoint.rb
|
187
|
+
- app/controllers/concerns/api/v1/base.rb
|
188
|
+
- app/controllers/concerns/api/v1/teams/endpoint_base.rb
|
174
189
|
- app/models/platform/application.rb
|
190
|
+
- app/serializers/api/v1/invitation_serializer.rb
|
191
|
+
- app/serializers/api/v1/membership_serializer.rb
|
192
|
+
- app/serializers/api/v1/team_serializer.rb
|
193
|
+
- app/serializers/api/v1/user_serializer.rb
|
194
|
+
- app/serializers/concerns/api/v1/invitations/serializer_base.rb
|
195
|
+
- app/serializers/concerns/api/v1/memberships/serializer_base.rb
|
196
|
+
- app/serializers/concerns/api/v1/teams/serializer_base.rb
|
197
|
+
- app/serializers/concerns/api/v1/users/serializer_base.rb
|
175
198
|
- app/views/account/platform/applications/_application.json.jbuilder
|
176
199
|
- app/views/account/platform/applications/_breadcrumbs.html.erb
|
177
200
|
- 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
|