apipie-postman 0.0.7 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/apipie-postman.rb +49 -39
- metadata +24 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb15fdaecb71ee97ad64d367620f122fc5ba847e682dfe5692c61b05d2fd8a98
|
4
|
+
data.tar.gz: 104174bf8f7dec3283fa1202e616c5d992d6496b8c6d99e3bb111e0293a0308f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6c6ddb7271df9f1ff84f4f939cc86c7cd1365fc71b8ec505d183841b2d6ca7be309ebf25e93c26cc4e843b09fb50c0102422459bc41e1869e46e7bc8d7e12d7
|
7
|
+
data.tar.gz: 6e31ad3dd6ccea47efb91c80fb566a84434ea173a06bcc397e3914555b2b4536497274da284924e8598a2b1b7a5c6e5cd49791747ab2b7b91ed50e25faaff925
|
data/lib/apipie-postman.rb
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
require 'json'
|
4
4
|
require 'faraday'
|
5
5
|
|
6
|
-
# General module for gem
|
7
6
|
module ApipiePostman
|
8
7
|
class << self
|
9
8
|
attr_accessor :configuration
|
@@ -30,36 +29,19 @@ module ApipiePostman
|
|
30
29
|
def self.generate_docs
|
31
30
|
file = File.read('doc/apipie_examples.json')
|
32
31
|
@docs = JSON.parse(file)
|
33
|
-
|
34
|
-
endpoints_hashes = []
|
32
|
+
folder_hashes = []
|
35
33
|
|
36
|
-
@docs.
|
37
|
-
|
38
|
-
|
34
|
+
@docs = @docs.each_with_object({}) do |array, result|
|
35
|
+
key = array[0].to_s.split('#')[0]
|
36
|
+
(result[key] ||= []).concat(array[1])
|
37
|
+
end.transform_values(&:flatten)
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
else
|
45
|
-
endpoint['request_data']
|
46
|
-
end
|
47
|
-
|
48
|
-
endpoints_hashes << {
|
49
|
-
name: endpoint['title'],
|
50
|
-
request: {
|
51
|
-
url: "#{self.configuration.base_url}#{endpoint['path']}",
|
52
|
-
method: endpoint['verb'],
|
53
|
-
header: [],
|
54
|
-
body: {
|
55
|
-
mode: 'raw',
|
56
|
-
raw: req_body.to_json
|
57
|
-
},
|
58
|
-
description: endpoint['title']
|
59
|
-
},
|
60
|
-
response: []
|
61
|
-
}
|
39
|
+
@docs.each_key do |key|
|
40
|
+
key_endpoint_hashes = []
|
41
|
+
@docs[key].each do |endpoint|
|
42
|
+
key_endpoint_hashes << create_endpoint_hash(endpoint, endpoint['request_data'] || {})
|
62
43
|
end
|
44
|
+
folder_hashes << create_folder(key, key_endpoint_hashes)
|
63
45
|
end
|
64
46
|
|
65
47
|
body = {
|
@@ -69,25 +51,53 @@ module ApipiePostman
|
|
69
51
|
description: 'Test description',
|
70
52
|
schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json'
|
71
53
|
},
|
72
|
-
item:
|
54
|
+
item: folder_hashes
|
73
55
|
}
|
74
56
|
}.to_json
|
57
|
+
|
75
58
|
headers = {
|
76
59
|
'X-Api-Key': self.configuration.postman_api_key,
|
77
60
|
'Content-Type': 'application/json'
|
78
61
|
}
|
79
62
|
|
80
|
-
|
63
|
+
collection_uid = check_collection_uid_by_name(headers)
|
64
|
+
|
65
|
+
if collection_uid.nil?
|
66
|
+
Faraday.public_send(:post, 'https://api.getpostman.com/collections/', body, headers)
|
67
|
+
else
|
68
|
+
Faraday.public_send(:put, "https://api.getpostman.com/collections/#{collection_uid['uid']}", body, headers)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.check_collection_uid_by_name(headers)
|
73
|
+
response = Faraday.public_send(:get, 'https://api.getpostman.com/collections/', {}, headers)
|
74
|
+
JSON.parse(response.body)['collections'].select do |col|
|
75
|
+
col['name'] == self.configuration.postman_collection_name
|
76
|
+
end.last
|
77
|
+
end
|
81
78
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
79
|
+
def self.create_endpoint_hash(endpoint, req_body)
|
80
|
+
{
|
81
|
+
name: endpoint['title'] == 'Default' ? "#{endpoint['verb']} #{endpoint['path']}" : endpoint['title'],
|
82
|
+
request: {
|
83
|
+
url: "#{self.configuration.base_url}#{endpoint['path']}",
|
84
|
+
method: endpoint['verb'],
|
85
|
+
header: [],
|
86
|
+
body: {
|
87
|
+
mode: 'raw',
|
88
|
+
raw: req_body.to_json
|
89
|
+
},
|
90
|
+
description: endpoint['title']
|
91
|
+
},
|
92
|
+
response: []
|
93
|
+
}
|
94
|
+
end
|
86
95
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
96
|
+
def self.create_folder(key, item_hashes)
|
97
|
+
{
|
98
|
+
name: key,
|
99
|
+
description: key,
|
100
|
+
item: item_hashes
|
101
|
+
}
|
92
102
|
end
|
93
103
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apipie-postman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Motogna
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -58,8 +58,28 @@ dependencies:
|
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '3.10'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rubocop
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.22'
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 1.22.1
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.22'
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 1.22.1
|
61
81
|
description: Use 'bundle exec apipie-postman' and 'rake apipie_postman' to generate
|
62
|
-
the docs!
|
82
|
+
the docs!
|
63
83
|
email: vmotogna@gmail.com
|
64
84
|
executables:
|
65
85
|
- apipie-postman
|
@@ -80,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
100
|
requirements:
|
81
101
|
- - "~>"
|
82
102
|
- !ruby/object:Gem::Version
|
83
|
-
version: '2.
|
103
|
+
version: '2.5'
|
84
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
105
|
requirements:
|
86
106
|
- - ">="
|