bullet_train-api 1.0.5 → 1.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 89d0d8de58c2132c0e4f9d5f704a8ca8035126f030ccaf711b2b1a27ebf793f6
4
- data.tar.gz: 279210193a45516e0e2ffb2d89c6dc5ac82406154dfef7e7ce0c229b8bc621aa
3
+ metadata.gz: 032d9344239258c4279f3a04e1aecbce98a4ef7f7a74a2c568047b64b348f2f0
4
+ data.tar.gz: a1d2970d2d64dab6a2e3fd192afda710e150ea7524f1f2635868864b9ccd8025
5
5
  SHA512:
6
- metadata.gz: 63fe9c16afc1e7d7753504f540304e5d0ed3cfe8812806adbe7f9f52e71ecdc9d2fcbea595968d195d42dd9f7b553af861033d3af6ca5ee1e45aa26d37ac4506
7
- data.tar.gz: 572fb40701d7c521c8e03bcff7a2fd5a30295fbba0e3c18e830ea84bc850010bf6cd0b95b1b9219fc0da5903316308257a04b672400d4a6d33761c866ccdfa8a
6
+ metadata.gz: 7a58f1503b3d11a2c7c46552d91a4e0c40bb9b258945501f4eb8146af4185f97d3ad73d05c729514319e0ad85d28eef71cf3d83024256a59389dfd79ed8d47e1
7
+ data.tar.gz: 7f44279ae68331a9513bcd4c54572da1ea3a14483ef54e9dccf9b393b30bc80eb73a96e87fb71ded864db3cf55df12eda712c91a80203410fd722cf26b65ec37
@@ -1,79 +1,9 @@
1
1
  class Api::V1::TeamsEndpoint < Api::V1::Root
2
- helpers do
3
- params :id do
4
- requires :id, type: Integer, allow_blank: false, desc: Api.heading(:id)
5
- end
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
- resource :teams, desc: Api.title(:actions) do
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
@@ -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.split(/\/app\/controllers\/api\/v\d+\//).last.split("_endpoint.").first
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
@@ -2,7 +2,6 @@ module Api::V1::Base
2
2
  extend ActiveSupport::Concern
3
3
 
4
4
  included do
5
- include Api::V1::Base
6
5
  include Api::V1::Defaults
7
6
  include Api::V1::LoadsAndAuthorizesApiResource
8
7
 
@@ -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
@@ -1,5 +1,5 @@
1
1
  module BulletTrain
2
2
  module Api
3
- VERSION = "1.0.5"
3
+ VERSION = "1.0.6"
4
4
  end
5
5
  end
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.5
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-02-12 00:00:00.000000000 Z
11
+ date: 2022-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -171,6 +171,7 @@ files:
171
171
  - app/controllers/api/v1/me_endpoint.rb
172
172
  - app/controllers/api/v1/teams_endpoint.rb
173
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