apiaryio 0.0.1 → 0.0.2

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.
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+ module Apiary
3
+ module Command
4
+ # Display help
5
+ class Help
6
+
7
+ def self.execute(options)
8
+ banner
9
+ commands
10
+ end
11
+
12
+ def self.banner
13
+ puts "\nUsage: apiary command [options]"
14
+ puts "Try 'apiary help' for more information."
15
+ end
16
+
17
+ def self.commands
18
+ puts "\nCurrently available apiary commands are:\n\n"
19
+ puts "\tpreview Show API documentation in default browser"
20
+ puts "\tpreview --browser [chrome|safari|firefox] Show API documentation in specified browser"
21
+ puts "\tpreview --path [PATH] Specify path to blueprint file"
22
+ puts "\tpreview --api_host [HOST] Specify apiary host"
23
+ puts "\tpreview --server Start standalone web server on port 8080"
24
+ puts "\tpreview --server --port [PORT] Start standalone web server on specified port"
25
+ puts "\n"
26
+ puts "\thelp Show help"
27
+ puts "\n"
28
+ puts "\tversion Show version"
29
+ puts "\n"
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,103 @@
1
+ # encoding: utf-8
2
+ require 'rest_client'
3
+ require 'rack'
4
+ module Apiary
5
+ module Command
6
+ # Display preview of local blueprint file
7
+ class Preview
8
+
9
+ BROWSERS = {
10
+ :safari => "Safari",
11
+ :chrome => "Google Chrome",
12
+ :firefox => "Firefox"
13
+ }
14
+
15
+ attr_reader :options
16
+
17
+ def initialize(args)
18
+ @options = {}
19
+ @options[:apib_path] = "apiary.apib"
20
+ @options[:api_host] = "api.apiary.io"
21
+ @options[:headers] = {:accept => "text/html", :content_type => "text/plain"}
22
+ @options[:port] = 8080
23
+ @options.merge! args
24
+ end
25
+
26
+ def self.execute(args)
27
+ args[:server] ? new(args).server : new(args).show
28
+ end
29
+
30
+ def server
31
+ run_server
32
+ end
33
+
34
+ def show
35
+ generate_static(apib_path)
36
+ end
37
+
38
+ def validate_apib_file(apib_file)
39
+ unless File.exist?(apib_file)
40
+ abort "Apiary definition file hasn't been found: #{apib_file.inspect}"
41
+ end
42
+ end
43
+
44
+ def apib_path
45
+ @options[:apib_path] || "#{File.basename(Dir.pwd)}.apib"
46
+ end
47
+
48
+ def browser
49
+ BROWSERS[@options[:browser]] || nil
50
+ end
51
+
52
+ def api_host
53
+ @options[:api_host]
54
+ end
55
+
56
+ def port
57
+ @options[:port]
58
+ end
59
+
60
+ def rack_app(&block)
61
+ Rack::Builder.new do
62
+ run lambda { |env| [200, Hash.new, [block.call]] }
63
+ end
64
+ end
65
+
66
+ def run_server
67
+ app = self.rack_app do
68
+ self.query_apiary(api_host, apib_path)
69
+ end
70
+
71
+ Rack::Server.start(:Port => port, :app => app)
72
+ end
73
+
74
+ def preview_path(apib_path)
75
+ basename = File.basename(apib_path)
76
+ "/tmp/#{basename}-preview.html"
77
+ end
78
+
79
+ def query_apiary(host, apib_path)
80
+ url = "https://#{host}/blueprint/generate"
81
+ data = File.read(apib_path)
82
+ RestClient.post(url, data, @options[:headers])
83
+ end
84
+
85
+ # TODO: add linux and windows systems
86
+ def open_generated_page(path)
87
+ exec "open #{browser_options} #{path}"
88
+ end
89
+
90
+ def generate_static(apib_path)
91
+ File.open(preview_path(apib_path), "w") do |file|
92
+ file.write(query_apiary(api_host, apib_path))
93
+ open_generated_page(file.path)
94
+ end
95
+ end
96
+
97
+ private
98
+ def browser_options
99
+ "-a #{BROWSERS[@options[:browser].to_sym]}" if @options[:browser]
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+ module Apiary
3
+ module Command
4
+ # Run commands
5
+ class Runner
6
+
7
+ def self.run(cmd, options)
8
+ Apiary::Command.const_get(cmd.to_s.capitalize).send(:execute, options)
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+ module Apiary
3
+ module Command
4
+ # Display version
5
+ class Version
6
+
7
+ def self.execute(options)
8
+ puts Apiary::VERSION
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module Apiary
2
- VERSION = "0.0.1"
3
- end
2
+ VERSION = "0.0.2"
3
+ end
data/spec/cli_spec.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Apiary::CLI do
4
+
5
+ it 'pass the test' do
6
+ true.should be_true
7
+ end
8
+
9
+ end
@@ -0,0 +1,2 @@
1
+ require 'rspec'
2
+ require 'apiary'
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.0.1
4
+ version: 0.0.2
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: 2012-06-12 00:00:00.000000000 Z
12
+ date: 2012-08-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 1.6.1
21
+ version: 1.6.7
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,42 +26,108 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 1.6.1
29
+ version: 1.6.7
30
30
  - !ruby/object:Gem::Dependency
