apiaryio 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/.gitignore +34 -12
  2. data/.travis.yml +1 -0
  3. data/Rakefile +8 -0
  4. data/apiary.gemspec +5 -2
  5. data/circle.yml +4 -0
  6. data/features/fetch.feature +7 -0
  7. data/features/fixtures/apiary.apib +48 -0
  8. data/features/preview.feature +7 -0
  9. data/features/publish.feature +7 -0
  10. data/features/step_definitions/file_content_step.rb +19 -0
  11. data/features/support/env.rb +7 -0
  12. data/features/support/setup.rb +1 -0
  13. data/features/version.feature +10 -0
  14. data/lib/apiary/cli.rb +37 -74
  15. data/lib/apiary/command/fetch.rb +2 -2
  16. data/lib/apiary/command/preview.rb +16 -5
  17. data/lib/apiary/command/publish.rb +3 -2
  18. data/lib/apiary/version.rb +1 -1
  19. data/spec/cli_spec.rb +1 -1
  20. data/spec/command/fetch_spec.rb +11 -9
  21. data/spec/spec_helper.rb +7 -0
  22. data/spec/support/aruba.rb +11 -0
  23. metadata +108 -52
  24. checksums.yaml +0 -7
  25. data/doc/Apiary.html +0 -131
  26. data/doc/Apiary/CLI.html +0 -528
  27. data/doc/Apiary/Command.html +0 -117
  28. data/doc/Apiary/Command/Fetch.html +0 -652
  29. data/doc/Apiary/Command/Help.html +0 -338
  30. data/doc/Apiary/Command/Preview.html +0 -1089
  31. data/doc/Apiary/Command/Publish.html +0 -658
  32. data/doc/Apiary/Command/Runner.html +0 -200
  33. data/doc/Apiary/Command/Version.html +0 -200
  34. data/doc/_index.html +0 -214
  35. data/doc/class_list.html +0 -54
  36. data/doc/css/common.css +0 -1
  37. data/doc/css/full_list.css +0 -57
  38. data/doc/css/style.css +0 -339
  39. data/doc/file.README.html +0 -169
  40. data/doc/file_list.html +0 -56
  41. data/doc/frames.html +0 -26
  42. data/doc/index.html +0 -169
  43. data/doc/js/app.js +0 -219
  44. data/doc/js/full_list.js +0 -178
  45. data/doc/js/jquery.js +0 -4
  46. data/doc/method_list.html +0 -281
  47. data/doc/top-level-namespace.html +0 -112
  48. data/lib/apiary/command/help.rb +0 -38
  49. data/lib/apiary/command/runner.rb +0 -13
  50. data/lib/apiary/command/version.rb +0 -13
data/.gitignore CHANGED
@@ -1,15 +1,37 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
1
29
  Gemfile.lock
2
- .bundle
30
+ .ruby-version
31
+ .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
3
34
  .rvmrc
4
- .tags
5
- .yardoc
6
- .rbenv-version
7
- *.gem
8
- /coverage
9
- /pkg
10
- /rdoc
11
- /vendor
12
- !/doc
13
- /.idea
14
- /nbproject/
15
35
 
36
+ # testing
37
+ features/fixtures/test.html
data/.travis.yml CHANGED
@@ -15,6 +15,7 @@ notifications:
15
15
  recipients:
16
16
  - lukas@apiary.io
17
17
  - adam@apiary.io
18
+ - ladislav@apiary.io
18
19
  on_success: change
19
20
  on_failure: always
20
21
  hipchat:
data/Rakefile CHANGED
@@ -2,6 +2,12 @@
2
2
  require "rubygems"
3
3
  require "rspec/core/rake_task"
4
4
  require 'yard'
5
+ require 'cucumber'
6
+ require 'cucumber/rake/task'
7
+
8
+ Cucumber::Rake::Task.new(:features) do |t|
9
+ t.cucumber_opts = "features --format pretty"
10
+ end
5
11
 
6
12
  desc "Run all specs"
7
13
  RSpec::Core::RakeTask.new(:spec) do |t|
@@ -11,6 +17,8 @@ end
11
17
  desc 'Default: Run all specs.'
12
18
  task :default => :spec
13
19
 
20
+ task :test => :spec
21
+
14
22
  task :doc => :yard
15
23
  task :gem => :gemspec
16
24
 
