swagger_hub_api_pusher 0.1.1 → 1.0.0
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/README.md +9 -1
- data/lib/generators/swagger_hub_api_pusher/install/USAGE +8 -0
- data/lib/generators/swagger_hub_api_pusher/install/install_generator.rb +11 -0
- data/lib/generators/swagger_hub_api_pusher/install/templates/swagger_hub_api_pusher.rb +9 -0
- data/lib/swagger_hub_api_pusher/configuration.rb +31 -0
- data/lib/swagger_hub_api_pusher/pusher.rb +36 -0
- data/lib/swagger_hub_api_pusher/version.rb +1 -1
- data/lib/swagger_hub_api_pusher.rb +8 -0
- data/lib/tasks/swagger.rake +5 -2
- data/swagger_hub_api_pusher.gemspec +4 -1
- metadata +36 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d70b3fa8846fe6c8f5567112fbacbd3167acbfc
|
4
|
+
data.tar.gz: 7fce8828fa2713b120579cd651ce08384a4b6ed8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 841384d1abd26acf0e0d87c8c5fc45b8b40c60a8fe8a56d31074b6aa8e6fac9485233514c681e389d3b314f1b59df333be48aaf3b320e8d1b0f3faf081c3d4b6
|
7
|
+
data.tar.gz: ab1ce26c81eff0cb36b8fdaa941eb7f0e907bb44d0a6741a991d164a630d1fa00af680f51f039ef353336e4220232dcd20f5229ec02ed2cfdeceb19f86750b4a
|
data/README.md
CHANGED
@@ -20,6 +20,14 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
+
Run the install generator:
|
24
|
+
|
25
|
+
$ rails generate swagger_hub_api_pusher:install
|
26
|
+
|
27
|
+
It will create `config/initializers/swagger_hub_api_pusher.rb` (add your settings from SwaggerHub API).
|
28
|
+
|
29
|
+
Run rake task for push you `swagger.json` to SwaggerHub:
|
30
|
+
|
23
31
|
$ rake swagger:push
|
24
32
|
|
25
33
|
|
@@ -31,7 +39,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
31
39
|
|
32
40
|
## Contributing
|
33
41
|
|
34
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
42
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/trickstersio/swagger_hub_api_pusher.
|
35
43
|
|
36
44
|
|
37
45
|
## License
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module SwaggerHubApiPusher
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
def add_initializer
|
8
|
+
template('swagger_hub_api_pusher.rb', 'config/initializers/swagger_hub_api_pusher.rb')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
SwaggerHubApiPusher.configure do |c|
|
2
|
+
# Specify owner, api_name, api_key, version and swagger_file from swaggerhub settings
|
3
|
+
# This is used by the SwaggerHubApiPusher to pushing swagger.json file
|
4
|
+
c.owner = 'owner'
|
5
|
+
c.api_name = 'api_name'
|
6
|
+
c.api_key = 'api_key'
|
7
|
+
c.version = 'version'
|
8
|
+
c.swagger_file = 'swagger/v1/swagger.json'
|
9
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module SwaggerHubApiPusher
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :owner, :api_name, :api_key, :version, :swagger_file
|
4
|
+
|
5
|
+
def valid?
|
6
|
+
[:owner, :api_name, :api_key, :version, :swagger_file].each do |param|
|
7
|
+
errors[param] = 'is blank' if is_blank?(public_send(param))
|
8
|
+
end
|
9
|
+
|
10
|
+
errors[:swagger_file] = 'not found' if !is_blank?(swagger_file) && file_not_found?
|
11
|
+
|
12
|
+
errors.empty?
|
13
|
+
end
|
14
|
+
|
15
|
+
def errors_messages
|
16
|
+
errors.map { |k, v| "#{k} #{v}" }.join(', ')
|
17
|
+
end
|
18
|
+
|
19
|
+
private def errors
|
20
|
+
@errors ||= {}
|
21
|
+
end
|
22
|
+
|
23
|
+
private def is_blank?(value)
|
24
|
+
!value || value.empty?
|
25
|
+
end
|
26
|
+
|
27
|
+
private def file_not_found?
|
28
|
+
!File.exists?(swagger_file)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module SwaggerHubApiPusher
|
4
|
+
class Pusher
|
5
|
+
def execute
|
6
|
+
raise ArgumentError, config.errors_messages unless config.valid?
|
7
|
+
|
8
|
+
response = Client.post(url,
|
9
|
+
body: File.read(config.swagger_file),
|
10
|
+
headers: {
|
11
|
+
'Content-Type' => 'application/json',
|
12
|
+
'Authorization' => config.api_key
|
13
|
+
}
|
14
|
+
)
|
15
|
+
|
16
|
+
if response.success?
|
17
|
+
puts 'swagger.json was successfully posted'
|
18
|
+
else
|
19
|
+
puts JSON.parse(response.body)['message']
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private def url
|
24
|
+
"/#{config.owner}/#{config.api_name}?version=#{config.version}"
|
25
|
+
end
|
26
|
+
|
27
|
+
private def config
|
28
|
+
@config ||= SwaggerHubApiPusher.config
|
29
|
+
end
|
30
|
+
|
31
|
+
class Client
|
32
|
+
include HTTParty
|
33
|
+
base_uri 'https://api.swaggerhub.com/apis'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,5 +1,13 @@
|
|
1
1
|
require "swagger_hub_api_pusher/version"
|
2
|
+
require "swagger_hub_api_pusher/configuration"
|
2
3
|
require "swagger_hub_api_pusher/railtie" if defined?(Rails)
|
3
4
|
|
4
5
|
module SwaggerHubApiPusher
|
6
|
+
def self.configure
|
7
|
+
yield(config)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.config
|
11
|
+
@config ||= Configuration.new
|
12
|
+
end
|
5
13
|
end
|
data/lib/tasks/swagger.rake
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
require 'swagger_hub_api_pusher/pusher'
|
2
|
+
require 'swagger_hub_api_pusher'
|
3
|
+
|
1
4
|
namespace :swagger do
|
2
5
|
desc 'Push swagger json to SwaggerHub API'
|
3
|
-
task :
|
4
|
-
|
6
|
+
task push: :environment do
|
7
|
+
SwaggerHubApiPusher::Pusher.new.execute
|
5
8
|
end
|
6
9
|
end
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
|
12
12
|
spec.summary = "Push swagger.json to SwaggerHub API"
|
13
13
|
spec.description = "Rake task for pushing swagger.json to SwaggerHub API"
|
14
|
-
spec.homepage = "https://github.com/
|
14
|
+
spec.homepage = "https://github.com/trickstersio/swagger_hub_api_pusher"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
@@ -21,7 +21,10 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
+
spec.add_runtime_dependency "httparty", "~> 0.15.5"
|
25
|
+
|
24
26
|
spec.add_development_dependency "bundler", "~> 1.14"
|
25
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
spec.add_development_dependency "pry", "~> 0.10.4"
|
27
30
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swagger_hub_api_pusher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
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-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.15.5
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.15.5
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +66,20 @@ dependencies:
|
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.10.4
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.10.4
|
55
83
|
description: Rake task for pushing swagger.json to SwaggerHub API
|
56
84
|
email:
|
57
85
|
- piton4eg@mail.ru
|
@@ -68,12 +96,17 @@ files:
|
|
68
96
|
- Rakefile
|
69
97
|
- bin/console
|
70
98
|
- bin/setup
|
99
|
+
- lib/generators/swagger_hub_api_pusher/install/USAGE
|
100
|
+
- lib/generators/swagger_hub_api_pusher/install/install_generator.rb
|
101
|
+
- lib/generators/swagger_hub_api_pusher/install/templates/swagger_hub_api_pusher.rb
|
71
102
|
- lib/swagger_hub_api_pusher.rb
|
103
|
+
- lib/swagger_hub_api_pusher/configuration.rb
|
104
|
+
- lib/swagger_hub_api_pusher/pusher.rb
|
72
105
|
- lib/swagger_hub_api_pusher/railtie.rb
|
73
106
|
- lib/swagger_hub_api_pusher/version.rb
|
74
107
|
- lib/tasks/swagger.rake
|
75
108
|
- swagger_hub_api_pusher.gemspec
|
76
|
-
homepage: https://github.com/
|
109
|
+
homepage: https://github.com/trickstersio/swagger_hub_api_pusher
|
77
110
|
licenses:
|
78
111
|
- MIT
|
79
112
|
metadata: {}
|