31
- name: launchy
31
+ name: rack
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - ! '>='
35
+ - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 0.3.2
37
+ version: 1.4.1
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ! '>='
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.4.1
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.11.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.11.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: yard
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 0.8.2.1
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
44
76
  - !ruby/object:Gem::Version
45
- version: 0.3.2
46
- description: Apiary.io API client
47
- email: team@apiary.io
77
+ version: 0.8.2.1
78
+ description: Apiary.io CLI
79
+ email:
80
+ - team@apiary.io
48
81
  executables:
49
82
  - apiary
50
83
  extensions: []
51
84
  extra_rdoc_files: []
52
85
  files:
86
+ - .gitignore
87
+ - .rspec
88
+ - Gemfile
89
+ - Gemfile.lock
90
+ - LICENSE
53
91
  - README.md
92
+ - Rakefile
93
+ - apiary.gemspec
54
94
  - bin/apiary
95
+ - doc/Apiary.html
96
+ - doc/Apiary/CLI.html
97
+ - doc/Apiary/Command.html
98
+ - doc/Apiary/Command/Help.html
99
+ - doc/Apiary/Command/Preview.html
100
+ - doc/Apiary/Command/Runner.html
101
+ - doc/Apiary/Command/Version.html
102
+ - doc/_index.html
103
+ - doc/class_list.html
104
+ - doc/css/common.css
105
+ - doc/css/full_list.css
106
+ - doc/css/style.css
107
+ - doc/file.README.html
108
+ - doc/file_list.html
109
+ - doc/frames.html
110
+ - doc/index.html
111
+ - doc/js/app.js
112
+ - doc/js/full_list.js
113
+ - doc/js/jquery.js
114
+ - doc/method_list.html
115
+ - doc/top-level-namespace.html
55
116
  - lib/apiary.rb
56
117
  - lib/apiary/cli.rb
57
- - lib/apiary/cmd.rb
58
- - lib/apiary/commands/base.rb
59
- - lib/apiary/commands/preview.rb
118
+ - lib/apiary/command/help.rb
119
+ - lib/apiary/command/preview.rb
120
+ - lib/apiary/command/runner.rb
121
+ - lib/apiary/command/version.rb
60
122
  - lib/apiary/version.rb
61
- homepage: http://apiary.io/
123
+ - spec/cli_spec.rb
124
+ - spec/spec_helper.rb
125
+ homepage: http://apiary.io
62
126
  licenses:
63
127
  - MIT
