apiaryio 0.3.5 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.gitignore +3 -2
  2. data/.travis.yml +3 -11
  3. data/README.md +7 -10
  4. data/Rakefile +4 -29
  5. data/apiary.gemspec +15 -9
  6. data/appveyor.yml +20 -11
  7. data/bin/apiary +1 -2
  8. data/circle.yml +2 -2
  9. data/features/preview.feature +1 -1
  10. data/features/step_definitions/file_content_step.rb +3 -12
  11. data/features/support/env.rb +2 -4
  12. data/lib/apiary.rb +0 -2
  13. data/lib/apiary/agent.rb +13 -0
  14. data/lib/apiary/cli.rb +5 -7
  15. data/lib/apiary/command/fetch.rb +48 -60
  16. data/lib/apiary/command/preview.rb +27 -46
  17. data/lib/apiary/command/publish.rb +27 -38
  18. data/lib/apiary/file_templates/preview.erb +1 -1
  19. data/lib/apiary/helpers.rb +45 -0
  20. data/lib/apiary/version.rb +1 -1
  21. data/spec/{cli_spec.rb → apiary/cli_spec.rb} +0 -1
  22. data/spec/{command → apiary/command}/fetch_spec.rb +0 -0
  23. data/spec/{command → apiary/command}/preview_spec.rb +1 -1
  24. data/spec/{command → apiary/command}/publish_spec.rb +7 -4
  25. data/spec/apiary/helpers_spec.rb +67 -0
  26. data/spec/fixtures/api_blueprint_and_swagger/apiary.apib +5 -0
  27. data/spec/fixtures/api_blueprint_and_swagger/swagger.yaml +5 -0
  28. data/{features → spec}/fixtures/apiary-invalid.apib +0 -0
  29. data/{features → spec}/fixtures/apiary.apib +0 -0
  30. data/{features → spec}/fixtures/apiary_with_bom.apib +0 -0
  31. data/spec/fixtures/empty_folder/.gitkeep +0 -0
  32. data/spec/fixtures/only_api_blueprint/apiary.apib +5 -0
  33. data/spec/fixtures/only_swagger/swagger.yaml +5 -0
  34. data/spec/spec.opts +1 -0
  35. data/spec/spec_helper.rb +8 -4
  36. data/spec/support/aruba.rb +1 -11
  37. data/spec/support/webmock.rb +1 -0
  38. metadata +70 -53
  39. data/features/support/setup.rb +0 -5
  40. data/lib/apiary/common.rb +0 -29
  41. 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
- features/fixtures/test.html
37
+ # testing
38
+ spec/fixtures/test.html
@@ -12,14 +12,6 @@ matrix:
12
12
  cache: bundler
13
13
  before_install:
14
14
  - gem update bundler
15
- matrix:
16
- allow_failures:
17
- - rvm: rbx-2
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 apiary.apib from API_NAME.apiary.io
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 apiary.apib on docs.API_NAME.apiary.io
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 apiary.apib into specified file
80
+ [--output=FILE] # Write API Description Document into specified file
81
81
 
82
- Fetch apiary.apib from API_NAME.apiary.io
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 blueprint file
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 blueprint file
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 apiary.apib on docs.API_NAME.apiary.io
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
- desc "Run all specs"
19
- RSpec::Core::RakeTask.new(:spec) do |t|
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
- desc 'Default: Run all specs.'
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
- YARD::Rake::YardocTask.new
37
-
38
- desc "Validate the gemspec"
13
+ desc 'Validate the gemspec'
39
14
  task :gemspec do
40
15
  gemspec.validate
41
16
  end
@@ -1,31 +1,37 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/apiary/version', __FILE__)
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 "rspec", "~> 3.2.0"
27
- gem.add_development_dependency "webmock", "~> 1.20"
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", ">= 0.6.2", "< 0.7.0"
30
- gem.add_development_dependency "cucumber", "~> 1.3", '>= 1.3.19'
35
+ gem.add_development_dependency "aruba", "~> 0.14"
36
+ gem.add_development_dependency "cucumber", "~> 2.0"
31
37
  end
@@ -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
- - SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
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
- build_script:
11
- - bundle install
18
+
12
19
  test_script:
