apiaryio 0.3.5 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -2
- data/.travis.yml +3 -11
- data/README.md +7 -10
- data/Rakefile +4 -29
- data/apiary.gemspec +15 -9
- data/appveyor.yml +20 -11
- data/bin/apiary +1 -2
- data/circle.yml +2 -2
- data/features/preview.feature +1 -1
- data/features/step_definitions/file_content_step.rb +3 -12
- data/features/support/env.rb +2 -4
- data/lib/apiary.rb +0 -2
- data/lib/apiary/agent.rb +13 -0
- data/lib/apiary/cli.rb +5 -7
- data/lib/apiary/command/fetch.rb +48 -60
- data/lib/apiary/command/preview.rb +27 -46
- data/lib/apiary/command/publish.rb +27 -38
- data/lib/apiary/file_templates/preview.erb +1 -1
- data/lib/apiary/helpers.rb +45 -0
- data/lib/apiary/version.rb +1 -1
- data/spec/{cli_spec.rb → apiary/cli_spec.rb} +0 -1
- data/spec/{command → apiary/command}/fetch_spec.rb +0 -0
- data/spec/{command → apiary/command}/preview_spec.rb +1 -1
- data/spec/{command → apiary/command}/publish_spec.rb +7 -4
- data/spec/apiary/helpers_spec.rb +67 -0
- data/spec/fixtures/api_blueprint_and_swagger/apiary.apib +5 -0
- data/spec/fixtures/api_blueprint_and_swagger/swagger.yaml +5 -0
- data/{features → spec}/fixtures/apiary-invalid.apib +0 -0
- data/{features → spec}/fixtures/apiary.apib +0 -0
- data/{features → spec}/fixtures/apiary_with_bom.apib +0 -0
- data/spec/fixtures/empty_folder/.gitkeep +0 -0
- data/spec/fixtures/only_api_blueprint/apiary.apib +5 -0
- data/spec/fixtures/only_swagger/swagger.yaml +5 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +8 -4
- data/spec/support/aruba.rb +1 -11
- data/spec/support/webmock.rb +1 -0
- metadata +70 -53
- data/features/support/setup.rb +0 -5
- data/lib/apiary/common.rb +0 -29
- data/spec/common_spec.rb +0 -29
data/.gitignore
CHANGED
@@ -8,6 +8,7 @@
|
|
8
8
|
/test/tmp/
|
9
9
|
/test/version_tmp/
|
10
10
|
/tmp/
|
11
|
+
/vendor
|
11
12
|
|
12
13
|
## Specific to RubyMotion:
|
13
14
|
.dat*
|
@@ -33,5 +34,5 @@ Gemfile.lock
|
|
33
34
|
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
35
|
.rvmrc
|
35
36
|
|
36
|
-
# testing
|
37
|
-
|
37
|
+
# testing
|
38
|
+
spec/fixtures/test.html
|
data/.travis.yml
CHANGED
@@ -12,14 +12,6 @@ matrix:
|
|
12
12
|
cache: bundler
|
13
13
|
before_install:
|
14
14
|
- gem update bundler
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
cache: bundler
|
19
|
-
notifications:
|
20
|
-
hipchat:
|
21
|
-
rooms:
|
22
|
-
secure: "HqBUrmf4P2bgvwb4b9PL1tBae2wcZaXadOgwRwAFhdhDZFHaKXIXlJRUW8tN\ntdO83OZgatxJrpWWQj8VYTfDuhlE3b3NxVWeXc3PkfrHmuvejQf4veh7kwR0\njLVE6jb+ZbFIwRE2W0VFLFKYQHI6PLem4W0OKXW5Shqzy8Ewlow="
|
23
|
-
template:
|
24
|
-
- '%{repository}#%{build_number} (%{branch} - %{commit} : %{author}): %{message} (<a href="%{build_url}">Details</a>/<a href="%{compare_url}">Change view</a>)'
|
25
|
-
format: html
|
15
|
+
script:
|
16
|
+
- bundle exec rspec spec
|
17
|
+
- bundle exec cucumber
|
data/README.md
CHANGED
@@ -57,10 +57,10 @@ export APIARY_API_KEY=<your_token>
|
|
57
57
|
```
|
58
58
|
$ apiary help
|
59
59
|
Commands:
|
60
|
-
apiary fetch --api-name=API_NAME # Fetch
|
60
|
+
apiary fetch --api-name=API_NAME # Fetch API Description Document from API_NAME.apiary.io
|
61
61
|
apiary help [COMMAND] # Describe available commands or one specific command
|
62
62
|
apiary preview # Show API documentation in default browser
|
63
|
-
apiary publish --api-name=API_NAME # Publish
|
63
|
+
apiary publish --api-name=API_NAME # Publish API Description Document on docs.API_NAME.apiary.io
|
64
64
|
apiary version # Show version
|
65
65
|
|
66
66
|
```
|
@@ -77,9 +77,9 @@ Usage:
|
|
77
77
|
Options:
|
78
78
|
--api-name=API_NAME
|
79
79
|
[--api-host=HOST] # Specify apiary host
|
80
|
-
[--output=FILE] # Write
|
80
|
+
[--output=FILE] # Write API Description Document into specified file
|
81
81
|
|
82
|
-
Fetch
|
82
|
+
Fetch API Description Document from API_NAME.apiary.io
|
83
83
|
```
|
84
84
|
|
85
85
|
#### preview
|
@@ -93,8 +93,7 @@ Options:
|
|
93
93
|
[--browser=chrome|safari|firefox] # Show API documentation in specified browser
|
94
94
|
# Possible values: chrome, safari, firefox
|
95
95
|
[--output=FILE] # Write generated HTML into specified file
|
96
|
-
[--path=PATH] # Specify path to
|
97
|
-
# Default: apiary.apib
|
96
|
+
[--path=PATH] # Specify path to API Description Document. When given a directory, it will look for apiary.apib or swagger.yaml file
|
98
97
|
[--api-host=HOST] # Specify apiary host
|
99
98
|
[--server], [--no-server] # Start standalone web server on port 8080
|
100
99
|
[--port=PORT] # Set port for --server option
|
@@ -112,12 +111,11 @@ Usage:
|
|
112
111
|
|
113
112
|
Options:
|
114
113
|
[--message=COMMIT_MESSAGE] # Publish with custom commit message
|
115
|
-
[--path=PATH] # Specify path to
|
116
|
-
# Default: apiary.apib
|
114
|
+
[--path=PATH] # Specify path to API Description Document. When given a directory, it will look for apiary.apib or swagger.yaml file
|
117
115
|
[--api-host=HOST] # Specify apiary host
|
118
116
|
--api-name=API_NAME
|
119
117
|
|
120
|
-
Publish
|
118
|
+
Publish API Description Document on docs.API_NAME.apiary.io
|
121
119
|
```
|
122
120
|
|
123
121
|
#### version
|
@@ -183,4 +181,3 @@ Copyright 2012-15 (c) Apiary Ltd.
|
|
183
181
|
|
184
182
|
Released under MIT license.
|
185
183
|
See [LICENSE](https://raw.githubusercontent.com/apiaryio/apiary-client/master/LICENSE) file for further details.
|
186
|
-
|
data/Rakefile
CHANGED
@@ -1,41 +1,16 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require "rubygems"
|
3
|
-
require "rspec/core/rake_task"
|
4
|
-
require 'yard'
|
5
|
-
require 'cucumber'
|
6
|
-
require 'cucumber/rake/task'
|
7
|
-
begin
|
8
|
-
require 'bundler/gem_tasks'
|
9
|
-
rescue LoadError
|
10
|
-
puts "Cannot load bundler/gem_tasks"
|
11
|
-
end
|
12
|
-
|
13
|
-
desc "Run all features"
|
14
|
-
Cucumber::Rake::Task.new(:features) do |t|
|
15
|
-
t.cucumber_opts = "features --format pretty"
|
16
|
-
end
|
17
2
|
|
18
|
-
|
19
|
-
|
20
|
-
t.fail_on_error = false
|
21
|
-
t.verbose = true
|
22
|
-
end
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
23
5
|
|
24
|
-
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
25
7
|
task :default => :spec
|
26
8
|
|
27
|
-
task :test => :spec
|
28
|
-
|
29
|
-
task :doc => :yard
|
30
|
-
task :gem => :gemspec
|
31
|
-
|
32
9
|
def gemspec
|
33
10
|
@gemspec ||= eval(File.read('apiary.gemspec'), binding, '.gemspec')
|
34
11
|
end
|
35
12
|
|
36
|
-
|
37
|
-
|
38
|
-
desc "Validate the gemspec"
|
13
|
+
desc 'Validate the gemspec'
|
39
14
|
task :gemspec do
|
40
15
|
gemspec.validate
|
41
16
|
end
|
data/apiary.gemspec
CHANGED
@@ -1,31 +1,37 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'apiary/version'
|
3
6
|
|
4
7
|
Gem::Specification.new do |gem|
|
8
|
+
gem.name = "apiaryio"
|
9
|
+
gem.version = Apiary::VERSION
|
5
10
|
gem.authors = ["Apiary Ltd."]
|
6
11
|
gem.email = ["team@apiary.io"]
|
12
|
+
|
7
13
|
gem.description = %q{Apiary.io CLI}
|
8
14
|
gem.summary = %q{Apiary.io CLI}
|
9
15
|
gem.homepage = "http://apiary.io"
|
10
16
|
gem.license = "MIT"
|
11
17
|
|
12
18
|
gem.files = `git ls-files`.split($\)
|
19
|
+
gem.bindir = "bin"
|
13
20
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
14
21
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
|
-
gem.name = "apiaryio"
|
16
22
|
gem.require_paths = ["lib"]
|
17
|
-
gem.version = Apiary::VERSION
|
18
23
|
|
19
24
|
gem.add_dependency "rest-client", "~> 1.8"
|
20
25
|
gem.add_dependency "rack", "~> 1.6.4"
|
21
|
-
gem.add_dependency "rake", "~> 10.4"
|
22
26
|
gem.add_dependency "thor", "~> 0.19.1"
|
23
27
|
|
24
28
|
gem.add_runtime_dependency "json", "~> 1.8"
|
25
29
|
|
26
|
-
gem.add_development_dependency "
|
27
|
-
gem.add_development_dependency "
|
30
|
+
gem.add_development_dependency "bundler", "~> 1.12"
|
31
|
+
gem.add_development_dependency "rake", "~> 10.0"
|
32
|
+
gem.add_development_dependency "rspec", "~> 3.4"
|
33
|
+
gem.add_development_dependency "webmock", "~> 2.0"
|
28
34
|
gem.add_development_dependency "yard", "~> 0.8"
|
29
|
-
gem.add_development_dependency "aruba", "
|
30
|
-
gem.add_development_dependency "cucumber", "~>
|
35
|
+
gem.add_development_dependency "aruba", "~> 0.14"
|
36
|
+
gem.add_development_dependency "cucumber", "~> 2.0"
|
31
37
|
end
|
data/appveyor.yml
CHANGED
@@ -1,22 +1,31 @@
|
|
1
1
|
---
|
2
|
-
version: "{build}"
|
2
|
+
version: "{branch}-{build}"
|
3
|
+
|
3
4
|
clone_depth: 10
|
5
|
+
|
6
|
+
build: off
|
7
|
+
|
4
8
|
install:
|
5
|
-
-
|
9
|
+
- set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH%
|
10
|
+
- gem update bundler
|
11
|
+
- bundle config --local path vendor/bundle
|
12
|
+
- bundle install
|
13
|
+
|
14
|
+
before_test:
|
6
15
|
- ruby --version
|
7
16
|
- gem --version
|
8
|
-
- gem install bundler --quiet --no-ri --no-rdoc
|
9
17
|
- bundler --version
|
10
|
-
|
11
|
-
- bundle install
|
18
|
+
|
12
19
|
test_script:
|
13
|
-
-
|
20
|
+
- bundle exec rspec spec
|
21
|
+
|
14
22
|
artifacts:
|
15
23
|
- path: pkg\*.gem
|
24
|
+
|
25
|
+
cache:
|
26
|
+
- vendor/bundle
|
27
|
+
|
16
28
|
environment:
|
17
29
|
matrix:
|
18
|
-
- ruby_version:
|
19
|
-
- ruby_version:
|
20
|
-
- ruby_version: "200-x64"
|
21
|
-
- ruby_version: "21"
|
22
|
-
- ruby_version: "21-x64"
|
30
|
+
- ruby_version: 193
|
31
|
+
- ruby_version: 22
|
data/bin/apiary
CHANGED
data/circle.yml
CHANGED
data/features/preview.feature
CHANGED
@@ -4,5 +4,5 @@ Feature: Show API documentation in specified browser
|
|
4
4
|
@needs_apiary_api_key
|
5
5
|
Scenario: Write generated HTML into specified file
|
6
6
|
|
7
|
-
When I run `apiary preview --path apiary.apib --output=test.html`
|
7
|
+
When I run `apiary preview --path ../../spec/fixtures/apiary.apib --output=test.html`
|
8
8
|
Then a file named "test.html" should exist
|
@@ -1,19 +1,10 @@
|
|
1
1
|
Then /^the output should contain the content of file "(.*)"$/ do |filename|
|
2
2
|
expected = nil
|
3
|
-
|
3
|
+
cd('../../spec/fixtures') do
|
4
4
|
expected = File.read(filename)
|
5
5
|
end
|
6
6
|
|
7
|
-
|
8
|
-
end
|
9
|
-
|
10
|
-
|
11
|
-
Then /^output file "(.*)" should contain the content of file "(.*)"$/ do |input, output|
|
12
|
-
expected = nil
|
13
|
-
in_current_dir do
|
14
|
-
actual = File.read(input)
|
15
|
-
expected = File.read(output)
|
16
|
-
end
|
7
|
+
actual = all_commands.map { |c| c.output }.join("\n")
|
17
8
|
|
18
|
-
|
9
|
+
expect(unescape_text(actual)).to include(unescape_text(expected))
|
19
10
|
end
|
data/features/support/env.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'aruba/cucumber'
|
2
|
-
require 'fileutils'
|
3
2
|
|
4
|
-
Before do
|
5
|
-
@
|
6
|
-
ENV['PATH'] = "./bin#{File::PATH_SEPARATOR}#{ENV['PATH']}"
|
3
|
+
Before('@needs_apiary_api_key') do
|
4
|
+
@aruba_timeout_seconds = 45
|
7
5
|
end
|
8
6
|
|
9
7
|
Around('@needs_apiary_api_key') do |scenario, block|
|
data/lib/apiary.rb
CHANGED
data/lib/apiary/agent.rb
ADDED
data/lib/apiary/cli.rb
CHANGED
@@ -7,10 +7,10 @@ require 'apiary/command/publish'
|
|
7
7
|
module Apiary
|
8
8
|
class CLI < Thor
|
9
9
|
|
10
|
-
desc 'fetch', 'Fetch
|
10
|
+
desc 'fetch', 'Fetch API Description Document from API_NAME.apiary.io'
|
11
11
|
method_option :api_name, :type => :string, :required => true, :default => ''
|
12
12
|
method_option :api_host, :type => :string, :banner => 'HOST', :desc => 'Specify apiary host'
|
13
|
-
method_option :output, :type => :string, :banner => 'FILE', :desc => 'Write
|
13
|
+
method_option :output, :type => :string, :banner => 'FILE', :desc => 'Write API Description Document into specified file'
|
14
14
|
|
15
15
|
def fetch
|
16
16
|
cmd = Apiary::Command::Fetch.new options
|
@@ -20,7 +20,7 @@ module Apiary
|
|
20
20
|
desc 'preview', 'Show API documentation in default browser'
|
21
21
|
method_option :browser, :type => :string, :enum => %w(chrome safari firefox), :banner => 'chrome|safari|firefox', :desc => 'Show API documentation in specified browser'
|
22
22
|
method_option :output, :type => :string, :banner => 'FILE', :desc => 'Write generated HTML into specified file'
|
23
|
-
method_option :path, :type => :string, :desc => 'Specify path to
|
23
|
+
method_option :path, :type => :string, :desc => 'Specify path to API Description Document. When given a directory, it will look for apiary.apib or swagger.yaml file'
|
24
24
|
method_option :api_host, :type => :string, :banner => 'HOST', :desc => 'Specify apiary host'
|
25
25
|
method_option :server, :type => :boolean, :desc => 'Start standalone web server on port 8080'
|
26
26
|
method_option :port, :type => :numeric, :banner => 'PORT', :desc => 'Set port for --server option'
|
@@ -31,9 +31,9 @@ module Apiary
|
|
31
31
|
cmd.execute
|
32
32
|
end
|
33
33
|
|
34
|
-
desc 'publish', 'Publish
|
34
|
+
desc 'publish', 'Publish API Description Document on docs.API_NAME.apiary.io'
|
35
35
|
method_option :message, :type => :string, :banner => 'COMMIT_MESSAGE', :desc => 'Publish with custom commit message'
|
36
|
-
method_option :path, :type => :string, :desc => 'Specify path to
|
36
|
+
method_option :path, :type => :string, :desc => 'Specify path to API Description Document. When given a directory, it will look for apiary.apib or swagger.yaml file'
|
37
37
|
method_option :api_host, :type => :string, :banner => 'HOST', :desc => 'Specify apiary host'
|
38
38
|
method_option :api_name, :type => :string, :required => true, :default => ''
|
39
39
|
|
@@ -50,5 +50,3 @@ module Apiary
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
53
|
-
|
54
|
-
Apiary::CLI.start(ARGV)
|
data/lib/apiary/command/fetch.rb
CHANGED
@@ -4,79 +4,67 @@ require 'rack'
|
|
4
4
|
require 'ostruct'
|
5
5
|
require 'json'
|
6
6
|
|
7
|
-
|
8
|
-
module Command
|
9
|
-
# Retrieve blueprint from apiary
|
10
|
-
class Fetch
|
11
|
-
attr_reader :options
|
7
|
+
require 'apiary/agent'
|
12
8
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
@options.path ||= "apiary.apib"
|
17
|
-
@options.api_host ||= "api.apiary.io"
|
18
|
-
@options.api_name ||= false
|
19
|
-
@options.api_key ||= ENV['APIARY_API_KEY']
|
20
|
-
@options.proxy ||= ENV['http_proxy']
|
21
|
-
@options.headers ||= {
|
22
|
-
:accept => "text/html",
|
23
|
-
:content_type => "text/plain",
|
24
|
-
:authentication => "Token #{@options.api_key}",
|
25
|
-
:user_agent => "Apiary Client Gem (https://help.apiary.io/tools/apiary-cli/)"
|
26
|
-
}
|
27
|
-
end
|
28
|
-
|
29
|
-
def execute()
|
30
|
-
response = fetch_from_apiary
|
31
|
-
if response.instance_of? String
|
32
|
-
puts response
|
33
|
-
end
|
34
|
-
end
|
9
|
+
module Apiary::Command
|
10
|
+
# Retrieve blueprint from apiary
|
11
|
+
class Fetch
|
35
12
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
13
|
+
def initialize(opts)
|
14
|
+
@options = OpenStruct.new(opts)
|
15
|
+
@options.api_host ||= 'api.apiary.io'
|
16
|
+
@options.api_name ||= false
|
17
|
+
@options.api_key ||= ENV['APIARY_API_KEY']
|
18
|
+
@options.proxy ||= ENV['http_proxy']
|
19
|
+
@options.headers ||= {
|
20
|
+
:accept => 'text/html',
|
21
|
+
:content_type => 'text/plain',
|
22
|
+
:authentication => "Token #{@options.api_key}",
|
23
|
+
:user_agent => Apiary.user_agent
|
24
|
+
}
|
25
|
+
end
|
40
26
|
|
41
|
-
|
42
|
-
|
43
|
-
|
27
|
+
def execute
|
28
|
+
response = fetch_from_apiary
|
29
|
+
if response.instance_of? String
|
30
|
+
puts response
|
31
|
+
end
|
32
|
+
end
|
44
33
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
else
|
49
|
-
response["code"]
|
50
|
-
end
|
34
|
+
def fetch_from_apiary
|
35
|
+
unless @options.api_name
|
36
|
+
abort 'Please provide an api-name option (subdomain part from your http://docs.<api-name>.apiary.io/)'
|
51
37
|
end
|
52
38
|
|
53
|
-
|
54
|
-
|
39
|
+
unless @options.api_key
|
40
|
+
abort 'API key must be provided through environment variable APIARY_API_KEY. Please go to https://login.apiary.io/tokens to obtain it.'
|
55
41
|
end
|
56
42
|
|
57
|
-
|
58
|
-
url = "https://#{host}/blueprint/get/#{@options.api_name}"
|
59
|
-
RestClient.proxy = @options.proxy
|
43
|
+
response = query_apiary
|
60
44
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
66
|
-
JSON.parse response.body
|
45
|
+
if @options.output
|
46
|
+
write_generated_path(response['code'], @options.output)
|
47
|
+
else
|
48
|
+
response['code']
|
67
49
|
end
|
50
|
+
end
|
68
51
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
73
|
-
end
|
52
|
+
def query_apiary
|
53
|
+
url = "https://#{@options.api_host}/blueprint/get/#{@options.api_name}"
|
54
|
+
RestClient.proxy = @options.proxy
|
74
55
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
56
|
+
begin
|
57
|
+
response = RestClient.get url, @options.headers
|
58
|
+
rescue RestClient::Exception => e
|
59
|
+
abort "Apiary service responded with an error: #{e.message}"
|
60
|
+
end
|
61
|
+
JSON.parse response.body
|
62
|
+
end
|
79
63
|
|
64
|
+
def write_generated_path(data, outfile)
|
65
|
+
File.open(outfile, 'w') do |file|
|
66
|
+
file.write(data)
|
67
|
+
end
|
80
68
|
end
|
81
69
|
end
|
82
70
|
end
|