blazer-api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +50 -0
- data/Rakefile +24 -0
- data/app/assets/config/blazer_api_manifest.js +2 -0
- data/app/assets/javascripts/blazer/api/application.js +13 -0
- data/app/assets/stylesheets/blazer/api/application.css +15 -0
- data/app/controllers/blazer/api/application_controller.rb +29 -0
- data/app/controllers/blazer/api/queries_controller.rb +13 -0
- data/app/helpers/blazer/api/application_helper.rb +6 -0
- data/app/jobs/blazer/api/application_job.rb +6 -0
- data/app/mailers/blazer/api/application_mailer.rb +8 -0
- data/app/models/blazer/api/application_record.rb +7 -0
- data/app/views/layouts/blazer/api/application.html.erb +14 -0
- data/config/routes.rb +3 -0
- data/lib/blazer/api.rb +15 -0
- data/lib/blazer/api/configuration.rb +11 -0
- data/lib/blazer/api/engine.rb +13 -0
- data/lib/blazer/api/version.rb +5 -0
- data/lib/tasks/blazer/api_tasks.rake +4 -0
- metadata +195 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e1f2c550cd4bef18a7a24b6f0a5bdef4a09bc7562248482345373d07c99d67fd
|
4
|
+
data.tar.gz: 847126aaa8b0ea5877a6be9102efe236784fa50c6c2f22ffbf8563d8b7ee276e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6d1ddfdbf1c8fd04884136f053f0268d5d10976b63eb7b581fef9c75c65ef9067fe4e00029f2347883d7b04413890a00c3ae674926b280011ac870f81335b0f8
|
7
|
+
data.tar.gz: b408655c63ffd491d184fdd28847b0ea5de4d9e34ffc457b4728680b0c87800cccd712e7bab1d3354428afa784c46a6393f8040e855b2afae97f290cfa0a70ce
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2018 Francisco Martins
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Blazer::Api
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'blazer-api'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
We use the same env var that blazer uses to connect the database:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
ENV["BLAZER_DATABASE_URL"] = "postgres://user:password@hostname:5432/database"
|
23
|
+
```
|
24
|
+
|
25
|
+
Optionaly, you can create a initializer to handle authentication:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
# config/initializers/blazer-api.rb
|
29
|
+
|
30
|
+
Blazer::Api.configure do |config|
|
31
|
+
config.authentication = -> (token, options) {
|
32
|
+
Admin.find_by(api_key: token)
|
33
|
+
}
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
And mount on `config/routes.rb`:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
Rails.application.routes.draw do
|
41
|
+
mount Blazer::Api::Engine, at: 'blazer-api'
|
42
|
+
...
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
Contribution directions go here.
|
48
|
+
|
49
|
+
## License
|
50
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Blazer::Api'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
load 'rails/tasks/statistics.rake'
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
require 'bundler/gem_tasks'
|
24
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Blazer
|
2
|
+
module Api
|
3
|
+
class ApplicationController < ActionController::Base
|
4
|
+
include ActionController::HttpAuthentication::Token::ControllerMethods
|
5
|
+
|
6
|
+
protect_from_forgery with: :exception
|
7
|
+
before_action :authenticate
|
8
|
+
|
9
|
+
delegate :db, :authentication, to: :configuration
|
10
|
+
|
11
|
+
def authenticate
|
12
|
+
authenticate_with_http_token do |token, options|
|
13
|
+
authentication.call(token, options)
|
14
|
+
end || render_unauthorized
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def render_unauthorized
|
20
|
+
self.headers["WWW-Authenticate"] = "Token realm=\"Application\""
|
21
|
+
render json: { error: 'Bad credentials' }, status: :unauthorized
|
22
|
+
end
|
23
|
+
|
24
|
+
def configuration
|
25
|
+
Blazer::Api.configuration
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Blazer api</title>
|
5
|
+
<%= stylesheet_link_tag "blazer/api/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "blazer/api/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/config/routes.rb
ADDED
data/lib/blazer/api.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "blazer/api/engine"
|
2
|
+
require "blazer/api/configuration"
|
3
|
+
require "sequel"
|
4
|
+
|
5
|
+
module Blazer
|
6
|
+
module Api
|
7
|
+
class << self
|
8
|
+
attr_accessor :configuration
|
9
|
+
def configure
|
10
|
+
self.configuration ||= Blazer::Api::Configuration.new
|
11
|
+
yield(configuration)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Blazer
|
2
|
+
module Api
|
3
|
+
class Engine < ::Rails::Engine
|
4
|
+
isolate_namespace Blazer::Api
|
5
|
+
|
6
|
+
config.generators do |g|
|
7
|
+
# g.test_framework :rspec
|
8
|
+
# g.fixture_replacement :factory_bot, dir: 'spec/factories'
|
9
|
+
g.assets false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blazer-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Francisco Martins
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "<"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '6'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '4'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "<"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '6'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '4'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: blazer
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.8'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.8'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: sequel
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '5.0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '5.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: pg
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rspec
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '3.6'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '3.6'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: pry
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0.11'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0.11'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: database_cleaner
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '1.6'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '1.6'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: factory_bot
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '4.8'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '4.8'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: shoulda-matchers
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '3.1'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '3.1'
|
145
|
+
description:
|
146
|
+
email:
|
147
|
+
- franciscomxs@gmail.com
|
148
|
+
executables: []
|
149
|
+
extensions: []
|
150
|
+
extra_rdoc_files: []
|
151
|
+
files:
|
152
|
+
- MIT-LICENSE
|
153
|
+
- README.md
|
154
|
+
- Rakefile
|
155
|
+
- app/assets/config/blazer_api_manifest.js
|
156
|
+
- app/assets/javascripts/blazer/api/application.js
|
157
|
+
- app/assets/stylesheets/blazer/api/application.css
|
158
|
+
- app/controllers/blazer/api/application_controller.rb
|
159
|
+
- app/controllers/blazer/api/queries_controller.rb
|
160
|
+
- app/helpers/blazer/api/application_helper.rb
|
161
|
+
- app/jobs/blazer/api/application_job.rb
|
162
|
+
- app/mailers/blazer/api/application_mailer.rb
|
163
|
+
- app/models/blazer/api/application_record.rb
|
164
|
+
- app/views/layouts/blazer/api/application.html.erb
|
165
|
+
- config/routes.rb
|
166
|
+
- lib/blazer/api.rb
|
167
|
+
- lib/blazer/api/configuration.rb
|
168
|
+
- lib/blazer/api/engine.rb
|
169
|
+
- lib/blazer/api/version.rb
|
170
|
+
- lib/tasks/blazer/api_tasks.rake
|
171
|
+
homepage: https://github.com/franciscomxs/blazer-api
|
172
|
+
licenses:
|
173
|
+
- MIT
|
174
|
+
metadata: {}
|
175
|
+
post_install_message:
|
176
|
+
rdoc_options: []
|
177
|
+
require_paths:
|
178
|
+
- lib
|
179
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
180
|
+
requirements:
|
181
|
+
- - ">="
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: '0'
|
184
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
requirements: []
|
190
|
+
rubyforge_project:
|
191
|
+
rubygems_version: 2.7.3
|
192
|
+
signing_key:
|
193
|
+
specification_version: 4
|
194
|
+
summary: Add a JSON API to Blazer
|
195
|
+
test_files: []
|