apipie-postman 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
+ SHA256:
3
+ metadata.gz: c0ff1490a21b17d9a93a14f2e25fcfddd8aeba8a4429b5db88549022b139eebb
4
+ data.tar.gz: e060ddfedc948bd622f37873982ead394c1d5c7827712fa7cba9b82d7dae3c2c
5
+ SHA512:
6
+ metadata.gz: 818b249909c7dfa66ab40f15fe280880ea18c53533643116cd3e3b5a64b54e896b423bbeae4cfaac52effa09a6d2f39287a832b1cf0524041073dbe9ba78d48f
7
+ data.tar.gz: cad4965ef44b7ff690baf12515a9c3bec261d2fbb04def7f04a6b35f8d3c8f4c028998ae9b20b9d7a3a710989402b08830aae29796e0586f08fdb0863ee581f6
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ text = "desc 'Run apipie-postman'\n
4
+ task apipie_postman: :environment do
5
+ puts ApipiePostman.configuration
6
+ puts 'Eat more apples!'
7
+ end"
8
+
9
+ File.open('lib/tasks/apipie_postman.rake', 'a') { |f| f.write(text) }
@@ -0,0 +1,90 @@
1
+ require 'json'
2
+ require 'faraday'
3
+
4
+ module ApipiePostman
5
+ class << self
6
+ attr_accessor :configuration
7
+ end
8
+
9
+ def self.configure
10
+ self.configuration ||= Configuration.new
11
+ yield(configuration)
12
+ end
13
+
14
+ class Configuration
15
+ attr_accessor :postman_api_key,
16
+ :postman_collection_name,
17
+ :base_url
18
+
19
+ def initialize
20
+ @postman_api_key = ''
21
+ @postman_collection_name = ''
22
+ @base_url = ''
23
+ end
24
+ end
25
+
26
+ def self.generate_docs
27
+ puts("asdf #{self.configuration}")
28
+ file = File.read('doc/apipie_examples.json')
29
+ @docs = JSON.parse(file)
30
+ docs_hashes = []
31
+ endpoints_hashes = []
32
+
33
+ @docs.each_key do |key|
34
+ docs_hashes << @docs[key]
35
+ end
36
+
37
+ docs_hashes.each do |doc_hash|
38
+ doc_hash.each do |endpoint|
39
+ req_body = if endpoint['request_data'].nil?
40
+ {}
41
+ else
42
+ endpoint['request_data']
43
+ end
44
+
45
+ endpoints_hashes << {
46
+ name: endpoint['title'],
47
+ request: {
48
+ url: "#{self.configuration.base_url}#{endpoint['path']}",
49
+ method: endpoint['verb'],
50
+ header: [],
51
+ body: {
52
+ mode: 'raw',
53
+ raw: req_body.to_json
54
+ },
55
+ description: endpoint['title']
56
+ },
57
+ response: []
58
+ }
59
+ end
60
+ end
61
+
62
+ body = {
63
+ collection: {
64
+ info: {
65
+ name: self.configuration.postman_collection_name,
66
+ description: 'Test description',
67
+ schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json'
68
+ },
69
+ item: endpoints_hashes
70
+ }
71
+ }.to_json
72
+ headers = {
73
+ 'X-Api-Key': self.configuration.postman_api_key,
74
+ 'Content-Type': 'application/json'
75
+ }
76
+
77
+ Faraday.public_send(:post, 'https://api.getpostman.com/collections/', body, headers)
78
+
79
+ # if Object.const_defined?('POSTMAN_COLLECTION_UID') && Object.const_defined?('POSTMAN_COLLECTION_ID')
80
+ # Faraday.public_send(:put, "https://api.getpostman.com/collections/#{Object.const_get('POSTMAN_COLLECTION_UID')}", body, headers)
81
+ # else
82
+ # response = Faraday.public_send(:post, 'https://api.getpostman.com/collections/', body, headers)
83
+
84
+ # if response.status == 200
85
+ # Object.const_set('POSTMAN_COLLECTION_UID', JSON.parse(response.body)['collection']['uid'])
86
+ # Object.const_set('POSTMAN_COLLECTION_ID', JSON.parse(response.body)['collection']['id'])
87
+ # end
88
+ # end
89
+ end
90
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apipie-postman
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Victor Motogna
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-08-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.4.3
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.4'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.4.3
33
+ description: 'Generate Postman collection from apipie output. '
34
+ email: vmotogna@gmail.com
35
+ executables:
36
+ - apipie-postman
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - bin/apipie-postman
41
+ - lib/apipie-postman.rb
42
+ homepage: https://rubygems.org/gems/apipie-postman
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
+ rubygems_version: 3.0.3
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Generate Postman collection from apipie output.
65
+ test_files: []