forked from apiaryio/apiary-client
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using this syntax is more fault-tolerant, easier to reuse without all…
… the dependencies. Not that big deal in this case but still.
- Loading branch information
botanicus
committed
Jul 6, 2012
1 parent
4841827
commit 5c05e76
Showing
5 changed files
with
63 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
module Apiary; end | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
require "apiary" | ||
require "apiary/cmd" | ||
|
||
class Apiary::CLI | ||
def self.start(*args) | ||
command = args.shift.strip rescue "help" | ||
Apiary::Command.load | ||
Apiary::Command.run(command, args) | ||
module Apiary | ||
class CLI | ||
def self.start(*args) | ||
command = args.shift.strip rescue "help" | ||
Apiary::Command.load | ||
Apiary::Command.run(command, args) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,43 @@ | ||
class Apiary::Command::Base | ||
attr_reader :args | ||
attr_reader :options | ||
module Apiary | ||
module Command | ||
class Base | ||
attr_reader :args | ||
attr_reader :options | ||
|
||
def initialize(args = [], options = {}) | ||
@args = args | ||
@options = options | ||
end | ||
def initialize(args = [], options = {}) | ||
@args = args | ||
@options = options | ||
end | ||
|
||
def self.namespace | ||
self.to_s.split("::").last.downcase | ||
end | ||
def self.namespace | ||
self.to_s.split("::").last.downcase | ||
end | ||
|
||
attr_reader :args | ||
attr_reader :options | ||
attr_reader :args | ||
attr_reader :options | ||
|
||
def self.method_added(method) | ||
return if self == Apiary::Command::Base | ||
return if private_method_defined?(method) | ||
return if protected_method_defined?(method) | ||
def self.method_added(method) | ||
return if self == Apiary::Command::Base | ||
return if private_method_defined?(method) | ||
return if protected_method_defined?(method) | ||
|
||
# help = extract_help_from_caller(caller.first) | ||
resolved_method = (method.to_s == "index") ? nil : method.to_s | ||
command = [self.namespace, resolved_method].compact.join(":") | ||
# banner = extract_banner(help) || command | ||
# help = extract_help_from_caller(caller.first) | ||
resolved_method = (method.to_s == "index") ? nil : method.to_s | ||
command = [self.namespace, resolved_method].compact.join(":") | ||
# banner = extract_banner(help) || command | ||
|
||
Apiary::Command.register_command( | ||
:klass => self, | ||
:method => method, | ||
:namespace => self.namespace, | ||
:command => command | ||
# :banner => banner.strip, | ||
# :help => help.join("\n"), | ||
# :summary => extract_summary(help), | ||
# :description => extract_description(help), | ||
# :options => extract_options(help) | ||
) | ||
Apiary::Command.register_command( | ||
:klass => self, | ||
:method => method, | ||
:namespace => self.namespace, | ||
:command => command | ||
# :banner => banner.strip, | ||
# :help => help.join("\n"), | ||
# :summary => extract_summary(help), | ||
# :description => extract_description(help), | ||
# :options => extract_options(help) | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,27 @@ | ||
require "apiary/commands/base" | ||
|
||
# Display preview of local blueprint file | ||
class Apiary::Command::Preview < Apiary::Command::Base | ||
module Apiary | ||
module Command | ||
class Preview < Apiary::Command::Base | ||
# Preview. | ||
# | ||
# Launch web browser and display preview of local blueprint file | ||
def index | ||
api_server = ENV.fetch("APIARY_API_HOST") { "api.apiary.io" } | ||
|
||
# preview | ||
# | ||
# Launch web browser and display preview of local blueprint file | ||
def index | ||
api_server = ENV.fetch("APIARY_API_HOST") { "api.apiary.io" } | ||
require "launchy" | ||
require "rest_client" | ||
|
||
require "launchy" | ||
require "rest_client" | ||
headers = {:accept => "text/html", :content_type => "text/plain"} | ||
response = RestClient.post "https://#{api_server}/blueprint/generate", IO.read("apiary.apib"), headers | ||
|
||
headers = {:accept => "text/html", :content_type => "text/plain"} | ||
response = RestClient.post "https://#{api_server}/blueprint/generate", IO.read("apiary.apib"), headers | ||
file = File.new("/tmp/apiarypreview.html", "w") | ||
file.write(response) | ||
file.close | ||
|
||
file = File.new("/tmp/apiarypreview.html", "w") | ||
file.write(response) | ||
file.close | ||
|
||
Launchy.open("file:///tmp/apiarypreview.html") | ||
Launchy.open("file:///tmp/apiarypreview.html") | ||
end | ||
end | ||
end | ||
end |