tomograph 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.rubocop.yml +11 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +4 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/tomograph.rb +14 -0
- data/lib/tomograph/configuration.rb +10 -0
- data/lib/tomograph/tomogram.rb +133 -0
- data/lib/tomograph/version.rb +3 -0
- data/tomograph.gemspec +26 -0
- metadata +186 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 207c274dea45b01a52e1f334ae5ffff33a37030b
|
4
|
+
data.tar.gz: 70e94ec412396908ba3aaff0885c53e5e458ed43
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ff7f894599ab4faa348e7c17327f88ceb7766bfb0f476975c6785132b0b177855ecbb0ec2d0ea82a1b704b0454f4c318994f7eb273a2ec2ac5023d39435790a9
|
7
|
+
data.tar.gz: adcd0502914565b4b19e2b6802c8133a92ee8c57c21f9afe454c3f6ab4b74cf108ae574183eaebe390ba5b6a5c9df2e024fd50cb897cec47af660f1592167bb1
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at d.efimov@fun-box.ru. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 d.efimov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# tomograph
|
2
|
+
|
3
|
+
This is make API Tomogram
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
config/application.rb
|
8
|
+
|
9
|
+
```
|
10
|
+
require 'tomograph'
|
11
|
+
```
|
12
|
+
|
13
|
+
## Config
|
14
|
+
|
15
|
+
### documentation
|
16
|
+
|
17
|
+
For gem needed by a ```drafter``` generate and save ```yaml``` file, and then turn it on config.
|
18
|
+
```
|
19
|
+
drafter doc/api.apib -o doc/api.yaml
|
20
|
+
```
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
Tomograph.configure do |config|
|
24
|
+
config.documentation = 'doc/api.yaml'
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
Then you can use the API tomogram by using the following call:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
Tomograph::Tomogram.json
|
32
|
+
```
|
33
|
+
|
34
|
+
API tomogram return to json format.
|
35
|
+
|
36
|
+
### prefix
|
37
|
+
Default empty String. This is prefix for url if in docimentation URI short .
|
38
|
+
|
39
|
+
## License
|
40
|
+
|
41
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'tomograph'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/tomograph.rb
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
|
3
|
+
module Tomograph
|
4
|
+
class Tomogram < String
|
5
|
+
class << self
|
6
|
+
def json
|
7
|
+
single_sharp = find_resource
|
8
|
+
|
9
|
+
result = single_sharp['content'].inject([]) do |result, resource|
|
10
|
+
next result if text_node?(resource)
|
11
|
+
|
12
|
+
result.concat(extract_actions(resource))
|
13
|
+
end
|
14
|
+
MultiJson.dump(result)
|
15
|
+
end
|
16
|
+
|
17
|
+
def delete_query_and_last_slash(path)
|
18
|
+
path = delete_till_the_end(path, '{&')
|
19
|
+
path = delete_till_the_end(path, '{?')
|
20
|
+
|
21
|
+
remove_the_slash_at_the_end(path)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def extract_actions(resource)
|
27
|
+
actions = []
|
28
|
+
resource_path = resource['attributes'] && resource['attributes']['href']
|
29
|
+
|
30
|
+
transitions = resource['content']
|
31
|
+
transitions.each do |transition|
|
32
|
+
next unless transition['element'] == 'transition'
|
33
|
+
|
34
|
+
path = transition['attributes'] && transition['attributes']['href'] || resource_path
|
35
|
+
|
36
|
+
transition['content'].each do |content|
|
37
|
+
next unless content['element'] == 'httpTransaction'
|
38
|
+
|
39
|
+
action = build_action(content, path)
|
40
|
+
actions << action if action
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
actions.group_by { |action| action['method'] + action['path'] }.map do |_key, resource_actions|
|
45
|
+
# because in yaml a response has a copy of the same request we can only use the first
|
46
|
+
{
|
47
|
+
'path' => resource_actions.first['path'],
|
48
|
+
'method' => resource_actions.first['method'],
|
49
|
+
'request' => resource_actions.first['request'],
|
50
|
+
'responses' => resource_actions.flat_map { |action| action['responses'] }.compact
|
51
|
+
}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def find_resource
|
56
|
+
documentation['content'][0]['content'].find do |resource|
|
57
|
+
!text_node?(resource) &&
|
58
|
+
resource['meta']['classes'][0] == 'resourceGroup' # skip Data Structures
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def documentation
|
63
|
+
YAML.load(File.read("#{Rails.root}/#{Tomograph.configuration.documentation}"))
|
64
|
+
end
|
65
|
+
|
66
|
+
def delete_till_the_end(path, beginning_with)
|
67
|
+
path_index = path.index(beginning_with)
|
68
|
+
path_index ||= 0
|
69
|
+
path_index -= 1
|
70
|
+
path.slice(0..path_index)
|
71
|
+
end
|
72
|
+
|
73
|
+
def remove_the_slash_at_the_end(path)
|
74
|
+
if path[-1] == '/'
|
75
|
+
path[0..-2]
|
76
|
+
else
|
77
|
+
path
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def build_action(content, path)
|
82
|
+
return if text_node?(content)
|
83
|
+
|
84
|
+
action_to_hash(content['content'], path)
|
85
|
+
end
|
86
|
+
|
87
|
+
def action_to_hash(actions, path)
|
88
|
+
{
|
89
|
+
'path' => "#{Tomograph.configuration.prefix}#{delete_query_and_last_slash(path)}",
|
90
|
+
'method' => actions.first['attributes']['method'],
|
91
|
+
'request' => request(actions),
|
92
|
+
'responses' => responses(actions)
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
def request(actions)
|
97
|
+
request_action = actions.find {|el| el['element'] === 'httpRequest' }
|
98
|
+
json_schema(request_action['content'])
|
99
|
+
end
|
100
|
+
|
101
|
+
def json_schema?(action)
|
102
|
+
action && action['element'] == 'asset' && action['attributes']['contentType'] == 'application/schema+json'
|
103
|
+
end
|
104
|
+
|
105
|
+
def responses(actions)
|
106
|
+
response_actions = actions.select {|el| el['element'] === 'httpResponse' }
|
107
|
+
|
108
|
+
response_actions.map do |response|
|
109
|
+
return unless response['attributes'] # if no response
|
110
|
+
|
111
|
+
{
|
112
|
+
'status' => response['attributes']['statusCode'],
|
113
|
+
'body' => json_schema(response['content'])
|
114
|
+
}
|
115
|
+
end.compact
|
116
|
+
end
|
117
|
+
|
118
|
+
def json_schema(actions)
|
119
|
+
schema_node = actions.find {|action| json_schema?(action) }
|
120
|
+
return {} unless schema_node
|
121
|
+
|
122
|
+
MultiJson.load(schema_node['content'])
|
123
|
+
rescue MultiJson::ParseError => e
|
124
|
+
puts "[Tomograph] Error while parsing #{ e }. skipping..."
|
125
|
+
{}
|
126
|
+
end
|
127
|
+
|
128
|
+
def text_node?(node)
|
129
|
+
node['element'] == 'copy' # Element is a human readable text
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
data/tomograph.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'tomograph/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'tomograph'
|
7
|
+
spec.version = Tomograph::VERSION
|
8
|
+
spec.authors = ['d.efimov']
|
9
|
+
spec.email = ['d.efimov@fun-box.ru']
|
10
|
+
|
11
|
+
spec.summary = 'Parser API Blueprint specifications'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
15
|
+
spec.bindir = 'exe'
|
16
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
17
|
+
spec.require_paths = ['lib']
|
18
|
+
|
19
|
+
spec.add_runtime_dependency 'multi_json', '~> 1.11', '>= 1.11.1'
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
21
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
22
|
+
spec.add_development_dependency 'byebug', '~> 8.2', '>= 8.2.1'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.4', '>= 3.4.0'
|
24
|
+
spec.add_development_dependency 'simplecov', '~> 0.11', '>= 0.11.2'
|
25
|
+
spec.add_development_dependency 'rubocop', '~> 0.43', '>= 0.43.0'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tomograph
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- d.efimov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: multi_json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.11.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.11'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.11.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.12'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.12'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '10.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '10.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: byebug
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '8.2'
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 8.2.1
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '8.2'
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 8.2.1
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rspec
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '3.4'
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 3.4.0
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '3.4'
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 3.4.0
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
name: simplecov
|
103
|
+
requirement: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - "~>"
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0.11'
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.11.2
|
111
|
+
type: :development
|
112
|
+
prerelease: false
|
113
|
+
version_requirements: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.11'
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: 0.11.2
|
121
|
+
- !ruby/object:Gem::Dependency
|
122
|
+
name: rubocop
|
123
|
+
requirement: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - "~>"
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0.43'
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 0.43.0
|
131
|
+
type: :development
|
132
|
+
prerelease: false
|
133
|
+
version_requirements: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0.43'
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: 0.43.0
|
141
|
+
description:
|
142
|
+
email:
|
143
|
+
- d.efimov@fun-box.ru
|
144
|
+
executables: []
|
145
|
+
extensions: []
|
146
|
+
extra_rdoc_files: []
|
147
|
+
files:
|
148
|
+
- ".gitignore"
|
149
|
+
- ".rubocop.yml"
|
150
|
+
- CODE_OF_CONDUCT.md
|
151
|
+
- Gemfile
|
152
|
+
- LICENSE.txt
|
153
|
+
- README.md
|
154
|
+
- Rakefile
|
155
|
+
- bin/console
|
156
|
+
- bin/setup
|
157
|
+
- lib/tomograph.rb
|
158
|
+
- lib/tomograph/configuration.rb
|
159
|
+
- lib/tomograph/tomogram.rb
|
160
|
+
- lib/tomograph/version.rb
|
161
|
+
- tomograph.gemspec
|
162
|
+
homepage:
|
163
|
+
licenses:
|
164
|
+
- MIT
|
165
|
+
metadata: {}
|
166
|
+
post_install_message:
|
167
|
+
rdoc_options: []
|
168
|
+
require_paths:
|
169
|
+
- lib
|
170
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
requirements: []
|
181
|
+
rubyforge_project:
|
182
|
+
rubygems_version: 2.5.1
|
183
|
+
signing_key:
|
184
|
+
specification_version: 4
|
185
|
+
summary: Parser API Blueprint specifications
|
186
|
+
test_files: []
|