grape-starter 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '0823711b471e505ebfbd048f139fa0276f4ebf41'
4
- data.tar.gz: e784796595cc5ac6d3c43ad1a6c0317b35c0467a
3
+ metadata.gz: d549f6e5ecd48d20c126a63de91a14ac9fb9262f
4
+ data.tar.gz: 33174fb1dd003ee55acbe824a96c2a56588c4d55
5
5
  SHA512:
6
- metadata.gz: 67113631c915da4adead1ee145c1640ebaa1e8131dbeef240c5ed354f3be8919223f743a241ba73cb5085fbe35e40499765008b0280c5f0f5d809f3f36bc12ef
7
- data.tar.gz: 4b6ba9fcd7b2b0de31a6022a72d57cf5eea654ebb2fd9b11a852a4fd3fb9b0902e6328da229cfd4b11478debf1400df8ffc7926fc55f450a62a6f1ce23d5070e
6
+ metadata.gz: c42c646d1248bd7d953049ddd80ae019ebe4df5220fddfd025e60c9910809009d2c8d7725472c53b7ac4307551c34ced33c5c3831002145587627887d4450c98
7
+ data.tar.gz: 458945f18afcf926a97624405ec0591ec3adf5068776ad5746865bb85d827639a0a435980a7dfcac2125b1907fd98bbc42e4b883bdb93bfdf4b265a67882eb65
data/README.md CHANGED
@@ -60,7 +60,7 @@ $ cd awesome_api
60
60
  $ ./script/server *port
61
61
  ```
62
62
  the API is now accessible under: [http://localhost:9292/api/v1/root](http://localhost:9292/api/v1/root)
63
- the documentation of it under: [http://localhost:9292/](http://localhost:9292/)
63
+ the documentation of it under: [http://localhost:9292/](http://localhost:9292/).
64
64
 
65
65
  More could be found in [README](template/README.md).
66
66
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Starter
3
- VERSION = '0.4.0'
3
+ VERSION = '0.4.1'
4
4
  end
data/template/README.md CHANGED
@@ -24,13 +24,14 @@ $ ./script/test
24
24
  #### Run
25
25
 
26
26
  ```
27
- $ ./script/server
27
+ $ ./script/server *port (default: 9292)
28
28
  ```
29
- and go to: [http://localhost:9292](http://localhost:9292)
29
+ and go to: [http://localhost:port/](http://localhost:9292/)
30
+ to access the OAPI documentation.
30
31
 
31
- or for production, set `RACK_ENV=production`
32
+ For production, set `RACK_ENV=production`
32
33
  ```
33
- $ export RACK_ENV=production ./script/server
34
+ $ RACK_ENV=production ./script/server *port (default: 9292)
34
35
  ```
35
36
 
36
37
  #### Update
data/template/Rakefile CHANGED
@@ -14,7 +14,7 @@ end
14
14
  require 'rubocop/rake_task'
15
15
  RuboCop::RakeTask.new(:rubocop)
16
16
 
17
- task default: [:rubocop, :spec]
17
+ task default: [:spec, :rubocop]
18
18
 
19
19
  require File.expand_path('../config/environment', __FILE__)
20
20
 
data/template/api/base.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  module Api
3
3
  class Base < Grape::API
4
+ # !!! a prefix is always required
4
5
  prefix :api
5
6
  version 'v1', using: :path
6
7
  format :json
data/template/config.ru CHANGED
@@ -12,8 +12,4 @@ end
12
12
 
13
13
  require File.expand_path('../config/application', __FILE__)
14
14
 
15
- app = App.new
16
- app.map '/', DocApp.new
17
- app.map '/api', Api::Base
18
-
19
- run app
15
+ run App.new
@@ -22,18 +22,12 @@ end
22
22
  require 'base'
23
23
 
24
24
  require 'rack'
25
-
26
25
  # provides the documentation of the API
27
26
  class DocApp
27
+ attr_reader :env
28
28
  def call(env)
29
- [200, { 'Content-Type' => 'text/html' }, [re_doc(env)]]
30
- end
31
-
32
- def re_doc(env)
33
- doc = template.sub('{{{server}}}', env['SERVER_NAME'])
34
- doc = doc.sub('{{{port}}}', env['SERVER_PORT'])
35
-
36
- doc
29
+ @env = env
30
+ [200, { 'Content-Type' => 'text/html' }, [template]]
37
31
  end
38
32
 
39
33
  def template
@@ -42,19 +36,22 @@ class DocApp
42
36
  <head>
43
37
  <title>ReDoc API documentation</title>
44
38
  <meta name='viewport' content='width=device-width, initial-scale=1'>
45
- <style>
46
- body {
47
- margin: 0;
48
- padding: 0;
49
- }
50
- </style>
39
+ <style>body {margin: 0;padding: 0;}</style>
51
40
  </head>
52
41
  <body>
53
- <redoc spec-url='http://{{{server}}}:{{{port}}}/api/v1/oapi.json'></redoc>
42
+ <redoc spec-url='http://#{server}:#{port}/#{Api::Base.prefix}/#{Api::Base.version}/oapi.json'></redoc>
54
43
  <script src='https://rebilly.github.io/ReDoc/releases/latest/redoc.min.js'> </script>
55
44
  </body>
56
45
  </html>"
57
46
  end
47
+
48
+ def server
49
+ @env['SERVER_NAME']
50
+ end
51
+
52
+ def port
53
+ @env['SERVER_PORT']
54
+ end
58
55
  end
59
56
 
60
57
  # provides the routing between the API and the html documentation of it
@@ -63,16 +60,11 @@ class App
63
60
  @apps = {}
64
61
  end
65
62
 
66
- def map(route, app)
67
- @apps[route] = app
68
- end
69
-
70
63
  def call(env)
71
- request = Rack::Request.new(env)
72
- if env['REQUEST_PATH'].start_with?('/api')
73
- @apps['/api'].call(env)
74
- elsif @apps[request.path]
75
- @apps[request.path].call(env)
64
+ if env['REQUEST_PATH'].start_with?("/#{Api::Base.prefix}")
65
+ Api::Base.call(env)
66
+ else
67
+ DocApp.new.call(env)
76
68
  end
77
69
  end
78
70
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-starter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - LeFnord