64
- post_install_message:
128
+ post_install_message: This gem is a client for http://apiary.io. Apiary is in closed
129
+ beta version now, you need an invitation. If you don't have one, visit http://apiary.us2.list-manage.com/subscribe?u=b89934a238dcec9533f4a834a&id=08f2bdde55
130
+ to get on the waiting list!
65
131
  rdoc_options: []
66
132
  require_paths:
67
133
  - lib
@@ -82,5 +148,8 @@ rubyforge_project:
82
148
  rubygems_version: 1.8.24
83
149
  signing_key:
84
150
  specification_version: 3
85
- summary: Apiary.io API client
86
- test_files: []
151
+ summary: Apiary.io CLI
152
+ test_files:
153
+ - spec/cli_spec.rb
154
+ - spec/spec_helper.rb
155
+ has_rdoc:
data/lib/apiary/cmd.rb DELETED
@@ -1,63 +0,0 @@
1
- # Base skeleton taken from Heroku base command,
2
- # https://github.com/heroku/heroku/blob/master/lib/heroku/command.rb
3
- # (c) Heroku and contributors
4
-
5
- module Apiary
6
- module Command
7
- class CommandFailed < RuntimeError; end
8
-
9
- def self.commands
10
- @@commands ||= {}
11
- end
12
-
13
- def self.command_aliases
14
- @@command_aliases ||= {}
15
- end
16
-
17
- def self.load
18
- Dir[File.join(File.dirname(__FILE__), "commands", "*.rb")].each do |file|
19
- require file
20
- end
21
- end
22
-
23
- def self.parse(cmd)
24
- commands[cmd] || commands[command_aliases[cmd]]
25
- end
26
-
27
- def self.prepare_run(cmd, args=[])
28
- command = parse(cmd)
29
-
30
- unless command
31
- if %w( -v --version ).include?(cmd)
32
- command = parse('version')
33
- else
34
- error([
35
- "`#{cmd}` is not an apiary command.",
36
- ].compact.join("\n"))
37
- end
38
- end
39
-
40
- # add args, opts
41
- [ command[:klass].new(), command[:method] ]
42
- end
43
-
44
- def self.register_command(command)
45
- commands[command[:command]] = command
46
- end
47
-
48
-
49
- def self.run(cmd, arguments=[])
50
- object, method = prepare_run(cmd, arguments.dup)
51
- object.send(method)
52
- rescue CommandFailed => e
53
- error e.message
54
- rescue OptionParser::ParseError
55
- commands[cmd] ? run("help", [cmd]) : run("help")
56
- end
57
-
58
- def self.error(message)
59
- $stderr.puts(message)
60
- exit(1)
61
- end
62
- end
63
- end
@@ -1,41 +0,0 @@
1
- class Apiary::Command::Base
2
-
3
- attr_reader :args
4
- attr_reader :options
5
-
6
- def initialize(args=[], options={})
7
- @args = args
8
- @options = options
9
- end
10
-
11
- def self.namespace
12
- self.to_s.split("::").last.downcase
13
- end
14
-
15
- attr_reader :args
16
- attr_reader :options
17
-
18
- def self.method_added(method)
19
- return if self == Apiary::Command::Base
20
- return if private_method_defined?(method)
21
- return if protected_method_defined?(method)
22
-
23
- # help = extract_help_from_caller(caller.first)
24
- resolved_method = (method.to_s == "index") ? nil : method.to_s
25
- command = [ self.namespace, resolved_method ].compact.join(":")
26
- # banner = extract_banner(help) || command
27
-
28
- Apiary::Command.register_command(
29
- :klass => self,
30
- :method => method,
31
- :namespace => self.namespace,
32
- :command => command
33
- # :banner => banner.strip,
34
- # :help => help.join("\n"),
35
- # :summary => extract_summary(help),
36
- # :description => extract_description(help),
37
- # :options => extract_options(help)
38
- )
39
- end
40
-
41
- end