rails_to_postman 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +25 -0
- data/Rakefile +2 -0
- data/lib/rails_to_postman.rb +8 -0
- data/lib/rails_to_postman/main.rb +95 -0
- data/lib/rails_to_postman/railtie.rb +11 -0
- data/lib/rails_to_postman/version.rb +3 -0
- data/lib/tasks/rails_to_postman.rake +4 -0
- data/rails_to_postman.gemspec +17 -0
- data/rails_to_postman.tmproj +27 -0
- metadata +59 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 vachman
|
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,25 @@
|
|
1
|
+
# RailsToPostman
|
2
|
+
|
3
|
+
TODO: Convert Ruby on Rails application routes to Postman REST Client format end export to json file.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rails_to_postman'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
$ rake export_routes
|
18
|
+
|
19
|
+
## Contributing
|
20
|
+
|
21
|
+
1. Fork it
|
22
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
23
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
24
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
25
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
module RailsToPostman
|
2
|
+
|
3
|
+
def self.export_routes
|
4
|
+
load Rails.application.root.join('config/routes.rb')
|
5
|
+
resources = get_routes
|
6
|
+
doc = render_postman_json_from(resources)
|
7
|
+
save_to_file(doc)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.normalise_route(route, path_prefix = nil)
|
11
|
+
route.verb.source.split('|').map do |verb|
|
12
|
+
{
|
13
|
+
:id => @_route_counter+=1,
|
14
|
+
:name => route.name,
|
15
|
+
:verb => verb.gsub(/[$^]/, ''),
|
16
|
+
:path => path_prefix.to_s + route.path.spec.to_s.sub('(.:format)', ''),
|
17
|
+
:reqs => route.requirements
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.get_routes
|
23
|
+
@_route_counter = 0
|
24
|
+
routes = []
|
25
|
+
Rails.application.routes.routes.each do |route|
|
26
|
+
next if route.app.is_a?(ActionDispatch::Routing::Mapper::Constraints)
|
27
|
+
routes << normalise_route(route)[0]
|
28
|
+
end
|
29
|
+
grouped_routes(routes.compact)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.grouped_routes(routes)
|
33
|
+
routes.group_by { |r| r[:reqs][:controller] }
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.render_postman_json_from(resources)
|
37
|
+
collection_id = Rails.application.class.parent.to_s.downcase
|
38
|
+
collection_name = Rails.application.class.parent.to_s
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
postman_json = {
|
43
|
+
id: collection_id,
|
44
|
+
name: collection_name,
|
45
|
+
timestamp: '1360664941208',
|
46
|
+
order: [],
|
47
|
+
requests: []
|
48
|
+
}
|
49
|
+
|
50
|
+
resources.each do |resource, routes|
|
51
|
+
postman_json[:order] << "resource##{resource}"
|
52
|
+
postman_json[:requests] << {
|
53
|
+
collectionId: collection_id,
|
54
|
+
id: "resource##{resource}",
|
55
|
+
name: resource.upcase,
|
56
|
+
description: "#{resource.capitalize} resources",
|
57
|
+
url: "/#{resource}",
|
58
|
+
method: "RESOURCES",
|
59
|
+
headers: "",
|
60
|
+
data: [],
|
61
|
+
dataMode: "params",
|
62
|
+
timestamp: 0,
|
63
|
+
responses: [],
|
64
|
+
version: 2
|
65
|
+
}
|
66
|
+
|
67
|
+
routes.each do |route|
|
68
|
+
postman_json[:order] << "#{resource}##{route[:reqs][:action]}"
|
69
|
+
postman_json[:requests] << {
|
70
|
+
collectionId: collection_id,
|
71
|
+
id: "#{resource}##{route[:reqs][:action]}",
|
72
|
+
name: "#{route[:reqs][:action]}",
|
73
|
+
description: "#{resource.capitalize} '#{route[:reqs][:action]}' method",
|
74
|
+
url: "{{url}}#{route[:path]}?token={{token}}",
|
75
|
+
method: route[:verb],
|
76
|
+
headers: "",
|
77
|
+
data: [],
|
78
|
+
dataMode: "params",
|
79
|
+
timestamp: 0,
|
80
|
+
responses: [],
|
81
|
+
version: 2
|
82
|
+
}
|
83
|
+
end
|
84
|
+
end
|
85
|
+
postman_json
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.save_to_file(doc)
|
89
|
+
file_path = "tmp/#{Rails.application.class.parent.to_s.downcase}_routes_for_postman.json"
|
90
|
+
output_file = File.open( file_path, 'w')
|
91
|
+
output_file << doc.to_json
|
92
|
+
output_file.close
|
93
|
+
puts "Rails to Postman - routes exported to: '#{file_path}'"
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/rails_to_postman/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Gevorgyan Vachagan"]
|
6
|
+
gem.email = ["va4@me.com"]
|
7
|
+
gem.description = %q{Export rails routes to json for Postman REST Client}
|
8
|
+
gem.summary = %q{Convert Ruby on Rails application routes to Postman REST Client format end export to json file.}
|
9
|
+
gem.homepage = "https://github.com/Vachman/rails_to_postman"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "rails_to_postman"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = RailsToPostman::VERSION
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
3
|
+
<plist version="1.0">
|
4
|
+
<dict>
|
5
|
+
<key>documents</key>
|
6
|
+
<array>
|
7
|
+
<dict>
|
8
|
+
<key>expanded</key>
|
9
|
+
<true/>
|
10
|
+
<key>name</key>
|
11
|
+
<string>rails_to_postman</string>
|
12
|
+
<key>regexFolderFilter</key>
|
13
|
+
<string>!.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string>
|
14
|
+
<key>sourceDirectory</key>
|
15
|
+
<string></string>
|
16
|
+
</dict>
|
17
|
+
</array>
|
18
|
+
<key>fileHierarchyDrawerWidth</key>
|
19
|
+
<integer>292</integer>
|
20
|
+
<key>metaData</key>
|
21
|
+
<dict/>
|
22
|
+
<key>showFileHierarchyDrawer</key>
|
23
|
+
<true/>
|
24
|
+
<key>windowFrame</key>
|
25
|
+
<string>{{295, 0}, {981, 778}}</string>
|
26
|
+
</dict>
|
27
|
+
</plist>
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_to_postman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gevorgyan Vachagan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-20 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Export rails routes to json for Postman REST Client
|
15
|
+
email:
|
16
|
+
- va4@me.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/rails_to_postman.rb
|
27
|
+
- lib/rails_to_postman/main.rb
|
28
|
+
- lib/rails_to_postman/railtie.rb
|
29
|
+
- lib/rails_to_postman/version.rb
|
30
|
+
- lib/tasks/rails_to_postman.rake
|
31
|
+
- rails_to_postman.gemspec
|
32
|
+
- rails_to_postman.tmproj
|
33
|
+
homepage: https://github.com/Vachman/rails_to_postman
|
34
|
+
licenses: []
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.8.23
|
54
|
+
signing_key:
|
55
|
+
specification_version: 3
|
56
|
+
summary: Convert Ruby on Rails application routes to Postman REST Client format end
|
57
|
+
export to json file.
|
58
|
+
test_files: []
|
59
|
+
has_rdoc:
|