apipie-postman 0.0.6 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/apipie-postman.rb +31 -31
  3. metadata +24 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d73708d74797840f39b2401d17db13df1aa9f5e73dcb6962fce892adb8c524f0
4
- data.tar.gz: 921dfe98ddca2fc897ae501964f5602311d0b5d2e74ef8130616343e5e36b2d1
3
+ metadata.gz: aeda7743bb6927b7777edb9342f3a275c86d77beec417611883399dcbf3e8d82
4
+ data.tar.gz: 1d66263d27c38a1bc6dae8f2cfd6172e8830e3a2e70e1f05afac8627429aa5b3
5
5
  SHA512:
6
- metadata.gz: 534c8dc950a2b12cc0839d7841113bb08615661f778b3e9649d9d0cd0c06ca79431b320409624994325f8b3e3ba57456a7a0cec912105639927e18319edbd999
7
- data.tar.gz: 4b18a5affa213f8343099e82ae62745bb06a05a23a8aed9a75ec3cac863109a4bea0f90cf394ba6c911a1527a85b3a78a483f706bcd9e7f45b5c9da8990ae822
6
+ metadata.gz: 437dbea53be02b6ebb000216890416c7296fba16817ef4b8d16028c3093e12327bcc86b9efc428c974daca6b16f280fad7df23e4991877377618c04f4118f0bb
7
+ data.tar.gz: a65329f239dd995255aceebe4d2aa8933fd3f684c676e1b062aee3cd33e514aa039e73baa841210c795e4c3b5cb09f683278be7d1223e75c838a32a248f62b68
@@ -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
@@ -39,26 +38,7 @@ module ApipiePostman
39
38
 
40
39
  docs_hashes.each do |doc_hash|
41
40
  doc_hash.each do |endpoint|
42
- req_body = if endpoint['request_data'].nil?
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
- }
41
+ endpoints_hashes << create_endpoint_hash(endpoint, endpoint['request_data'] || {})
62
42
  end
63
43
  end
64
44
 
@@ -72,22 +52,42 @@ module ApipiePostman
72
52
  item: endpoints_hashes
73
53
  }
74
54
  }.to_json
55
+
75
56
  headers = {
76
57
  'X-Api-Key': self.configuration.postman_api_key,
77
58
  'Content-Type': 'application/json'
78
59
  }
79
60
 
80
- Faraday.public_send(:post, 'https://api.getpostman.com/collections/', body, headers)
61
+ collection_uid = check_collection_uid_by_name(headers)
62
+
63
+ if collection_uid.nil?
64
+ Faraday.public_send(:post, 'https://api.getpostman.com/collections/', body, headers)
65
+ else
66
+ Faraday.public_send(:put, "https://api.getpostman.com/collections/#{collection_uid['uid']}", body, headers)
67
+ end
68
+ end
81
69
 
82
- # if Object.const_defined?('POSTMAN_COLLECTION_UID') && Object.const_defined?('POSTMAN_COLLECTION_ID')
83
- # Faraday.public_send(:put, "https://api.getpostman.com/collections/#{Object.const_get('POSTMAN_COLLECTION_UID')}", body, headers)
84
- # else
85
- # response = Faraday.public_send(:post, 'https://api.getpostman.com/collections/', body, headers)
70
+ def self.check_collection_uid_by_name(headers)
71
+ response = Faraday.public_send(:get, 'https://api.getpostman.com/collections/', {}, headers)
72
+ JSON.parse(response.body)['collections'].select do |col|
73
+ col['name'] == self.configuration.postman_collection_name
74
+ end.last
75
+ end
86
76
 
87
- # if response.status == 200
88
- # Object.const_set('POSTMAN_COLLECTION_UID', JSON.parse(response.body)['collection']['uid'])
89
- # Object.const_set('POSTMAN_COLLECTION_ID', JSON.parse(response.body)['collection']['id'])
90
- # end
91
- # end
77
+ def self.create_endpoint_hash(endpoint, req_body)
78
+ {
79
+ name: endpoint['title'] == 'Default' ? "#{endpoint['verb']} #{endpoint['path']}" : endpoint['title'],
80
+ request: {
81
+ url: "#{self.configuration.base_url}#{endpoint['path']}",
82
+ method: endpoint['verb'],
83
+ header: [],
84
+ body: {
85
+ mode: 'raw',
86
+ raw: req_body.to_json
87
+ },
88
+ description: endpoint['title']
89
+ },
90
+ response: []
91
+ }
92
92
  end
93
93
  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.6
4
+ version: 0.0.10
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-08-25 00:00:00.000000000 Z
11
+ date: 2021-10-14 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! More details on https://github.com/VictorMotogna/apipie-postman
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.4'
103
+ version: '2.5'
84
104
  required_rubygems_version: !ruby/object:Gem::Requirement
85
105
  requirements:
86
106
  - - ">="