rails_api_explorer 0.0.2.pre.1 → 0.0.3.pre.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: 92e109fe3ecbff439ba1527c91138e8aea97cae1
4
- data.tar.gz: 6ae0e546fab6cb707335daaefe25c6b496658eaa
3
+ metadata.gz: dacad37d291f229361c45ca9d3e110c4b17f0012
4
+ data.tar.gz: ff5df9502368e73e237550cb4f1cbc80e51d510b
5
5
  SHA512:
6
- metadata.gz: 5941e240df85be5594187045bed33bda332cda60ca1d5115a118eaa09b1ff2724a74be737c22c544fa93b67ab3902abc7c0aee04783c4490cd5e0b2bc31bcde5
7
- data.tar.gz: 6a201c1994bd8100f41e6f700e669003c2b2ceae847ccd4c1974f719292f56e8c08179571cb44d26b104900f2a5aea17a831bfc8040297d391c78f1edd11649b
6
+ metadata.gz: b6a90cf0709ce9c7e1d08fb79277116d4d0a7b1ebb9582d5699217728595363e991b6601ec1e11c775699974e7e24c0282e8d9f23b7e34441e5d2f2993133ee1
7
+ data.tar.gz: 6013f6dfb5d59b644c9b3218006f81018186dfe57854af33c0aea2fae1c840d51573eec186f6199e07c7ace2eafc5acb61b7380ea0ab58c969735ac19a9b69b6
data/README.md CHANGED
@@ -1,11 +1,9 @@
1
1
  # rails_api_explorer
2
2
 
3
- Provides a simple DSL to describe your API, and let's you mount an interactive sandbox to explore and test it.
3
+ Provides a simple DSL to describe your JSON API, and let's you mount an interactive sandbox to explore and test it.
4
4
 