data/apiary.gemspec CHANGED
@@ -19,9 +19,12 @@ Gem::Specification.new do |gem|
19
19
  gem.add_dependency "rest-client", "~> 1.6.7"
20
20
  gem.add_dependency "rack", ">= 1.4.0", "< 1.6.0"
21
21
  gem.add_dependency "rake"
22
+ gem.add_dependency "thor"
22
23
 
23
- gem.add_development_dependency "rspec"
24
+ gem.add_development_dependency "rspec", "~> 3.1.0"
24
25
  gem.add_development_dependency "webmock"
25
- gem.add_development_dependency "yard"
26
+ gem.add_development_dependency "yard"
27
+ gem.add_development_dependency "aruba"
28
+ gem.add_development_dependency "cucumber"
26
29
 
27
30
  end
data/circle.yml ADDED
@@ -0,0 +1,4 @@
1
+ test:
2
+ override:
3
+ - bundle exec rake test
4
+ - bundle exec rake features
@@ -0,0 +1,7 @@
1
+ Feature: Fetch apiary.apib from API_NAME.apiary.io
2
+
3
+ # This is integration testing you have to set APIARY_API_KEY
4
+ Scenario: Fetch apiary.apib from API_NAME.apiary.io
5
+
6
+ When I run `apiary fetch --api-name apiaryclienttest`
7
+ Then the output should contain the content of file "apiary.apib"
@@ -0,0 +1,48 @@
1
+ FORMAT: 1A
2
+
3
+ # Apiary Client Test - DON'T CHANGE DOCUMENT!
4
+
5
+ This document is used for testing apiary-client
6
+
7
+ # Group Notes
8
+ Notes related resources of the **Notes API**
9
+
10
+ ## Notes Collection [/notes
11
+ ### List all Notes [GET]
12
+ + Response 200 (application/json)
13
+
14
+ [{
15
+ "id": 1, "title": "Jogging in park"
16
+ }, {
17
+ "id": 2, "title": "Pick-up posters from post-office"
18
+ }]
19
+
20
+ ### Create a Note [POST
21
+
22
+ + Request
23
+
24
+ sflmvs;mv;dsm{ "title": "Buy cheese and bread for breakfast." }
25
+
26
+ + Response 201 (application/json)
27
+
28
+ { "id": 3, "title": "Buy cheese and bread for breakfast." }
29
+
30
+ ## Note [/notes/{id}]
31
+ A single Note object with all its details
32
+
33
+ + Parameters
34
+ + id (required, number, `1`) ... Numeric `id` of the Note to perform action with. Has example value.
35
+
36
+ ### Retrieve a Note [GET]
37
+ + Response 200 (application/json)
38
+
39
+ + Header
40
+
41
+ X-My-Header: The Value
42
+
43
+ + Body
44
+
45
+ { "id": 2, "title": "Pick-up posters from post-office" }
46
+
47
+ ### Remove a Note [DELETE]
48
+ + Response 204
@@ -0,0 +1,7 @@
1
+ Feature: Show API documentation in specified browser
2
+
3
+ # This is integration testing you have to set APIARY_API_KEY
4
+ Scenario: Write generated HTML into specified file
5
+
6
+ When I run `apiary preview --path apiary.apib --output=test.html`
7
+ Then a file named "test.html" should exist
@@ -0,0 +1,7 @@
1
+ Feature: Publish apiary.apib on docs.API_NAME.apiary.io
2
+
3
+ # This is integration testing you have to set APIARY_API_KEY
4
+ Scenario: Publish apiary.apib on docs.API_NAME.apiary.io
5
+
6
+ When I run `apiary publish --path=apiary.apib --api-name 1111apiaryclienttest`
7
+ Then the exit status should be 1
@@ -0,0 +1,19 @@
1
+ Then /^the output should contain the content of file "(.*)"$/ do |filename|
2
+ expected = nil
3
+ in_current_dir do
4
+ expected = File.read(filename)
5
+ end
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
17
+
18
+ assert_partial_output(expected, actual)
19
+ end
@@ -0,0 +1,7 @@
1
+ require 'aruba/cucumber'
2
+ require 'fileutils'
3
+
4
+ Before do
5
+ @dirs << "../../features/fixtures"
6
+ ENV['PATH'] = "./bin#{File::PATH_SEPARATOR}#{ENV['PATH']}"
7
+ end
@@ -0,0 +1 @@
1
+ require 'aruba/cucumber'
@@ -0,0 +1,10 @@
1
+ Feature: Version of Apiary client
2
+
3
+ Scenario: Print the semantic version of Apiary client
4
+
5
+ # Note the output should be a semantic version (semver.org)
6
+ # The matching regex was taken from https://github.com/isaacs/node-semver/issues/32#issue-15023919
7
+
8
+ When I run `apiary version`
9
+ Then the output should match /^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/
10
+ And the exit status should be 0
data/lib/apiary/cli.rb CHANGED
@@ -1,88 +1,51 @@
1
1
  # encoding: utf-8
