bullet_train-api 1.0.0 → 1.0.1
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/base.rb +26 -0
- data/app/controllers/api.rb +93 -0
- data/lib/bullet_train/api/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e0f1c01d87b93a40a16d82907bf84068a03842fb085b4a95b984d70512f0bde
|
4
|
+
data.tar.gz: 60a82c00ed0fed7accc7de60fe4e294fb09ac2cdd644f4257e3013a8086d13cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abed93cb81502188395b8571f50c3f0e60b7704ed2b83d958006d0bd152cd24023b8563601be5506e47ab6278abf7154d5f27d2f545faaa6f1012399b3f22b87
|
7
|
+
data.tar.gz: 52962a262499e9ea63ba67ce6bd83853375d82bb1caabdbb128a7b4cb07998597ae3dd0d662a46f1781005177bc41c837f03499c2dfdfbc324a1dd4363219a99
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "grape-swagger"
|
2
|
+
require_relative "../api"
|
3
|
+
|
4
|
+
class Api::Base < Grape::API
|
5
|
+
content_type :jsonapi, "application/vnd.api+json"
|
6
|
+
formatter :json, Grape::Formatter::Jsonapi
|
7
|
+
formatter :jsonapi, Grape::Formatter::Jsonapi
|
8
|
+
format :jsonapi
|
9
|
+
default_error_formatter :json
|
10
|
+
|
11
|
+
# TODO Shouldn't this be in V1 or not versioned?
|
12
|
+
include Api::V1::ExceptionsHandler
|
13
|
+
|
14
|
+
mount Api::V1::Root
|
15
|
+
|
16
|
+
# Swagger docs are available at `/api/swagger_doc.json`.
|
17
|
+
add_swagger_documentation \
|
18
|
+
hide_documentation_path: true,
|
19
|
+
array_use_braces: true,
|
20
|
+
api_version: "v1",
|
21
|
+
info: {
|
22
|
+
title: I18n.t("application.name"),
|
23
|
+
description: I18n.t("application.description")
|
24
|
+
},
|
25
|
+
endpoint_auth_wrapper: WineBouncer::OAuth2
|
26
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# We have to do this because there are a couple of different Grape contexts where you're trying to define something
|
2
|
+
# for a model's API representation, but the execution context doesn't have access to the endpoint object you're
|
3
|
+
# defining things for. I understand the design thinking that caused that situation, but unfortunately for us we just
|
4
|
+
# have to brute force our way around it for now. In doing so, we're implementing something not unlike the magic of the
|
5
|
+
# `t` helper in Rails views.
|
6
|
+
|
7
|
+
module Api
|
8
|
+
def self.topic
|
9
|
+
path = caller.find { |path| path.include?("controllers/api") && !path.include?("app/controllers/api.rb") }
|
10
|
+
path.gsub!(/^#{Rails.root}\/app\/controllers\/api\/v\d+\//, "")
|
11
|
+
path.split("_endpoint.").first
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.serializer
|
15
|
+
# TODO This could be smart enough to figure out if `V1` is accurate, as well.
|
16
|
+
"Api::V1::#{Api.topic.classify}Serializer"
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.status(code)
|
20
|
+
I18n.t("api.statuses.#{code}")
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.title(path)
|
24
|
+
I18n.t("#{topic}.api.#{path}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.heading(path)
|
28
|
+
I18n.t("#{topic}.api.fields.#{path}.heading")
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.show_desc
|
32
|
+
proc do
|
33
|
+
success code: 200, model: Api.serializer, message: Api.status(200)
|
34
|
+
failure [
|
35
|
+
{code: 401, message: Api.status(401)}, # unauthorized
|
36
|
+
{code: 403, message: Api.status(403)}, # forbidden
|
37
|
+
{code: 404, message: Api.status(404)}, # not found
|
38
|
+
{code: 429, message: Api.status(429)} # too many requests
|
39
|
+
]
|
40
|
+
produces ["application/vnd.api+json"]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.index_desc
|
45
|
+
proc do
|
46
|
+
success code: 200, model: Api.serializer, message: Api.status(200)
|
47
|
+
failure [
|
48
|
+
{code: 401, message: Api.status(401)}, # unauthorized
|
49
|
+
{code: 429, message: Api.status(429)} # too many requests
|
50
|
+
]
|
51
|
+
produces ["application/vnd.api+json"]
|
52
|
+
is_array true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.create_desc
|
57
|
+
proc do
|
58
|
+
success code: 201, model: Api.serializer, message: Api.status(201)
|
59
|
+
failure [
|
60
|
+
{code: 400, message: Api.status(400)}, # bad request
|
61
|
+
{code: 401, message: Api.status(401)}, # unauthorized
|
62
|
+
{code: 403, message: Api.status(403)}, # forbidden
|
63
|
+
{code: 406, message: Api.status(406)}, # not acceptable
|
64
|
+
{code: 422, message: Api.status(422)}, # unprocessable entity
|
65
|
+
{code: 429, message: Api.status(429)} # too many requests
|
66
|
+
]
|
67
|
+
consumes ["application/json", "multipart/form-data"]
|
68
|
+
produces ["application/vnd.api+json"]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.update_desc
|
73
|
+
proc do
|
74
|
+
success code: 200, model: Api.serializer, message: Api.status(200)
|
75
|
+
failure [
|
76
|
+
{code: 400, message: Api.status(400)}, # bad request
|
77
|
+
{code: 401, message: Api.status(401)}, # unauthorized
|
78
|
+
{code: 403, message: Api.status(403)}, # forbidden
|
79
|
+
{code: 404, message: Api.status(404)}, # not found
|
80
|
+
{code: 406, message: Api.status(406)}, # not acceptable
|
81
|
+
{code: 422, message: Api.status(422)}, # unprocessable entity
|
82
|
+
{code: 429, message: Api.status(429)} # too many requests
|
83
|
+
]
|
84
|
+
consumes ["application/json", "multipart/form-data"]
|
85
|
+
produces ["application/vnd.api+json"]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.destroy_desc
|
90
|
+
# TODO We don't have anything for this, but we want to make sure it's easy to roll out updates going forward.
|
91
|
+
proc {}
|
92
|
+
end
|
93
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Culver
|
@@ -36,6 +36,8 @@ files:
|
|
36
36
|
- Rakefile
|
37
37
|
- app/assets/config/bullet_train_api_manifest.js
|
38
38
|
- app/controllers/account/platform/applications_controller.rb
|
39
|
+
- app/controllers/api.rb
|
40
|
+
- app/controllers/api/base.rb
|
39
41
|
- app/controllers/api/v1.rb
|
40
42
|
- app/controllers/api/v1/defaults.rb
|
41
43
|
- app/controllers/api/v1/exceptions_handler.rb
|