apiaryio 0.2.0 → 0.2.1
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.
- data/.travis.yml +9 -3
 - data/README.md +1 -1
 - data/Rakefile +5 -0
 - data/apiary.gemspec +5 -2
 - data/circle.yml +3 -0
 - data/features/fixtures/apiary-invalid.apib +48 -0
 - data/lib/apiary.rb +1 -0
 - data/lib/apiary/cli.rb +2 -0
 - data/lib/apiary/command/preview.rb +26 -25
 - data/lib/apiary/command/publish.rb +20 -20
 - data/lib/apiary/common.rb +34 -0
 - data/lib/apiary/version.rb +1 -1
 - data/spec/common_spec.rb +33 -0
 - metadata +53 -10
 
    
        data/.travis.yml
    CHANGED
    
    | 
         @@ -1,15 +1,21 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            language: ruby
         
     | 
| 
       2 
2 
     | 
    
         
             
            rvm:
         
     | 
| 
       3 
     | 
    
         
            -
              - "1.9.2"
         
     | 
| 
       4 
3 
     | 
    
         
             
              - "1.9.3"
         
     | 
| 
       5 
4 
     | 
    
         
             
              - "2.0.0"
         
     | 
| 
       6 
     | 
    
         
            -
              - "2.1.0"
         
     | 
| 
       7 
5 
     | 
    
         
             
              - "2.1.1"
         
     | 
| 
       8 
6 
     | 
    
         
             
              - "jruby-19mode"  # JRuby in 1.9 mode
         
     | 
| 
       9 
7 
     | 
    
         
             
              - "rbx-2"
         
     | 
| 
       10 
8 
     | 
    
         | 
| 
      
 9 
     | 
    
         
            +
            matrix:
         
     | 
| 
      
 10 
     | 
    
         
            +
              allow_failures:
         
     | 
| 
      
 11 
     | 
    
         
            +
                - rvm: rbx-2
         
     | 
| 
      
 12 
     | 
    
         
            +
            cache: bundler
         
     | 
| 
      
 13 
     | 
    
         
            +
            before_install:
         
     | 
| 
      
 14 
     | 
    
         
            +
              - gem update bundler
         
     | 
| 
      
 15 
     | 
    
         
            +
            matrix:
         
     | 
| 
      
 16 
     | 
    
         
            +
              allow_failures:
         
     | 
| 
      
 17 
     | 
    
         
            +
                - rvm: rbx-2
         
     | 
| 
       11 
18 
     | 
    
         
             
            cache: bundler
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
19 
     | 
    
         
             
            notifications:
         
     | 
| 
       14 
20 
     | 
    
         
             
              email:
         
     | 
| 
       15 
21 
     | 
    
         
             
                recipients:
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -47,7 +47,7 @@ machine, either using static files or using a standalone web server... 
     | 
|
| 
       47 
47 
     | 
    
         
             
                  publish --api-name [API_NAME] \
         
     | 
| 
       48 
48 
     | 
    
         
             
                          --message [COMMIT_MESSAGE]          Publish with custom commit message
         
     | 
| 
       49 
49 
     | 
    
         
             
                  fetch   --api-name [API_NAME]               Fetch apiary.apib from API_NAME.apiary.io
         
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
      
 50 
     | 
    
         
            +
                          --output [FILE]                     Write apiary.apib into specified file
         
     | 
| 
       51 
51 
     | 
    
         
             
                  help                                        Show this help
         
     | 
| 
       52 
52 
     | 
    
         
             
                  version                                     Show version
         
     | 
| 
       53 
53 
     | 
    
         | 
    
        data/Rakefile
    CHANGED
    
    | 
         @@ -4,6 +4,11 @@ require "rspec/core/rake_task" 
     | 
|
| 
       4 
4 
     | 
    
         
             
            require 'yard'
         
     | 
| 
       5 
5 
     | 
    
         
             
            require 'cucumber'
         
     | 
| 
       6 
6 
     | 
    
         
             
            require 'cucumber/rake/task'
         
     | 
| 
      
 7 
     | 
    
         
            +
            begin
         
     | 
| 
      
 8 
     | 
    
         
            +
                  require 'bundler/gem_tasks'
         
     | 
| 
      
 9 
     | 
    
         
            +
            rescue LoadError
         
     | 