13
- - rake test
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: "193"
19
- - ruby_version: "200"
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
@@ -2,5 +2,4 @@
2
2
  $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..','lib')))
3
3
  require 'apiary'
4
4
 
5
- Apiary::CLI.new(ARGV)
6
-
5
+ Apiary::CLI.start
data/circle.yml CHANGED
@@ -3,5 +3,5 @@ dependencies:
3
3
  - gem update bundler
4
4
  test:
5
5
  override:
6
- - bundle exec rake test
7
- - bundle exec rake features
6
+ - bundle exec rspec spec
7
+ - bundle exec cucumber
@@ -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
- in_current_dir do
3
+ cd('../../spec/fixtures') do
4
4
  expected = File.read(filename)
5
5
  end
6
6
 
7
- assert_partial_output(expected, all_output)
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
- assert_partial_output(expected, actual)
9
+ expect(unescape_text(actual)).to include(unescape_text(expected))
19
10
  end
@@ -1,9 +1,7 @@
1
1
  require 'aruba/cucumber'
2
- require 'fileutils'
3
2
 
4
- Before do
5
- @dirs << "../../features/fixtures"
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|
@@ -1,7 +1,5 @@
1
- require 'rubygems'
2
1
  require 'apiary/version'
3
2
  require 'apiary/cli'
4
- require 'apiary/common'
5
3
 
6
4
  module Apiary
7
5
  end
@@ -0,0 +1,13 @@
1
+ module Apiary
2
+ USER_AGENT = "apiaryio-gem/#{Apiary::VERSION} (#{RUBY_PLATFORM}) ruby/#{RUBY_VERSION}"
3
+
4
+ module_function
5
+
6
+ def user_agent
7
+ @@user_agent ||= USER_AGENT
8
+ end
9
+
10
+ def user_agent=(agent)
11
+ @@user_agent = agent
12
+ end
13
+ end
@@ -7,10 +7,10 @@ require 'apiary/command/publish'
7
7
  module Apiary
8
8
  class CLI < Thor
9
9
 
10
- desc 'fetch', 'Fetch apiary.apib from API_NAME.apiary.io'
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 apiary.apib into specified file'
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 blueprint file', :default => 'apiary.apib'
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 apiary.apib on docs.API_NAME.apiary.io'
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 blueprint file', :default => 'apiary.apib'
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)
@@ -4,79 +4,67 @@ require 'rack'
4
4
  require 'ostruct'
5
5
  require 'json'
6
6
 
7
- module Apiary
8
- module Command
9
- # Retrieve blueprint from apiary
10
- class Fetch
11
- attr_reader :options
7
+ require 'apiary/agent'
12
8
 
13
- # TODO: use OpenStruct to store @options
14
- def initialize(opts)
15
- @options = OpenStruct.new(opts)
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
- def fetch_from_apiary
37
- unless @options.api_name
38
- abort "Please provide an api-name option (subdomain part from your http://docs.<api-name>.apiary.io/)"
39
- end
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
- unless @options.api_key
42
- abort "API key must be provided through environment variable APIARY_API_KEY. Please go to https://login.apiary.io/tokens to obtain it."
43
- end
27
+ def execute
28
+ response = fetch_from_apiary
29
+ if response.instance_of? String
30
+ puts response
31
+ end
32
+ end
44
33
 
45
- response = self.query_apiary(@options.api_host, @options.path)
46
- if @options.output
47
- write_generated_path(response["code"], @options.output)
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
- def path
54
- @options.path || "#{File.basename(Dir.pwd)}.apib"
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
- def query_apiary(host, path)
58
- url = "https://#{host}/blueprint/get/#{@options.api_name}"
59
- RestClient.proxy = @options.proxy
43
+ response = query_apiary
60
44
 
61
- begin
62
- response = RestClient.get url, @options.headers
63
- rescue RestClient::Exception => e
64
- abort "Apiary service responded with an error: #{e.message}"
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
- def write_generated_path(data, outfile)
70
- File.open(outfile, 'w') do |file|
71
- file.write(data)
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
- private
76
- def api_name
77
- "-a"
78
- end
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