5
5
  [Here's a demo.](http://rails-api-explorer.herokuapp.com)
6
6
 
7
- This project is in the early stages of development and missing some features. Pull requests are more than welcome!
8
-
9
7
  ## Installation
10
8
 
11
9
  Add this line to your application's Gemfile:
@@ -18,8 +16,21 @@ And then execute:
18
16
 
19
17
  $ bundle
20
18
 
19
+
21
20
  ## Usage
22
21
 
22
+ ### Assets
23
+ Include the JavaScript in your `application.js`, make sure to require it *after* jQuery:
24
+
25
+ //= require jquery
26
+ //= require api_explorer
27
+
28
+ Include the CSS in `application.css`:
29
+
30
+ *= require api_explorer
31
+
32
+
33
+ ### Describe your API
23
34
  Describe your API in `config/initializers/api_explorer.rb`:
24
35
 
25
36
  ```ruby
@@ -74,7 +85,7 @@ Then mount it in your `routes.rb`:
74
85
  mount ApiExplorer::Engine => '/api/explore', as: 'api_explorer'
75
86
  ```
76
87
 
77
-
88
+ ### Access control
78
89
  If you don't want the public to access the explorer, you can provide a lambda that will be executed in the `before_filter` of the controller:
79
90
 
80
91
  ```ruby
@@ -84,6 +95,7 @@ ApiExplorer.auth = lambda do
84
95
  end
85
96
  ```
86
97
 
98
+ ## Notes
87
99
  The explorer is rendered within your application layout and uses bootstrap 3 classes, so it's prettier if you have that included.
88
100
  Bootstrap is optional, but it requires jQuery.
89
101
 
data/Rakefile CHANGED
@@ -14,10 +14,8 @@ RDoc::Task.new(:rdoc) do |rdoc|
14
14
  rdoc.rdoc_files.include('lib/**/*.rb')
15
15
  end
16
16
 
17
- APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
17
  load 'rails/tasks/engine.rake'
19
18
 
20
19
 
21
20
 
22
21
  Bundler::GemHelper.install_tasks
23
-
@@ -1,54 +1,54 @@
1
- $.fn.serializeObject = function() {
2
- var self = this,
3
- json = {},
4
- push_counters = {},
5
- patterns = {
6
- "validate": /^[a-zA-Z][a-zA-Z0-9_\-]*(?:\[(?:\d*|[a-zA-Z0-9_\-]+)\])*$/,
7
- "key": /[a-zA-Z0-9_\-]+|(?=\[\])/g,
8
- "push": /^$/,
9
- "fixed": /^\d+$/,
10
- "named": /^[a-zA-Z0-9_\-]+$/
11
- };
1
+ $.fn.serializeObject = function() {
2
+ var self = this,
3
+ json = {},
4
+ push_counters = {},
5
+ patterns = {
6
+ "validate": /^[a-zA-Z][a-zA-Z0-9_\-]*(?:\[(?:\d*|[a-zA-Z0-9_\-]+)\])*$/,
7
+ "key": /[a-zA-Z0-9_\-]+|(?=\[\])/g,
8
+ "push": /^$/,
9
+ "fixed": /^\d+$/,
10
+ "named": /^[a-zA-Z0-9_\-]+$/
11
+ };
12
12
 
13
- this.build = function(base, key, value){
14
- base[key] = value;
15
- return base;
16
- };
17
- this.push_counter = function(key){
18
- if(push_counters[key] === undefined){
19
- push_counters[key] = 0;
20
- }
21
- return push_counters[key]++;
22
- };
23
- $.each($(this).serializeArray(), function(){
24
- // skip invalid keys
25
- if(!patterns.validate.test(this.name)) {
26
- return;
27
- }
28
- var k,
29
- keys = this.name.match(patterns.key),
30
- merge = this.value,
31
- reverse_key = this.name;
13
+ this.build = function(base, key, value){
14
+ base[key] = value;
15
+ return base;
16
+ };
17
+ this.push_counter = function(key){
18
+ if(push_counters[key] === undefined){
19
+ push_counters[key] = 0;
20
+ }
21
+ return push_counters[key]++;
22
+ };
23
+ $.each($(this).serializeArray(), function(){
24
+ // skip invalid keys
25
+ if(!patterns.validate.test(this.name)) {
26
+ return;
27
+ }
28
+ var k,
29
+ keys = this.name.match(patterns.key),
30
+ merge = this.value,
31
+ reverse_key = this.name;
32
32
 
33
- while((k = keys.pop()) !== undefined){
33
+ while((k = keys.pop()) !== undefined){
34
34
 
35
- // adjust reverse_key
36
- reverse_key = reverse_key.replace(new RegExp("\\[" + k + "\\]$"), '');
35
+ // adjust reverse_key
36
+ reverse_key = reverse_key.replace(new RegExp("\\[" + k + "\\]$"), '');
37
37
 
38
- // push
39
- if(k.match(patterns.push)){
40
- merge = self.build([], self.push_counter(reverse_key), merge);
41
- }
42
- // fixed
43
- else if(k.match(patterns.fixed)){
44
- merge = self.build([], k, merge);
45
- }
46
- // named
47
- else if(k.match(patterns.named)){
48
- merge = self.build({}, k, merge);
49
- }
38
+ // push
39
+ if(k.match(patterns.push)){
40
+ merge = self.build([], self.push_counter(reverse_key), merge);
50
41
  }
51
- json = $.extend(true, json, merge);
52
- });
53
- return json;
54
- };
42
+ // fixed
43
+ else if(k.match(patterns.fixed)){
44
+ merge = self.build([], k, merge);
45
+ }
46
+ // named
47
+ else if(k.match(patterns.named)){
48
+ merge = self.build({}, k, merge);
49
+ }
50
+ }
51
+ json = $.extend(true, json, merge);
52
+ });
53
+ return json;
54
+ };
@@ -10,7 +10,5 @@
10
10
  // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
11
  // about supported directives.
12
12
  //
13
- //= require jquery
14
- //= require jquery_ujs
15
13
  //= require api_explorer/serialize_object
16
- //= require_tree .
14
+ //= require api_explorer/explorer
@@ -1,5 +1,5 @@
1
1
  <div class="row request" id="node<%= id %>">
2
- <%= form_for :request, url: request_path, html: { class: "col-sm-6" } do |f| %>
2
+ <%= form_for :request, html: { class: "col-sm-6" } do |f| %>
3
3
  <%= f.hidden_field :method, value: req.method %>
4
4
  <%= f.hidden_field :path, value: req.full_path %>
5
5
 
@@ -9,7 +9,6 @@
9
9
  <% req.url_segments.each do |type, s| %>
10
10
  <% if type == :param %>
11
11
  <%= pf.text_field s, placeholder: ":#{s}" %>
12
- <!-- span contenteditable="true" data-ph="<%= ":#{s}" %>" data-name="<%= s %>"></span -->
13
12
  <% else %>
14
13
  <%= raw s %>
15
14
  <% end %>
@@ -20,7 +19,6 @@
20
19
  <div>
21
20
  <p><%= simple_format req.description %></p>
22
21
 
23
- <!-- %= render 'api_explorer/explorer/form/url_params', params: req.url_params, f: f % -->
24
22
  <%= render 'api_explorer/explorer/form/headers', request: req, f: f %>
25
23
  <% if req.params.any? %>
26
24
  <fieldset>
@@ -6,8 +6,6 @@
6
6
  <% @description.headers.each do |h| %>
7
7
  <% next if request.excluded_shared_headers.include?(h.name) %>
8
8
 
9
- <!--%= hf.label h.name, h.name %-->
10
- <!--%= raw " (<a class='shared-link' href='#shared-header-#{h.name}'>shared</a>)" %-->
11
9
  <%= hf.hidden_field h.name, class: "shared header", data: { name: h.name } %>
12
10
  <% end %>
13
11
  <% end %>
@@ -3,9 +3,6 @@
3
3
  window.api_explorer_base_url = "<%= @description.base_url %>";
4
4
  </script>
5
5
 
6
- <%= stylesheet_link_tag "api_explorer/application", media: "all" %>
7
- <%= javascript_include_tag "api_explorer/application" %>
8
-
9
6
  <div class="row">
10
7
  <div class="col-sm-12">
11
8
  <h1>Index</h1>
data/config/routes.rb CHANGED
@@ -1,4 +1,3 @@
1
1
  ApiExplorer::Engine.routes.draw do
2
2
  root to: 'explorer#index'
3
- post 'request' => 'explorer#perform_request'
4
3
  end
@@ -1,5 +1,9 @@
1
1
  module ApiExplorer
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace ApiExplorer
4
+
5
+ initializer "rails_api_explorer.assets.precompile" do |app|
6
+ app.config.assets.precompile += %w(api_explorer.css api_explorer.js)
7
+ end
4
8
  end
5
9
  end
@@ -1,3 +1,3 @@
1
1
  module ApiExplorer
2
- VERSION = "0.0.2.pre.1"
2
+ VERSION = "0.0.3.pre.1"
3
3
  end
data/lib/api_explorer.rb CHANGED
@@ -8,12 +8,11 @@ require "api_explorer/request"
8
8
  require "api_explorer/dsl"
9
9
 
10
10
  module ApiExplorer
11
- mattr_accessor :description, :shared_headers, :shared_params, :auth
11
+ mattr_accessor :description, :auth
12
12
 
13
13
  def self.describe(&block)
14
14
  self.description = Description.new("", "", [], [], [])
15
15
  proxy = DescriptionProxy.new(description)
16
16
  proxy.collect(&block)
17
- #self.description = Description.new(proxy.path, proxy.children, proxy.shared_headers, proxy.shared_params)
18
17
  end
19
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_api_explorer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2.pre.1
4
+ version: 0.0.3.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Hollmann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-30 00:00:00.000000000 Z
11
+ date: 2015-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: jquery-rails
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: sqlite3
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -90,11 +76,11 @@ files:
90
76
  - MIT-LICENSE
91
77
  - README.md
92
78
  - Rakefile
93
- - app/assets/javascripts/api_explorer/application.js
79
+ - app/assets/javascripts/api_explorer.js
94
80
  - app/assets/javascripts/api_explorer/explorer.js
95
81
  - app/assets/javascripts/api_explorer/scroll.js
96
82
  - app/assets/javascripts/api_explorer/serialize_object.js
97
- - app/assets/stylesheets/api_explorer/application.css
83
+ - app/assets/stylesheets/api_explorer.css
98
84
  - app/assets/stylesheets/api_explorer/explorer.css
99
85
  - app/controllers/api_explorer/application_controller.rb
100
86
  - app/controllers/api_explorer/explorer_controller.rb