| 
      
 10 
     | 
    
         
            +
                  puts "Cannot load bundler/gem_tasks"
         
     | 
| 
      
 11 
     | 
    
         
            +
            end
         
     | 
| 
       7 
12 
     | 
    
         | 
| 
       8 
13 
     | 
    
         
             
            Cucumber::Rake::Task.new(:features) do |t|
         
     | 
| 
       9 
14 
     | 
    
         
             
              t.cucumber_opts = "features --format pretty"
         
     | 
    
        data/apiary.gemspec
    CHANGED
    
    | 
         @@ -18,8 +18,11 @@ Gem::Specification.new do |gem| 
     | 
|
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
              gem.add_dependency "rest-client", "~> 1.6.7"
         
     | 
| 
       20 
20 
     | 
    
         
             
              gem.add_dependency "rack", ">= 1.4.0", "< 1.6.0"
         
     | 
| 
       21 
     | 
    
         
            -
              gem.add_dependency "rake"
         
     | 
| 
       22 
     | 
    
         
            -
              gem.add_dependency "thor"
         
     | 
| 
      
 21 
     | 
    
         
            +
              gem.add_dependency "rake", "~> 10.3.2"
         
     | 
| 
      
 22 
     | 
    
         
            +
              gem.add_dependency "thor", "~> 0.19.1"
         
     | 
| 
      
 23 
     | 
    
         
            +
              gem.add_dependency "redsnow", "~> 0.2.0"
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
              gem.add_runtime_dependency "json", "~> 1.8.1"
         
     | 
| 
       23 
26 
     | 
    
         | 
| 
       24 
27 
     | 
    
         
             
              gem.add_development_dependency "rspec", "~> 3.1.0"
         
     | 
| 
       25 
28 
     | 
    
         
             
              gem.add_development_dependency "webmock"
         
     | 
    
        data/circle.yml
    CHANGED
    
    
| 
         @@ -0,0 +1,48 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            FORMAT: 1A
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            #    Apiary Client Test
         
     | 