2
- require 'optparse'
2
+ require "thor"
3
+ require "apiary/command/fetch"
4
+ require "apiary/command/preview"
5
+ require "apiary/command/publish"
6
+
3
7
  module Apiary
4
- class CLI
8
+ class CLI < Thor
5
9
 
6
- attr_reader :command
10
+ desc "fetch", "Fetch apiary.apib from API_NAME.apiary.io"
11
+ method_option :api_name, :type => :string, :required => true, :default => ''
7
12
 
8
- def initialize(args)
9
- options = parse_options!(args)
10
- @command = options.delete(:command)
11
- run(options)
13
+ def fetch
14
+ cmd = Apiary::Command::Fetch.new options
15
+ cmd.execute
12
16
  end
13
17
 
14
- def run(options)
15
- Apiary::Command::Runner.run(@command, options)
18
+ desc "preview", "Show API documentation in default browser"
19
+ method_option :browser, :type => :string, :enum => %w(chrome safari firefox), :banner => "chrome|safari|firefox", :desc => "Show API documentation in specified browser"
20
+ method_option :output, :type => :string, :banner => "FILE", :desc => "Write generated HTML into specified file"
21
+ method_option :path, :type => :string, :desc => "Specify path to blueprint file", :default => 'apiary.apib'
22
+ method_option :api_host, :type => :string, :banner => "HOST", :desc => "Specify apiary host"
23
+ method_option :server, :type => :boolean, :desc => "Start standalone web server on port 8080"
24
+ method_option :port, :type => :numeric, :banner => "PORT", :desc => "Set port for --server option"
25
+
26
+ def preview
27
+ cmd = Apiary::Command::Preview.new options
28
+ cmd.execute
16
29
  end
17
30
 
18
- def parse_options!(args)
19
- options = {}
20
- command = nil
21
- if args.first && !args.first.start_with?("-")
22
- command = args.first
23
- end
24
-
25
- options_parser = OptionParser.new do |opts|
26
- opts.on("--path [PATH]") do |path|
27
- raise OptionParser::InvalidOption unless ["fetch", "preview", "publish"].include? command
28
- options[:path] = path
29
- end
30
-
31
- opts.on("--output [PATH]") do |path|
32
- raise OptionParser::InvalidOption unless ["fetch", "preview"].include? command
33
- options[:output] = path
34
- end
35
-
36
- opts.on("--api_host API_HOST") do |api_host|
37
- raise OptionParser::InvalidOption unless ["fetch", "preview", "publish"].include? command
38
- options[:api_host] = api_host
39
- end
40
-
41
- opts.on("--api-name API_HOST") do |api_name|
42
- raise OptionParser::InvalidOption unless ["fetch", "publish"].include? command
43
- options[:api_name] = api_name
44
- end
45
-
46
- opts.on("--message COMMIT_MESSAGE") do |commit_message|
47
- raise OptionParser::InvalidOption if command != "publish"
48
- options[:commit_message] = commit_message
49
- end
50
-
51
- opts.on("--browser BROWSER") do |browser|
52
- raise OptionParser::InvalidOption if command != "preview"
53
- options[:browser] = browser
54
- end
31
+ desc "publish", "Publish apiary.apib on docs.API_NAME.apiary.io"
32
+ method_option :message, :type => :string, :banner => "COMMIT_MESSAGE", :desc => "Publish with custom commit message"
33
+ method_option :path, :type => :string, :desc => "Specify path to blueprint file", :default => 'apiary.apib'
34
+ method_option :api_host, :type => :string, :banner => "HOST", :desc => "Specify apiary host"
35
+ method_option :api_name, :type => :string, :required => true, :default => ''
55
36
 
