sabisu_rails 0.0.1.pre.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +109 -0
- data/Rakefile +1 -0
- data/app/assets/javascripts/sabisu_rails/application.js +12 -0
- data/app/assets/javascripts/sabisu_rails/sabisu.js.coffee +40 -0
- data/app/assets/stylesheets/sabisu_rails/application.css.scss +9 -0
- data/app/assets/stylesheets/sabisu_rails/explorer.css.scss +117 -0
- data/app/assets/stylesheets/sabisu_rails/furatto_overrides.scss +24 -0
- data/app/controllers/sabisu_rails/base_controller.rb +16 -0
- data/app/controllers/sabisu_rails/explorer_controller.rb +15 -0
- data/app/helpers/sabisu_rails/explorer_helper.rb +28 -0
- data/app/helpers/sabisu_rails_helper.rb +3 -0
- data/app/views/layouts/sabisu_rails.html.erb +28 -0
- data/app/views/sabisu_rails/explorer/index.html.erb +86 -0
- data/app/views/sabisu_rails/explorer/index.js.erb +6 -0
- data/config/routes.rb +3 -0
- data/lib/generators/sabisu_rails/install_generator.rb +17 -0
- data/lib/generators/sabisu_rails/templates/sabisu_rails.rb +34 -0
- data/lib/sabisu_rails/builders/base.rb +26 -0
- data/lib/sabisu_rails/builders/headers_builder.rb +6 -0
- data/lib/sabisu_rails/builders/url_params_builder.rb +6 -0
- data/lib/sabisu_rails/builders.rb +7 -0
- data/lib/sabisu_rails/engine.rb +5 -0
- data/lib/sabisu_rails/explorer.rb +35 -0
- data/lib/sabisu_rails/helpers/required.rb +14 -0
- data/lib/sabisu_rails/helpers.rb +5 -0
- data/lib/sabisu_rails/railtie.rb +22 -0
- data/lib/sabisu_rails/request.rb +28 -0
- data/lib/sabisu_rails/route_recognizer.rb +34 -0
- data/lib/sabisu_rails/version.rb +3 -0
- data/lib/sabisu_rails.rb +70 -0
- data/sabisu_rails.gemspec +30 -0
- data/vendor/assets/javascripts/sabisu_rails/KelpJSONView.js +120 -0
- data/vendor/assets/javascripts/sabisu_rails/pace.js +2 -0
- data/vendor/assets/stylesheets/sabisu_rails/KelpJSONView.css.scss +50 -0
- data/vendor/assets/stylesheets/sabisu_rails/pace.css +80 -0
- metadata +167 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 284b0d527cd0903c0553fdbb85a121935c342e83
|
4
|
+
data.tar.gz: db4e336d9dfeee82b8f322b67d2730f19290db15
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 54ba3eaf47892f081eed2a42fb0ea1d6d7d7cdd8a6a9ec16a89c45ce5ecc737f0206c3c86ce292565c404a4257a077aa26bc691cdf62cdfd386ba0f1c8d63f7f
|
7
|
+
data.tar.gz: bfa4740da7113d819377b2313bc03714d41b2e90ca22e43e5cb357972b37ec41caf7df7c29b93ba89c032065b3136653355fea0765aa5a59d88c550e710e8e1d
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Abraham Kuri
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# [Sabisu](https://github.com/IcaliaLabs/sabisu)
|
2
|
+
|
3
|
+
Sabisu is a powerful postman-like engine client to explore your Rails application api. It's still under heavy development, but it is quite impressive and beautiful. Give it a try!
|
4
|
+
|
5
|
+
It was created by [Abraham Kuri](https://twitter.com/kurenn) from [Icalia Labs](http://twitter.com/icalialabs).
|
6
|
+
|
7
|
+
To get started, checkout:
|
8
|
+
|
9
|
+
#### [http://icalialabs.github.io/sabisu-rails/](http://icalialabs.github.io/sabisu-rails/)
|
10
|
+
|
11
|
+
## Table of contents
|
12
|
+
|
13
|
+
- [Installation](#installation)
|
14
|
+
- [Customization](#customization)
|
15
|
+
- [Bug tracker & feature request](#bug-tracker-&-feature-request)
|
16
|
+
- [Contributing](#contributing)
|
17
|
+
- [Community](#community)
|
18
|
+
- [Heroes](#heroes)
|
19
|
+
- [License](#license)
|
20
|
+
|
21
|
+
## Quick start
|
22
|
+
|
23
|
+
Install sabisu is extremely easy, just add some gems to your `Gemfile`
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
gem 'sabisu-rails'
|
27
|
+
gem 'compass-rails'
|
28
|
+
gem 'furatto'
|
29
|
+
gem 'font-awesome-rails'
|
30
|
+
```
|
31
|
+
And then execute:
|
32
|
+
|
33
|
+
```console
|
34
|
+
$ bundle install
|
35
|
+
```
|
36
|
+
|
37
|
+
After you install Sabisu you need to run the generator:
|
38
|
+
|
39
|
+
```console
|
40
|
+
rails g sabisu_rails:install
|
41
|
+
```
|
42
|
+
|
43
|
+
The generator will install in initializer which describes all the Sabisu configuration options.
|
44
|
+
|
45
|
+
Some of these configuration options include you api endpoint base uri, so as your resources, so you better take a look at it.
|
46
|
+
|
47
|
+
Once you are done with the configuration, start your rails application and navigate to `http://localhost:3000/sabisu_rails/explorer`
|
48
|
+
|
49
|
+
If everything went good you should see a nice explorer interface with your resources.
|
50
|
+
|
51
|
+
## Customization
|
52
|
+
|
53
|
+
Sabisu is highly customizable to make your life easier, here is a quick example of a real app configuration, remember you have the configuration file under `config/initializers/sabisu_rails.rb`.
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
SabisuRails.setup do |config|
|
57
|
+
|
58
|
+
# Base uri for posting the
|
59
|
+
config.base_api_uri = 'api.sabisu.dev'
|
60
|
+
|
61
|
+
# Ignored attributes for building the forms
|
62
|
+
# config.ignored_attributes = %w{ created_at updated_at id }
|
63
|
+
|
64
|
+
# HTTP methods
|
65
|
+
# config.http_methods = %w{ GET POST PUT DELETE PATCH }
|
66
|
+
|
67
|
+
# Headers to include on each request
|
68
|
+
config.api_headers = {'Accept' => 'application/vnd.sabisu.v1'}
|
69
|
+
|
70
|
+
# Resources on the api
|
71
|
+
config.resources = [:products, :users]
|
72
|
+
|
73
|
+
end
|
74
|
+
```
|
75
|
+
We invite you to look at the full file for further customization.
|
76
|
+
|
77
|
+
## Bug tracker & feature request
|
78
|
+
|
79
|
+
Have a bug or a feature request? [Please open a new issue](https://github.com/IcaliaLabs/sabisu-rails/issues). Before opening any issue, please search for existing issues.
|
80
|
+
|
81
|
+
We recommend you to read the version [milestiones](https://github.com/IcaliaLabs/sabisu-rails/issues?milestone=2&state=open) if you feel like want to collaborate.
|
82
|
+
|
83
|
+
## Contributing
|
84
|
+
|
85
|
+
Please submit all pull requests against a separate branch. Although it does not have tests yet, be a nice guy and add some for your feature. We'll be working hard to add them too.
|
86
|
+
|
87
|
+
In case you are wondering what to attack, we have a milestone with the version to work, some fixes and refactors. Feel free to start one.
|
88
|
+
|
89
|
+
Thanks!
|
90
|
+
|
91
|
+
## Community
|
92
|
+
|
93
|
+
Keep track of new feautres, development issues and community news.
|
94
|
+
|
95
|
+
* Follow [@kurenn](https://twitter.com/kurenn)
|
96
|
+
* Have a question about anything, email us at weare@icalialabs.com
|
97
|
+
|
98
|
+
## Heroes
|
99
|
+
|
100
|
+
**Abraham Kuri**
|
101
|
+
|
102
|
+
+ [http://twitter.com/kurenn](http://twitter.com/kurenn)
|
103
|
+
+ [http://github.com/kurenn](http://github.com/kurenn)
|
104
|
+
+ [http://klout.com/#/kurenn](http://klout.com/#/kurenn)
|
105
|
+
|
106
|
+
|
107
|
+
## Copyright and license
|
108
|
+
|
109
|
+
Code and documentation copyright 2013-2014 Icalia Labs. Code released under [the MIT license](LICENSE).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into including all the files listed below.
|
2
|
+
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
|
3
|
+
// be included in the compiled file accessible from http://example.com/assets/application.js
|
4
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
5
|
+
// the compiled file.
|
6
|
+
//
|
7
|
+
//= require jquery
|
8
|
+
//= require jquery_ujs
|
9
|
+
//= require sabisu_rails/KelpJSONView
|
10
|
+
//= require furatto
|
11
|
+
//= require sabisu_rails/sabisu
|
12
|
+
//= require sabisu_rails/pace
|
@@ -0,0 +1,40 @@
|
|
1
|
+
capitalize = (str) ->
|
2
|
+
str[0].toUpperCase() + str.slice(1)
|
3
|
+
|
4
|
+
$ ->
|
5
|
+
$addButtons = $('.explorer-fields-link-js')
|
6
|
+
fieldId = 1
|
7
|
+
|
8
|
+
$addButtons.on 'click', (e) ->
|
9
|
+
e.preventDefault()
|
10
|
+
$wrapperTarget = $($(@).data('target'))
|
11
|
+
inputType = $(@).data('type')
|
12
|
+
singleInputType = capitalize(inputType.substring(0, inputType.length - 1).replace("_", " "))
|
13
|
+
|
14
|
+
fieldsToAppend = "<div class='row'>
|
15
|
+
<div class='col-5'>
|
16
|
+
<input type='text' name='explorer[#{inputType}][#{fieldId}][#{inputType}_name_#{fieldId}]' id='explorer_#{inputType}_name_#{fieldId}' placeholder='#{singleInputType} name'/>
|
17
|
+
</div>
|
18
|
+
<div class='col-6'>
|
19
|
+
<input type='text' name='explorer[#{inputType}][#{fieldId}][#{inputType}_value_#{fieldId}]' id='explorer_#{inputType}_value_#{fieldId}' placeholder='#{singleInputType} value'/>
|
20
|
+
</div>
|
21
|
+
<div class='col-1'>
|
22
|
+
<a href='#' class='remove_input button radius nomargin danger three-d' data-counter='##{inputType}_counter_js'><i class='fa fa-trash-o'></i></a>
|
23
|
+
</div>
|
24
|
+
</div>"
|
25
|
+
|
26
|
+
$wrapperTarget.append(fieldsToAppend)
|
27
|
+
$("##{inputType}_counter_js").text($wrapperTarget.children().length)
|
28
|
+
fieldId++
|
29
|
+
|
30
|
+
$(document).on 'click', '.remove_input', (e) ->
|
31
|
+
e.preventDefault()
|
32
|
+
inputsWrapper = $(@).parent().parent().parent()
|
33
|
+
counter = $($(@).data('counter'))
|
34
|
+
$(@).parent().parent().remove()
|
35
|
+
counter.text(inputsWrapper.children().length)
|
36
|
+
|
37
|
+
$('#explorer_form').submit ->
|
38
|
+
Pace.start()
|
39
|
+
|
40
|
+
|
@@ -0,0 +1,9 @@
|
|
1
|
+
@import 'furatto/functions';
|
2
|
+
@import 'furatto/selectors';
|
3
|
+
@import 'normalize';
|
4
|
+
@import 'sabisu_rails/furatto_overrides';
|
5
|
+
@import 'font-awesome';
|
6
|
+
@import 'furatto';
|
7
|
+
@import 'sabisu_rails/KelpJSONView';
|
8
|
+
@import 'sabisu_rails/explorer';
|
9
|
+
@import 'sabisu_rails/pace';
|
@@ -0,0 +1,117 @@
|
|
1
|
+
.main-content {
|
2
|
+
border-left: 1px solid darken(#F5F5F5, 5%);
|
3
|
+
padding-left: 30px;
|
4
|
+
background: #FFF;
|
5
|
+
padding-bottom: 20px;
|
6
|
+
}
|
7
|
+
|
8
|
+
.navigation {
|
9
|
+
&.side {
|
10
|
+
height: 100%;
|
11
|
+
padding: 0;
|
12
|
+
.header {
|
13
|
+
background: #EA5D5F;
|
14
|
+
border: 1px solid darken(#EA5D5F, 4%);
|
15
|
+
padding-left: 20px;
|
16
|
+
padding-top: 50px;
|
17
|
+
padding-bottom: 10px;
|
18
|
+
|
19
|
+
&:hover {
|
20
|
+
background: #EA5D5F;
|
21
|
+
border: 1px solid darken(#EA5D5F, 4%);
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
li {
|
26
|
+
padding-left: 20px;
|
27
|
+
cursor: pointer;
|
28
|
+
&:hover {
|
29
|
+
background: #7BD5D3;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
li.active {
|
34
|
+
position: relative;
|
35
|
+
background: #7BD5D3;
|
36
|
+
border: 1px solid darken(#7BD5D3, 4%);
|
37
|
+
|
38
|
+
&:after {
|
39
|
+
content: '';
|
40
|
+
position: absolute;
|
41
|
+
right: -2px;
|
42
|
+
top: 12px;
|
43
|
+
width: 0;
|
44
|
+
height: 0;
|
45
|
+
border-top: 12px solid transparent;
|
46
|
+
border-bottom: 12px solid transparent;
|
47
|
+
|
48
|
+
border-right:12px solid #FFF;
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
.nomargin {
|
55
|
+
margin: 0;
|
56
|
+
}
|
57
|
+
|
58
|
+
fieldset {
|
59
|
+
border: none;
|
60
|
+
padding: 0 0 8px 0;
|
61
|
+
margin-top: 15px;
|
62
|
+
color: #555;
|
63
|
+
text-transform: uppercase;
|
64
|
+
|
65
|
+
legend {
|
66
|
+
border-bottom: 1px solid rgba(#b3b3b3, 0.5);
|
67
|
+
display: block;
|
68
|
+
width: 100%;
|
69
|
+
padding-bottom: 8px;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
.button {
|
74
|
+
&.danger {
|
75
|
+
color: #777;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
.navigation {
|
80
|
+
&.inline {
|
81
|
+
li {
|
82
|
+
a {
|
83
|
+
padding: 2px 5px;
|
84
|
+
font-weight: lighter;
|
85
|
+
}
|
86
|
+
|
87
|
+
&.active {
|
88
|
+
border-top: 2px solid darken($navigation-inline-active-background, 10%);
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
.response-details {
|
95
|
+
float: right;
|
96
|
+
padding-right: 25px;
|
97
|
+
}
|
98
|
+
|
99
|
+
.response-wrapper {
|
100
|
+
padding-right: 10px;
|
101
|
+
}
|
102
|
+
|
103
|
+
.text-strong {
|
104
|
+
font-weight: bold;
|
105
|
+
}
|
106
|
+
|
107
|
+
.headers {
|
108
|
+
span {
|
109
|
+
display: inline-block;
|
110
|
+
margin-bottom: 10px;
|
111
|
+
font-size: 13px;
|
112
|
+
}
|
113
|
+
|
114
|
+
i.fa {
|
115
|
+
margin: 0 8px;
|
116
|
+
}
|
117
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
// Navigation overrides
|
2
|
+
$navigation-header-color: #FFF;
|
3
|
+
$navigation-header-font-size: px-to-rems(16);
|
4
|
+
$navigation-list-item-active-color: #FFF;
|
5
|
+
$navigation-list-link-display: block;
|
6
|
+
$navigation-list-link-padding: 12px 0;
|
7
|
+
$navigation-link-color: #333;
|
8
|
+
$navigation-list-item-font-size: 1rem;
|
9
|
+
|
10
|
+
$navigation-inline-active-background: #B2789C;
|
11
|
+
$navigation-inline-active-padding: 2px 10px;
|
12
|
+
|
13
|
+
// Base overrides
|
14
|
+
$body-background-color: #F5F5F5;
|
15
|
+
|
16
|
+
// Buttons
|
17
|
+
$button-default-background-color: #EA5D5F;
|
18
|
+
$button-primary-background: #7BD5D3;
|
19
|
+
$button-danger-background: #ecf0f1;
|
20
|
+
$button-success-background: #8ABD68;
|
21
|
+
|
22
|
+
// Labels
|
23
|
+
$label-default-background: $button-default-background-color;
|
24
|
+
$label-primary-background: #34495e;
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module SabisuRails
|
2
|
+
class BaseController < ApplicationController
|
3
|
+
|
4
|
+
layout SabisuRails.layout
|
5
|
+
|
6
|
+
before_filter :authenticate
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
def authenticate
|
11
|
+
authenticate_or_request_with_http_basic do |username, password|
|
12
|
+
username == SabisuRails.authentication_username && password == SabisuRails.authentication_password
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module SabisuRails
|
2
|
+
class ExplorerController < SabisuRails::BaseController
|
3
|
+
|
4
|
+
def index
|
5
|
+
@resources = SabisuRails.resources
|
6
|
+
@explorer = SabisuRails::Explorer.new(params[:explorer] || {})
|
7
|
+
@response = SabisuRails::Request.new(@explorer, params[@explorer.resource_name], params[:explorer]).response
|
8
|
+
respond_to do |format|
|
9
|
+
format.html
|
10
|
+
format.js
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module SabisuRails::ExplorerHelper
|
2
|
+
|
3
|
+
def label_attribute(explorer, attr)
|
4
|
+
explorer.required_attribute?(attr) ? "* #{attr.capitalize}" : attr.capitalize
|
5
|
+
end
|
6
|
+
|
7
|
+
def active_resource_state(resource)
|
8
|
+
loaded_resource = SabisuRails.default_resource
|
9
|
+
if params[:explorer].nil?
|
10
|
+
"active" if loaded_resource == resource
|
11
|
+
else
|
12
|
+
"active" if params[:explorer][:resource] == resource
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def prettify_headers(headers)
|
17
|
+
html = ""
|
18
|
+
headers.each do |k, v|
|
19
|
+
k = k.titleize.split(' ').join('-')
|
20
|
+
header_name = content_tag :span, k, class: 'text-muted text-strong'
|
21
|
+
arrow = content_tag :span," <i class='fa fa-long-arrow-right'></i> ".html_safe, class: 'text-muted'
|
22
|
+
header_value = content_tag :span, v, class: 'text-muted'
|
23
|
+
html << (header_name + arrow + header_value)
|
24
|
+
html << "<br />"
|
25
|
+
end
|
26
|
+
html.html_safe
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<html lang="en">
|
2
|
+
|
3
|
+
<head>
|
4
|
+
<!--includes meta tags, title and more header definitions-->
|
5
|
+
<meta charset="utf-8">
|
6
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
|
8
|
+
<link href="http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel="stylesheet" type="text/css">
|
9
|
+
|
10
|
+
<title>Sabisu Explorer</title>
|
11
|
+
|
12
|
+
<!-- Furatto core CSS -->
|
13
|
+
<%= stylesheet_link_tag "sabisu_rails/application", :cache => true %>
|
14
|
+
<%= csrf_meta_tag %>
|
15
|
+
|
16
|
+
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
|
17
|
+
<!--[if lt IE 9]>
|
18
|
+
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
|
19
|
+
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
|
20
|
+
<![endif]-->
|
21
|
+
</head>
|
22
|
+
|
23
|
+
<body>
|
24
|
+
<%= yield %>
|
25
|
+
<%= javascript_include_tag "sabisu_rails/application" %>
|
26
|
+
<%= yield :javascripts %>
|
27
|
+
</body>
|
28
|
+
</html>
|
@@ -0,0 +1,86 @@
|
|
1
|
+
<div class="row">
|
2
|
+
<div class="col-2 nopadding">
|
3
|
+
<ul class="navigation side">
|
4
|
+
<li class="header"><%= SabisuRails.app_name %> - <br /> Api Explorer</li>
|
5
|
+
<% @resources.each do |resource| %>
|
6
|
+
<li class="<%= active_resource_state(resource) %>"><%= link_to resource.capitalize, explorer_path(explorer: { resource: resource }) %></li>
|
7
|
+
<% end %>
|
8
|
+
</ul>
|
9
|
+
</div>
|
10
|
+
<div class="col-10 nopadding">
|
11
|
+
<div class="main-content">
|
12
|
+
<div class="row">
|
13
|
+
<div class="col-2">
|
14
|
+
<h4 class="text-muted"><%= "/#{@explorer.resource}/" %></h4>
|
15
|
+
</div>
|
16
|
+
<div class="col-10">
|
17
|
+
|
18
|
+
<%= form_for :explorer, url: explorer_path, html: {id: 'explorer_form'}, method: :get, remote: true do |f| %>
|
19
|
+
<%= f.hidden_field :resource, value: @explorer.resource %>
|
20
|
+
<div class="row">
|
21
|
+
<div class="col-6">
|
22
|
+
<%= f.text_field :uri_pattern, value: @explorer.uri_pattern, placeholder: "URI pattern. 1 or bids or orders/1" %>
|
23
|
+
</div>
|
24
|
+
<div class="col-2">
|
25
|
+
<%= f.select :http_method, options_for_select(SabisuRails.http_methods, @explorer.http_method.upcase) %>
|
26
|
+
</div>
|
27
|
+
<div class="col-2">
|
28
|
+
<a href="#" class="button radius block nomargin three-d explorer-fields-link-js" data-target="#url_params_inputs" data-type="url_params"><i class="fa fa-link"></i>Url params</a>
|
29
|
+
</div>
|
30
|
+
<div class="col-2">
|
31
|
+
<a href="#" class="button radius block nomargin three-d explorer-fields-link-js" data-target="#header_inputs" data-type="headers"><i class="fa fa-indent"></i> Headers</a>
|
32
|
+
</div>
|
33
|
+
</div>
|
34
|
+
<br />
|
35
|
+
<fieldset>
|
36
|
+
<legend>Url params (<span class="label round" id="url_params_counter_js">0</span>)</legend>
|
37
|
+
<div class="row" id="url_params_inputs">
|
38
|
+
|
39
|
+
</div>
|
40
|
+
</fieldset>
|
41
|
+
<fieldset>
|
42
|
+
<legend>Headers (<span class="label round" id="headers_counter_js">0</span>)</legend>
|
43
|
+
<div class="row" id="header_inputs">
|
44
|
+
|
45
|
+
</div>
|
46
|
+
</fieldset>
|
47
|
+
|
48
|
+
<%= f.submit "Send", class: 'button large radius three-d success', data: { :disable_with => "Processing..." } %>
|
49
|
+
<% end %>
|
50
|
+
</div>
|
51
|
+
</div>
|
52
|
+
|
53
|
+
<div class="response-wrapper">
|
54
|
+
<hr />
|
55
|
+
|
56
|
+
<div class="row">
|
57
|
+
<div class="response-details">
|
58
|
+
<ul class="navigation inline">
|
59
|
+
<li><small><strong>STATUS:</strong></small> <span class="label primary radius" id="response_status"><%= @response.code %></span></li>
|
60
|
+
<li><small><strong>TIME:</strong></small> <span class="label primary radius" id="response_time"><%= @response.headers['x-runtime'] %> ms</span></li>
|
61
|
+
</ul>
|
62
|
+
</div>
|
63
|
+
<ul class="navigation inline" data-tabu>
|
64
|
+
<li><a href="#result">Body</a></li>
|
65
|
+
<li><a href="#headers_result">(<span id="headers_count"><%= @response.headers.count %></span>) Headers</a></li>
|
66
|
+
</ul>
|
67
|
+
<div class="tabu-content">
|
68
|
+
<div class="content row" id="result">
|
69
|
+
</div>
|
70
|
+
<div class="content row headers" id="headers_result">
|
71
|
+
<%= prettify_headers @response.headers %>
|
72
|
+
</div>
|
73
|
+
</div>
|
74
|
+
</div>
|
75
|
+
</div>
|
76
|
+
</div>
|
77
|
+
</div>
|
78
|
+
</div>
|
79
|
+
|
80
|
+
<%= content_for :javascripts do %>
|
81
|
+
<script type="text/javascript" charset="utf-8">
|
82
|
+
$(document).ready(function(){
|
83
|
+
$.JSONView(<%= @response.body.html_safe %>, $('#result'));
|
84
|
+
});
|
85
|
+
</script>
|
86
|
+
<% end %>
|
@@ -0,0 +1,6 @@
|
|
1
|
+
$.JSONView(<%= @response.body.html_safe %>, $('#result'));
|
2
|
+
$("#response_status").text(<%= @response.code %>);
|
3
|
+
$("#response_time").text(<%= @response.headers['x-runtime'] %>);
|
4
|
+
$('#headers_result').html("<%= j prettify_headers @response.headers %>");
|
5
|
+
$('#headers_count').text(<%= @response.headers.count %>)
|
6
|
+
Pace.stop();
|
data/config/routes.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module SabisuRails
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path("../templates", __FILE__)
|
5
|
+
|
6
|
+
desc "Creates a Sabisu initializer in your application"
|
7
|
+
|
8
|
+
def copy_initializer
|
9
|
+
template "sabisu_rails.rb", "config/initializers/sabisu_rails.rb"
|
10
|
+
end
|
11
|
+
|
12
|
+
def mount_sabisu_engine
|
13
|
+
route %Q(mount SabisuRails::Engine => "/sabisu_rails")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Use this module to configure the sabisu available options
|
2
|
+
|
3
|
+
SabisuRails.setup do |config|
|
4
|
+
|
5
|
+
# Base uri for posting the
|
6
|
+
# config.base_api_uri = nil
|
7
|
+
|
8
|
+
# Ignored attributes for building the forms
|
9
|
+
# config.ignored_attributes = %w{ created_at updated_at id }
|
10
|
+
|
11
|
+
# HTTP methods
|
12
|
+
# config.http_methods = %w{ GET POST PUT DELETE PATCH }
|
13
|
+
|
14
|
+
# Headers to include on each request
|
15
|
+
# config.api_headers = {}
|
16
|
+
|
17
|
+
# Layout configuration
|
18
|
+
# config.layout = "sabisu"
|
19
|
+
|
20
|
+
# Resources on the api
|
21
|
+
# config.resources = [:products, :users...]
|
22
|
+
|
23
|
+
# Application name
|
24
|
+
# mattr_accessor :app_name
|
25
|
+
# @@app_name = Rails.application.class.parent_name
|
26
|
+
|
27
|
+
# Authentication
|
28
|
+
# mattr_accessor :authentication_username
|
29
|
+
# @@authentication_username = "admin"
|
30
|
+
|
31
|
+
# mattr_accessor :authentication_password
|
32
|
+
# @@authentication_password = "sekret"
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module SabisuRails
|
2
|
+
module Builders
|
3
|
+
class Base
|
4
|
+
|
5
|
+
def initialize(params)
|
6
|
+
@params = params || {}
|
7
|
+
sanitize_params
|
8
|
+
end
|
9
|
+
|
10
|
+
def build
|
11
|
+
query_params = {}
|
12
|
+
@sanitized_params.each do |k,v|
|
13
|
+
values = v.values #returns the nested hash, and we get the values from that hash
|
14
|
+
query_params[values[0]] = values[1]
|
15
|
+
end
|
16
|
+
query_params
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def sanitize_params
|
22
|
+
@sanitized_params = @params.reject { |k,v| v.blank? }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|