| 
      
 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 
     | 
    
         
            +
            { "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
         
     | 
    
        data/lib/apiary.rb
    CHANGED
    
    
    
        data/lib/apiary/cli.rb
    CHANGED
    
    | 
         @@ -9,6 +9,8 @@ module Apiary 
     | 
|
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
                desc "fetch", "Fetch apiary.apib from API_NAME.apiary.io"
         
     | 
| 
       11 
11 
     | 
    
         
             
                method_option :api_name, :type => :string, :required => true, :default => ''
         
     | 
| 
      
 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"
         
     | 
| 
       12 
14 
     | 
    
         | 
| 
       13 
15 
     | 
    
         
             
                def fetch
         
     | 
| 
       14 
16 
     | 
    
         
             
                  cmd = Apiary::Command::Fetch.new options
         
     | 
| 
         @@ -4,6 +4,8 @@ require 'rack' 
     | 
|
| 
       4 
4 
     | 
    
         
             
            require 'ostruct'
         
     | 
| 
       5 
5 
     | 
    
         
             
            require 'json'
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
      
 7 
     | 
    
         
            +
            require "apiary/common"
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
       7 
9 
     | 
    
         
             
            module Apiary
         
     | 
| 
       8 
10 
     | 
    
         
             
              module Command
         
     | 
| 
       9 
11 
     | 
    
         
             
                # Display preview of local blueprint file
         
     | 
| 
         @@ -17,9 +19,7 @@ module Apiary 
     | 
|
| 
       17 
19 
     | 
    
         | 
| 
       18 
20 
     | 
    
         
             
                  attr_reader :options
         
     | 
| 
       19 
21 
     | 
    
         | 
| 
       20 
     | 
    
         
            -
                  # TODO: use OpenStruct to store @options
         
     | 
| 
       21 
22 
     | 
    
         
             
                  def initialize(opts)
         
     | 
| 
       22 
     | 
    
         
            -
                    puts opts
         
     | 
| 
       23 
23 
     | 
    
         
             
                    @options = OpenStruct.new(opts)
         
     | 
| 
       24 
24 
     | 
    
         
             
                    @options.path         ||= "apiary.apib"
         
     | 
| 
       25 
25 
     | 
    
         
             
                    @options.api_host     ||= "api.apiary.io"
         
     | 
| 
         @@ -46,9 +46,8 @@ module Apiary 
     | 
|
| 
       46 
46 
     | 
    
         
             
                  end
         
     | 
| 
       47 
47 
     | 
    
         | 
| 
       48 
48 
     | 
    
         
             
                  def validate_apib_file(apib_file)
         
     | 
| 
       49 
     | 
    
         
            -
                     
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
                    end
         
     | 
| 
      
 49 
     | 
    
         
            +
                    common = Apiary::Common.new
         
     | 
| 
      
 50 
     | 
    
         
            +
                    common.validate_apib_file(apib_file)
         
     | 
| 
       52 
51 
     | 
    
         
             
                  end
         
     | 
| 
       53 
52 
     | 
    
         | 
| 
       54 
53 
     | 
    
         
             
                  def path
         
     | 
| 
         @@ -80,25 +79,29 @@ module Apiary 
     | 
|
| 
       80 
79 
     | 
    
         | 
| 
       81 
80 
     | 
    
         
             
                  def query_apiary(host, path)
         
     | 
| 
       82 
81 
     | 
    
         
             
                    url  = "https://#{host}/blueprint/generate"
         
     | 
| 
       83 
     | 
    
         
            -
                     
     | 
| 
       84 
     | 
    
         
            -
                       
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
                       
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
                    RestClient.proxy = @options.proxy
         
     | 
| 
      
 82 
     | 
    
         
            +
                    if validate_apib_file(path)
         
     | 
| 
      
 83 
     | 
    
         
            +
                      begin
         
     | 
| 
      
 84 
     | 
    
         
            +
                        data = File.read(path)
         
     | 
| 
      
 85 
     | 
    
         
            +
                      rescue
         
     | 
| 
      
 86 
     | 
    
         
            +
                        abort "File #{path} not found."
         
     | 
| 
      
 87 
     | 
    
         
            +
                      end
         
     | 
| 
       90 
88 
     | 
    
         | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
                       
     | 
| 
       96 
     | 
    
         
            -
                         
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
      
 89 
     | 
    
         
            +
                      RestClient.proxy = @options.proxy
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
                      begin
         
     | 
| 
      
 92 
     | 
    
         
            +
                        RestClient.post(url, data, @options.headers)
         
     | 
| 
      
 93 
     | 
    
         
            +
                      rescue RestClient::BadRequest => e
         
     | 
| 
      
 94 
     | 
    
         
            +
                        err = JSON.parse e.response
         
     | 
| 
      
 95 
     | 
    
         
            +
                        if err.has_key? 'parserError'
         
     | 
| 
      
 96 
     | 
    
         
            +
                          abort "#{err['message']}: #{err['parserError']} (Line: #{err['line']}, Column: #{err['column']})"
         
     | 
| 
      
 97 
     | 
    
         
            +
                        else
         
     | 
| 
      
 98 
     | 
    
         
            +
                          abort "Apiary service responded with an error: #{err['message']}"
         
     | 
| 
      
 99 
     | 
    
         
            +
                        end
         
     | 
| 
      
 100 
     | 
    
         
            +
                      rescue RestClient::Exception => e
         
     | 
| 
      
 101 
     | 
    
         
            +
                        abort "Apiary service responded with an error: #{e.message}"
         
     | 
| 
       99 
102 
     | 
    
         
             
                      end
         
     | 
| 
       100 
     | 
    
         
            -
                     
     | 
| 
       101 
     | 
    
         
            -
                      abort "Apiary  
     | 
| 
      
 103 
     | 
    
         
            +
                    else
         
     | 
| 
      
 104 
     | 
    
         
            +
                      abort "Sorry, Apiary can't display invalid blueprint."
         
     | 
| 
       102 
105 
     | 
    
         
             
                    end
         
     | 
| 
       103 
106 
     | 
    
         
             
                  end
         
     | 
| 
       104 
107 
     | 
    
         | 
| 
         @@ -108,9 +111,7 @@ module Apiary 
     | 
|
| 
       108 
111 
     | 
    
         
             
                  end
         
     | 
| 
       109 
112 
     | 
    
         | 
| 
       110 
113 
     | 
    
         
             
                  def write_generated_path(path, outfile)
         
     | 
| 
       111 
     | 
    
         
            -
                    File. 
     | 
| 
       112 
     | 
    
         
            -
                      file.write(File.open(path, 'r').read)
         
     | 
| 
       113 
     | 
    
         
            -
                    end
         
     | 
| 
      
 114 
     | 
    
         
            +
                    File.write(outfile, File.read(path))
         
     | 
| 
       114 
115 
     | 
    
         
             
                  end
         
     | 
| 
       115 
116 
     | 
    
         | 
| 
       116 
117 
     | 
    
         
             
                  def generate_static(path)
         
     | 
| 
         @@ -3,6 +3,7 @@ require 'rest_client' 
     | 
|
| 
       3 
3 
     | 
    
         
             
            require 'rack'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require 'ostruct'
         
     | 
| 
       5 
5 
     | 
    
         
             
            require 'json'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require "apiary/common"
         
     | 
| 
       6 
7 
     | 
    
         | 
| 
       7 
8 
     | 
    
         
             
            module Apiary
         
     | 
| 
       8 
9 
     | 
    
         
             
              module Command
         
     | 
| 
         @@ -11,7 +12,6 @@ module Apiary 
     | 
|
| 
       11 
12 
     | 
    
         | 
| 
       12 
13 
     | 
    
         
             
                  attr_reader :options
         
     | 
| 
       13 
14 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
                  # TODO: use OpenStruct to store @options
         
     | 
| 
       15 
15 
     | 
    
         
             
                  def initialize(opts)
         
     | 
| 
       16 
16 
     | 
    
         
             
                    @options = OpenStruct.new(opts)
         
     | 
| 
       17 
17 
     | 
    
         
             
                    @options.path           ||= "apiary.apib"
         
     | 
| 
         @@ -46,9 +46,8 @@ module Apiary 
     | 
|
| 
       46 
46 
     | 
    
         
             
                  end
         
     | 
| 
       47 
47 
     | 
    
         | 
| 
       48 
48 
     | 
    
         
             
                  def validate_apib_file(apib_file)
         
     | 
| 
       49 
     | 
    
         
            -
                     
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
                    end
         
     | 
| 
      
 49 
     | 
    
         
            +
                    common = Apiary::Common.new
         
     | 
| 
      
 50 
     | 
    
         
            +
                    common.validate_apib_file(apib_file)
         
     | 
| 
       52 
51 
     | 
    
         
             
                  end
         
     | 
| 
       53 
52 
     | 
    
         | 
| 
       54 
53 
     | 
    
         
             
                  def path
         
     | 
| 
         @@ -57,24 +56,25 @@ module Apiary 
     | 
|
| 
       57 
56 
     | 
    
         | 
| 
       58 
57 
     | 
    
         
             
                  def query_apiary(host, path)
         
     | 
| 
       59 
58 
     | 
    
         
             
                    url  = "https://#{host}/blueprint/publish/#{@options.api_name}"
         
     | 
| 
       60 
     | 
    
         
            -
                    validate_apib_file path
         
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
      
 59 
     | 
    
         
            +
                    if validate_apib_file path
         
     | 
| 
      
 60 
     | 
    
         
            +
                      data = {
         
     | 
| 
      
 61 
     | 
    
         
            +
                        :code => File.read(path),
         
     | 
| 
      
 62 
     | 
    
         
            +
                        :messageToSave => @options.commit_message
         
     | 
| 
      
 63 
     | 
    
         
            +
                      }
         
     | 
| 
      
 64 
     | 
    
         
            +
                      RestClient.proxy = @options.proxy
         
     | 
| 
       66 
65 
     | 
    
         | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
      
 66 
     | 
    
         
            +
                      begin
         
     | 
| 
      
 67 
     | 
    
         
            +
                        RestClient.post url, data, @options.headers
         
     | 
| 
      
 68 
     | 
    
         
            +
                      rescue RestClient::BadRequest => e
         
     | 
| 
      
 69 
     | 
    
         
            +
                        err = JSON.parse e.response
         
     | 
| 
      
 70 
     | 
    
         
            +
                        if err.has_key? 'parserError'
         
     | 
| 
      
 71 
     | 
    
         
            +
                          abort "#{err['message']}: #{err['parserError']}"
         
     | 
| 
      
 72 
     | 
    
         
            +
                        else
         
     | 
| 
      
 73 
     | 
    
         
            +
                          abort "Apiary service responded with an error: #{err['message']}"
         
     | 
| 
      
 74 
     | 
    
         
            +
                        end
         
     | 
| 
      
 75 
     | 
    
         
            +
                      rescue RestClient::Exception => e
         
     | 
| 
      
 76 
     | 
    
         
            +
                        abort "Apiary service responded with an error: #{e.message}"
         
     | 
| 
       75 
77 
     | 
    
         
             
                      end
         
     | 
| 
       76 
     | 
    
         
            -
                    rescue RestClient::Exception => e
         
     | 
| 
       77 
     | 
    
         
            -
                      abort "Apiary service responded with an error: #{e.message}"
         
     | 
| 
       78 
78 
     | 
    
         
             
                    end
         
     | 
| 
       79 
79 
     | 
    
         
             
                  end
         
     | 
| 
       80 
80 
     | 
    
         | 
| 
         @@ -0,0 +1,34 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # encoding: utf-8
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'redsnow'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            module Apiary
         
     | 
| 
      
 5 
     | 
    
         
            +
                # Common function used in commands
         
     | 
| 
      
 6 
     | 
    
         
            +
                class Common
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                  attr_accessor :error_message
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                  def initialize()
         
     | 
| 
      
 11 
     | 
    
         
            +
                  end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                  def validate_blueprint(code)
         
     | 
| 
      
 14 
     | 
    
         
            +
                    result = RedSnow.parse(code)
         
     | 
| 
      
 15 
     | 
    
         
            +
                    if result.error[:code] == 0
         
     | 
| 
      
 16 
     | 
    
         
            +
                      @error_message = nil
         
     | 
| 
      
 17 
     | 
    
         
            +
                      return true
         
     | 
| 
      
 18 
     | 
    
         
            +
                    else
         
     | 
| 
      
 19 
     | 
    
         
            +
                      @error_message = result.error[:message]
         
     | 
| 
      
 20 
     | 
    
         
            +
                      puts "Blueprint validation error: #{@error_message}"
         
     | 
| 
      
 21 
     | 
    
         
            +
                      return false
         
     | 
| 
      
 22 
     | 
    
         
            +
                    end
         
     | 
| 
      
 23 
     | 
    
         
            +
                  end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                  def validate_apib_file(apib_file)
         
     | 
| 
      
 26 
     | 
    
         
            +
                    unless File.exist?(apib_file)
         
     | 
| 
      
 27 
     | 
    
         
            +
                      raise "Apiary definition file hasn't been found: #{apib_file.inspect}"
         
     | 
| 
      
 28 
     | 
    
         
            +
                    end
         
     | 
| 
      
 29 
     | 
    
         
            +
                    code = File.read(apib_file)
         
     | 
| 
      
 30 
     | 
    
         
            +
                    return validate_blueprint(code)
         
     | 
| 
      
 31 
     | 
    
         
            +
                  end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                end
         
     | 
| 
      
 34 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/apiary/version.rb
    CHANGED
    
    
    
        data/spec/common_spec.rb
    ADDED
    
    | 
         @@ -0,0 +1,33 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe Apiary::Common do
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
              describe 'Validate apib files' do
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                it 'test existing file' do
         
     | 
| 
      
 8 
     | 
    
         
            +
                  common = Apiary::Common.new
         
     | 
| 
      
 9 
     | 
    
         
            +
                  expect(common.validate_apib_file('features/fixtures/apiary.apib')).to be_truthy
         
     | 
| 
      
 10 
     | 
    
         
            +
                end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                it 'test non existing file' do
         
     | 
| 
      
 13 
     | 
    
         
            +
                  common = Apiary::Common.new
         
     | 
| 
      
 14 
     | 
    
         
            +
                  expect {common.validate_apib_file('features/fixtures/apiary.xxx')}.to raise_error(/file hasn't been found/)
         
     | 
| 
      
 15 
     | 
    
         
            +
                end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
              describe 'Validate blueprint' do
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                it 'test validate blueprint' do
         
     | 
| 
      
 22 
     | 
    
         
            +
                  common = Apiary::Common.new
         
     | 
| 
      
 23 
     | 
    
         
            +
                  expect(common.validate_blueprint('# API_NAME')).to be_truthy
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                it 'test invalidate blueprint' do
         
     | 
| 
      
 27 
     | 
    
         
            +
                  common = Apiary::Common.new
         
     | 
| 
      
 28 
     | 
    
         
            +
                  expect(common.validate_blueprint("\t# API_NAME\t\r\n## Group Name")).to be_falsey
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
              end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: apiaryio
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.2. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.1
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -9,7 +9,7 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2014- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2014-10-13 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: rest-client
         
     | 
| 
         @@ -54,33 +54,65 @@ dependencies: 
     | 
|
| 
       54 
54 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       55 
55 
     | 
    
         
             
                none: false
         
     | 
| 
       56 
56 
     | 
    
         
             
                requirements:
         
     | 
| 
       57 
     | 
    
         
            -
                - -  
     | 
| 
      
 57 
     | 
    
         
            +
                - - ~>
         
     | 
| 
       58 
58 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       59 
     | 
    
         
            -
                    version:  
     | 
| 
      
 59 
     | 
    
         
            +
                    version: 10.3.2
         
     | 
| 
       60 
60 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       61 
61 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       62 
62 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       63 
63 
     | 
    
         
             
                none: false
         
     | 
| 
       64 
64 
     | 
    
         
             
                requirements:
         
     | 
| 
       65 
     | 
    
         
            -
                - -  
     | 
| 
      
 65 
     | 
    
         
            +
                - - ~>
         
     | 
| 
       66 
66 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       67 
     | 
    
         
            -
                    version:  
     | 
| 
      
 67 
     | 
    
         
            +
                    version: 10.3.2
         
     | 
| 
       68 
68 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       69 
69 
     | 
    
         
             
              name: thor
         
     | 
| 
       70 
70 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       71 
71 
     | 
    
         
             
                none: false
         
     | 
| 
       72 
72 
     | 
    
         
             
                requirements:
         
     | 
| 
       73 
     | 
    
         
            -
                - -  
     | 
| 
      
 73 
     | 
    
         
            +
                - - ~>
         
     | 
| 
       74 
74 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       75 
     | 
    
         
            -
                    version:  
     | 
| 
      
 75 
     | 
    
         
            +
                    version: 0.19.1
         
     | 
| 
       76 
76 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       77 
77 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       78 
78 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       79 
79 
     | 
    
         
             
                none: false
         
     | 
| 
       80 
80 
     | 
    
         
             
                requirements:
         
     | 
| 
       81 
     | 
    
         
            -
                - -  
     | 
| 
      
 81 
     | 
    
         
            +
                - - ~>
         
     | 
| 
       82 
82 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       83 
     | 
    
         
            -
                    version:  
     | 
| 
      
 83 
     | 
    
         
            +
                    version: 0.19.1
         
     | 
| 
      
 84 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 85 
     | 
    
         
            +
              name: redsnow
         
     | 
| 
      
 86 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 87 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 88 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 89 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 90 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 91 
     | 
    
         
            +
                    version: 0.2.0
         
     | 
| 
      
 92 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 93 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 94 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 95 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 96 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 97 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 98 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 99 
     | 
    
         
            +
                    version: 0.2.0
         
     | 
| 
      
 100 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 101 
     | 
    
         
            +
              name: json
         
     | 
| 
      
 102 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 103 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 104 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 105 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 106 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 107 
     | 
    
         
            +
                    version: 1.8.1
         
     | 
| 
      
 108 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 109 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 110 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 111 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 112 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 113 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 114 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 115 
     | 
    
         
            +
                    version: 1.8.1
         
     | 
| 
       84 
116 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       85 
117 
     | 
    
         
             
              name: rspec
         
     | 
| 
       86 
118 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -180,6 +212,7 @@ files: 
     | 
|
| 
       180 
212 
     | 
    
         
             
            - bin/apiary
         
     | 
| 
       181 
213 
     | 
    
         
             
            - circle.yml
         
     | 
| 
       182 
214 
     | 
    
         
             
            - features/fetch.feature
         
     | 
| 
      
 215 
     | 
    
         
            +
            - features/fixtures/apiary-invalid.apib
         
     | 
| 
       183 
216 
     | 
    
         
             
            - features/fixtures/apiary.apib
         
     | 
| 
       184 
217 
     | 
    
         
             
            - features/preview.feature
         
     | 
| 
       185 
218 
     | 
    
         
             
            - features/publish.feature
         
     | 
| 
         @@ -192,9 +225,11 @@ files: 
     | 
|
| 
       192 
225 
     | 
    
         
             
            - lib/apiary/command/fetch.rb
         
     | 
| 
       193 
226 
     | 
    
         
             
            - lib/apiary/command/preview.rb
         
     | 
| 
       194 
227 
     | 
    
         
             
            - lib/apiary/command/publish.rb
         
     | 
| 
      
 228 
     | 
    
         
            +
            - lib/apiary/common.rb
         
     | 
| 
       195 
229 
     | 
    
         
             
            - lib/apiary/version.rb
         
     | 
| 
       196 
230 
     | 
    
         
             
            - spec/cli_spec.rb
         
     | 
| 
       197 
231 
     | 
    
         
             
            - spec/command/fetch_spec.rb
         
     | 
| 
      
 232 
     | 
    
         
            +
            - spec/common_spec.rb
         
     | 
| 
       198 
233 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
       199 
234 
     | 
    
         
             
            - spec/support/aruba.rb
         
     | 
| 
       200 
235 
     | 
    
         
             
            homepage: http://apiary.io
         
     | 
| 
         @@ -210,12 +245,18 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       210 
245 
     | 
    
         
             
              - - ! '>='
         
     | 
| 
       211 
246 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       212 
247 
     | 
    
         
             
                  version: '0'
         
     | 
| 
      
 248 
     | 
    
         
            +
                  segments:
         
     | 
| 
      
 249 
     | 
    
         
            +
                  - 0
         
     | 
| 
      
 250 
     | 
    
         
            +
                  hash: 1564942254574113745
         
     | 
| 
       213 
251 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       214 
252 
     | 
    
         
             
              none: false
         
     | 
| 
       215 
253 
     | 
    
         
             
              requirements:
         
     | 
| 
       216 
254 
     | 
    
         
             
              - - ! '>='
         
     | 
| 
       217 
255 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       218 
256 
     | 
    
         
             
                  version: '0'
         
     | 
| 
      
 257 
     | 
    
         
            +
                  segments:
         
     | 
| 
      
 258 
     | 
    
         
            +
                  - 0
         
     | 
| 
      
 259 
     | 
    
         
            +
                  hash: 1564942254574113745
         
     | 
| 
       219 
260 
     | 
    
         
             
            requirements: []
         
     | 
| 
       220 
261 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       221 
262 
     | 
    
         
             
            rubygems_version: 1.8.23
         
     | 
| 
         @@ -224,6 +265,7 @@ specification_version: 3 
     | 
|
| 
       224 
265 
     | 
    
         
             
            summary: Apiary.io CLI
         
     | 
| 
       225 
266 
     | 
    
         
             
            test_files:
         
     | 
| 
       226 
267 
     | 
    
         
             
            - features/fetch.feature
         
     | 
| 
      
 268 
     | 
    
         
            +
            - features/fixtures/apiary-invalid.apib
         
     | 
| 
       227 
269 
     | 
    
         
             
            - features/fixtures/apiary.apib
         
     | 
| 
       228 
270 
     | 
    
         
             
            - features/preview.feature
         
     | 
| 
       229 
271 
     | 
    
         
             
            - features/publish.feature
         
     | 
| 
         @@ -233,6 +275,7 @@ test_files: 
     | 
|
| 
       233 
275 
     | 
    
         
             
            - features/version.feature
         
     | 
| 
       234 
276 
     | 
    
         
             
            - spec/cli_spec.rb
         
     | 
| 
       235 
277 
     | 
    
         
             
            - spec/command/fetch_spec.rb
         
     | 
| 
      
 278 
     | 
    
         
            +
            - spec/common_spec.rb
         
     | 
| 
       236 
279 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
       237 
280 
     | 
    
         
             
            - spec/support/aruba.rb
         
     | 
| 
       238 
281 
     | 
    
         
             
            has_rdoc: 
         
     |