56
- opts.on("--server") do
57
- raise OptionParser::InvalidOption if command != "preview"
58
- options[:server] = true
59
- end
60
-
61
- opts.on("--port [PORT]") do |port|
62
- raise OptionParser::InvalidOption unless ["fetch", "preview", "publish"].include? command
63
- options[:port] = port
64
- end
65
-
66
- opts.on('-v', '--version') do
67
- raise OptionParser::InvalidOption if command
68
- command = :version
69
- end
70
-
71
- opts.on( '-h', '--help') do
72
- raise OptionParser::InvalidOption if command
73
- command = :help
74
- end
75
- end
37
+ def publish
38
+ cmd = Apiary::Command::Publish.new options
39
+ cmd.execute
40
+ end
76
41
 
77
- options_parser.parse!
78
- options[:command] = command || :help
79
- options
42
+ desc "version", "Show version"
43
+ method_option :aliases => "-v"
80
44
 
81
- rescue OptionParser::InvalidOption => e
82
- puts e
83
- puts Apiary::Command::Help.banner
84
- exit 1
45
+ def version
46
+ puts Apiary::VERSION
85
47
  end
86
-
87
48
  end
88
49
  end
50
+
51
+ Apiary::CLI.start(ARGV)
@@ -27,8 +27,8 @@ module Apiary
27
27
  }
28
28
  end
29
29
 
30
- def self.execute(args)
31
- response = new(args).fetch_from_apiary
30
+ def execute()
31
+ response = fetch_from_apiary
32
32
  if response.instance_of? String
33
33
  puts response
34
34
  end
@@ -19,16 +19,22 @@ module Apiary
19
19
 
20
20
  # TODO: use OpenStruct to store @options
21
21
  def initialize(opts)
22
+ puts opts
22
23
  @options = OpenStruct.new(opts)
23
24
  @options.path ||= "apiary.apib"
24
25
  @options.api_host ||= "api.apiary.io"
25
26
  @options.headers ||= {:accept => "text/html", :content_type => "text/plain"}
26
27
  @options.port ||= 8080
27
28
  @options.proxy ||= ENV['http_proxy']
29
+ @options.server ||= false
28
30
  end
29
31
 
30
- def self.execute(args)
31
- args[:server] ? new(args).server : new(args).show
32
+ def execute
33
+ if @options.server
34
+ server
35
+ else
36
+ show
37
+ end
32
38
  end
33
39
 
34
40
  def server
@@ -36,7 +42,7 @@ module Apiary
36
42
  end
37
43
 
38
44
  def show
39
- generate_static(path)
45
+ generate_static(@options.path)
40
46
  end
41
47
 
42
48
  def validate_apib_file(apib_file)
@@ -74,7 +80,12 @@ module Apiary
74
80
 
75
81
  def query_apiary(host, path)
76
82
  url = "https://#{host}/blueprint/generate"
77
- data = File.read(path)
83
+ begin
84
+ data = File.read(path)
85
+ rescue
86
+ abort "File #{path} not found."
87
+ end
88
+
78
89
  RestClient.proxy = @options.proxy
79
90
 
80
91
  begin
@@ -82,7 +93,7 @@ module Apiary
82
93
  rescue RestClient::BadRequest => e
83
94
  err = JSON.parse e.response
84
95
  if err.has_key? 'parserError'
85
- abort "#{err['message']}: #{err['parserError']}"
96
+ abort "#{err['message']}: #{err['parserError']} (Line: #{err['line']}, Column: #{err['column']})"
86
97
  else
87
98
  abort "Apiary service responded with an error: #{err['message']}"
88
99
  end
@@ -28,8 +28,8 @@ module Apiary
28
28
  @options.commit_message ||= "Saving blueprint from apiary-client"
29
29
  end
30
30
 
31
- def self.execute(args)
32
- new(args).publish_on_apiary
31
+ def execute()
32
+ publish_on_apiary
33
33
  end
34
34
 
35
35
  def publish_on_apiary
@@ -57,6 +57,7 @@ module Apiary
57
57
 
58
58
  def query_apiary(host, path)
59
59
  url = "https://#{host}/blueprint/publish/#{@options.api_name}"
60
+ validate_apib_file path
60
61
  data = {
61
62
  :code => File.read(path),
62
63
  :messageToSave => @options.commit_message
@@ -1,3 +1,3 @@
1
1
  module Apiary
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end