swagger_hub_api_pusher 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/swagger_hub_api_pusher/pusher.rb +52 -9
- data/lib/swagger_hub_api_pusher/version.rb +1 -1
- data/lib/tasks/swagger.rake +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e18a807f363126d056e5866772a2dce3b3c07ff2
|
4
|
+
data.tar.gz: abe42036b6fa32a60c383b4b8725c982e76f869e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e0df65508e8210c213804fe3970553eb8a60b6de226672bf199f073e47cf56872333404a89ac64119c2f459124a2162a4f9f15e2661c625e528304e619ccc52
|
7
|
+
data.tar.gz: 362979324edb51ffcb62843e7c0bf072e303bb36dbf1eaf38a5ee3b4a28294c488d4e79fd4df6b73bfdc043cec7c724282dad5125f09802274bd106c34fc9637
|
@@ -1,33 +1,76 @@
|
|
1
1
|
require 'uri'
|
2
2
|
require 'net/https'
|
3
|
+
require 'json'
|
3
4
|
|
4
5
|
module SwaggerHubApiPusher
|
5
6
|
class Pusher
|
6
7
|
SUCCESS_STATUSES = [200, 201].freeze
|
7
8
|
BASE_URL = 'https://api.swaggerhub.com/apis'.freeze
|
9
|
+
VERSION_REGEX = /(\d+\.)?(\d+\.)?(\*|\d+)/
|
8
10
|
|
9
11
|
def execute
|
10
12
|
raise ArgumentError, config.errors_messages unless config.valid?
|
11
13
|
|
12
|
-
|
13
|
-
request = Net::HTTP::Post.new(uri)
|
14
|
-
request['Content-Type'] = 'application/json'
|
15
|
-
request['Authorization'] = config.api_key
|
16
|
-
request.body = File.read(config.swagger_file)
|
14
|
+
return if published_api_is_actual?
|
17
15
|
|
18
|
-
response =
|
19
|
-
http.request(request)
|
20
|
-
end
|
16
|
+
response = push_swagger_file
|
21
17
|
|
22
18
|
unless SUCCESS_STATUSES.include?(response.code.to_i)
|
23
19
|
JSON.parse(response.body)['message']
|
24
20
|
end
|
25
21
|
end
|
26
22
|
|
27
|
-
private def
|
23
|
+
private def published_api_is_actual?
|
24
|
+
response = perform_request Net::HTTP::Get, get_api_url
|
25
|
+
return unless SUCCESS_STATUSES.include?(response.code.to_i)
|
26
|
+
|
27
|
+
apis = JSON.parse(response.body)['apis']
|
28
|
+
last_published_api = apis.reverse.find do |api|
|
29
|
+
api['properties'].find do |pr|
|
30
|
+
pr['type'] == 'X-Published' && pr['value'] == 'true'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
return unless last_published_api
|
34
|
+
|
35
|
+
last_published_version = last_published_api['properties'].find { |pr| pr['type'] == 'X-Version' }['value']
|
36
|
+
version(config.version) <= version(last_published_version)
|
37
|
+
end
|
38
|
+
|
39
|
+
private def version(version_str)
|
40
|
+
matched = VERSION_REGEX.match(version_str)
|
41
|
+
Gem::Version.new(matched ? matched[0] : nil)
|
42
|
+
end
|
43
|
+
|
44
|
+
private def push_swagger_file
|
45
|
+
perform_request Net::HTTP::Post, post_api_url, swagger_file
|
46
|
+
end
|
47
|
+
|
48
|
+
private def perform_request(request_class, url, body = nil)
|
49
|
+
uri = URI.parse(url)
|
50
|
+
|
51
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
52
|
+
http.use_ssl = true
|
53
|
+
|
54
|
+
request = request_class.new(uri.request_uri)
|
55
|
+
request['Content-Type'] = 'application/json'
|
56
|
+
request['Authorization'] = config.api_key
|
57
|
+
request.body = body unless body.nil?
|
58
|
+
|
59
|
+
http.request(request)
|
60
|
+
end
|
61
|
+
|
62
|
+
private def get_api_url
|
63
|
+
"#{BASE_URL}/#{config.owner}/#{config.api_name}"
|
64
|
+
end
|
65
|
+
|
66
|
+
private def post_api_url
|
28
67
|
"#{BASE_URL}/#{config.owner}/#{config.api_name}?version=#{config.version}"
|
29
68
|
end
|
30
69
|
|
70
|
+
private def swagger_file
|
71
|
+
@swagger_file ||= File.read(config.swagger_file)
|
72
|
+
end
|
73
|
+
|
31
74
|
private def config
|
32
75
|
@config ||= SwaggerHubApiPusher.config
|
33
76
|
end
|
data/lib/tasks/swagger.rake
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swagger_hub_api_pusher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Markov Alexey
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06
|
11
|
+
date: 2017-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|