api_bluerails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 59fec8440a48e7345215a750d69e2231d2a8e118
4
+ data.tar.gz: 2422a7fd4876a3b2b2b4ca1bf692799f5f2831ca
5
+ SHA512:
6
+ metadata.gz: a21a6678fa24d0ae66a7edfaf90c116a8cfe3ed1ce991979c69dacc89384a86a558f5c925010a8738efeefbf2bb1f2c2d87b6c00859d6bc9fe9a073798520667
7
+ data.tar.gz: 0b35f3990cac2e6a74d3acee8871727307903d7f65060c18017602490bec378b795266277b577057ce2c2711799fe11ad49eb64a1e1b338a3a1fd612a6dd8153
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Manuel Dudda
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,61 @@
1
+ # Api Bluerails
2
+
3
+ This project uses MIT-LICENSE.
4
+
5
+ Tools for developing an API written in Rails with api blueprint documentation
6
+
7
+ ## Usage
8
+
9
+ ### Overview of provided Rake Tasks
10
+
11
+ ```shell
12
+ rake -T
13
+
14
+ rake doc:coverage # Print Coverage of the api blueprint with rails routes
15
+ ```
16
+
17
+
18
+ ### doc:coverage
19
+
20
+ ```shell
21
+ >>>
22
+ available Routes
23
+ -----------------------------------------------------------------------------------------------------------------
24
+ /assets | GET, POST, PUT, DELETE
25
+ /oauth/authorize/:code.json | GET
26
+ /oauth/authorize.json | GET, POST, PUT, DELETE
27
+ /oauth/token.json | POST
28
+ /oauth/revoke.json | POST
29
+ ...
30
+ /api/status.json | GET
31
+ /rails/info/properties.json | GET, POST, PUT, DELETE
32
+ = 96 | = 153
33
+
34
+ <<<
35
+
36
+
37
+ >>>
38
+ documneted routes
39
+ -----------------------------------------------------------------------------------------------------------------
40
+ /api/status.json | GET
41
+ /oauth/token.json | POST, POST, POST
42
+ /api/v2/users.json | POST, DELETE
43
+ /api/v2/users/sign_in.json | GET
44
+ = 4 | = 7
45
+
46
+ <<<
47
+
48
+
49
+ >>>
50
+ not documented routes
51
+ -----------------------------------------------------------------------------------------------------------------
52
+ /api/v2/partner/{namespace}/{foreign_token}/store.json | GET
53
+ /api/v2/partner/{namespace}/{foreign_token}/transactions.json | POST
54
+ /api/v2/user/payment_identities/{payment_identity_id}.json | PUT, DELETE
55
+ = 3 | = 4
56
+
57
+ <<<
58
+ echo $?
59
+ 4
60
+
61
+ ```
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'api_bluerails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'api_bluerails'
8
+ spec.version = ApiBluerails::VERSION
9
+ spec.authors = ['Manuel Dudda']
10
+ spec.email = ['manueldudda@redpeppix.de']
11
+ spec.summary = 'Tools for developing an API written in Rails with api blueprint documentation'
12
+ spec.description = 'Tools for developing an API written in Rails with api blueprint documentation'
13
+ spec.homepage = 'https://github.com/manuel84/api_bluerails'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+ spec.add_runtime_dependency 'rails'
21
+
22
+ end
@@ -0,0 +1,16 @@
1
+ %w(version coverage railtie).each { |f| require "api_bluerails/#{f}" }
2
+
3
+ module ApiBluerails
4
+ def self.coverage
5
+ app_urls_hash, covered_urls_hash, uncovered_urls_hash = ApiBluerails::Coverage.coverage
6
+ {'verfügbare Routes' => app_urls_hash, 'dokumentierte Routes' => covered_urls_hash, 'nicht dokumentierte Routes' => uncovered_urls_hash}.each do |title, hash|
7
+ puts "\n\n>>>"
8
+ puts title
9
+ puts "-"*113
10
+ hash.each { |url, verbs| puts sprintf("%80s | %30s", url, verbs.join(', ')) }
11
+ puts sprintf("=%79s | =%29s", hash.keys.count, hash.values.sum { |v| v.count })
12
+ puts "\n<<<"
13
+ end
14
+ exit [uncovered_urls_hash.size, 255].min
15
+ end
16
+ end
@@ -0,0 +1,75 @@
1
+ module ApiBluerails
2
+ class Coverage
3
+ def self.coverage
4
+ routes = Rails.application.routes.routes
5
+ app_urls_hash = Hash.new([])
6
+ app_urls = routes.collect { |r| [r.path.spec.to_s, r.constraints] }
7
+ app_urls.each do |app_url, constraint|
8
+ app_url.gsub!('(/:locale)', '/locale') # (/:locale)/users/sign_in(.:format) => /locale/users/sign_in(.:format)
9
+ app_url.gsub!('(.:format)', '.json') # /api/v2/devices/:device_id/transactions/:id/assume(.:format) => /api/v2/devices/:device_id/transactions/:id/assume.json
10
+ app_url.gsub!(/\:([a-zA-Z_]+)\//, '{\1}/') # /api/v2/devices/:device_id/transactions/:id/assume.json => /api/v2/devices/{device_id}/transactions/:id/assume.json
11
+
12
+ if app_url.ends_with?(':id.json')
13
+ resource = app_url.split('/')[-2].ends_with?('}') ? app_url.split('/')[-3] : app_url.split('/')[-2]
14
+ app_url.gsub!(':id.json', "{#{resource.singularize}_id}.json") # /api/v2/user/transactions/:id.json => /api/v2/user/transactions/{transaction_id}.json
15
+ end
16
+
17
+ if app_url.include?('{id}')
18
+ namespaces = app_url.split('/')
19
+ app_url.gsub!('{id}', "{#{namespaces[namespaces.index('{id}')-1].singularize}_id}") # /api/v2/user/transactions/{id}/receipt.json => /api/v2/user/transactions/{transaction_id}/receipt.json
20
+ end
21
+ app_urls_hash[app_url] += constraint.has_key?(:request_method) ? constraint[:request_method].source.gsub('^', '').gsub('$', '').split('|') : %w(GET POST PUT DELETE)
22
+ end
23
+
24
+ #puts app_urls_hash
25
+
26
+ apib_file = File.read api_doc_location(determine_latest_api_version)
27
+ url_holder_pattern = /^##\s.+\[(\/.+)(json|{format})(\{\?.+\})?\]$/
28
+ # Regex for:
29
+ ## User Transaction [/api/v2/user/transactions/{transaction_id}.{format}{?user_key,device_id}]
30
+ # =>
31
+ #1. /api/v2/user/transactions/{transaction_id}.
32
+ #2. {format}
33
+ #3. {?user_key,device_id}
34
+
35
+ http_verb_pattern = /^###\s.+\[(GET|POST|PUT|DELETE)\]$/
36
+ covered_urls_hash = {}
37
+ current_url = ""
38
+ apib_file.each_line do |line|
39
+ matchdata = line.match(url_holder_pattern)
40
+ matchdata2 = line.match(http_verb_pattern)
41
+ if matchdata
42
+ current_url = matchdata[1] + matchdata[2]
43
+ current_url.gsub!('{format}', 'json')
44
+ covered_urls_hash[current_url] = []
45
+ end
46
+ covered_urls_hash[current_url] << matchdata2[1] if matchdata2
47
+ end
48
+
49
+
50
+ # ignore the following routes
51
+ exceptions = {
52
+ # Rails routes
53
+ '/assets' => %w(GET POST PUT DELETE),
54
+ '/rails/info/properties.json' => %w(GET POST PUT DELETE)
55
+ }
56
+ config_file = Rails.root.join('config', 'api_bluerails.yml')
57
+ if File.exists?(config_file)
58
+ config = YAML.load(File.open(config_file)).freeze
59
+ exceptions.merge! config['exceptions'] if config['exceptions']
60
+ end
61
+
62
+ uncovered_urls_hash = {}
63
+ app_urls_hash.each do |url, verbs|
64
+ uncovered_urls_hash[url] = verbs
65
+ uncovered_urls_hash[url] = verbs - covered_urls_hash[url] if covered_urls_hash.has_key?(url)
66
+ uncovered_urls_hash[url] -= exceptions[url] if exceptions.has_key?(url)
67
+ end
68
+
69
+
70
+ uncovered_urls_hash.delete_if { |k, v| v.empty? }
71
+ return app_urls_hash, covered_urls_hash, uncovered_urls_hash
72
+ end
73
+ end
74
+
75
+ end
@@ -0,0 +1,11 @@
1
+ require 'api_bluerails'
2
+ require 'rails'
3
+ module ApiBluerails
4
+ class Railtie < Rails::Railtie
5
+ rake_tasks do
6
+ f = File.join(File.dirname(__FILE__), '..', '..', 'tasks', 'coverage.rake')
7
+ load f
8
+ # load 'tasks/uml.rake'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module ApiBluerails
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,8 @@
1
+ namespace :doc do
2
+
3
+ desc 'Print Coverage of the api blueprint with rails routes'
4
+ task :coverage => :environment do
5
+ ApiBluerails.coverage
6
+ end
7
+
8
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: api_bluerails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Manuel Dudda
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-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: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Tools for developing an API written in Rails with api blueprint documentation
28
+ email:
29
+ - manueldudda@redpeppix.de
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENSE.txt
35
+ - README.md
36
+ - api_bluerails.gemspec
37
+ - lib/api_bluerails.rb
38
+ - lib/api_bluerails/coverage.rb
39
+ - lib/api_bluerails/railtie.rb
40
+ - lib/api_bluerails/version.rb
41
+ - tasks/coverage.rake
42
+ homepage: https://github.com/manuel84/api_bluerails
43
+ licenses:
44
+ - MIT
45
+ metadata: {}
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 2.2.2
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: Tools for developing an API written in Rails with api blueprint documentation
66
+ test_files: []