Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
A bit more rubyish.
  • Loading branch information
botanicus committed Jul 6, 2012
1 parent a15244a commit 4841827
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 19 deletions.
2 changes: 0 additions & 2 deletions lib/apiary/cli.rb
Expand Up @@ -2,11 +2,9 @@
require "apiary/cmd"

class Apiary::CLI

def self.start(*args)
command = args.shift.strip rescue "help"
Apiary::Command.load
Apiary::Command.run(command, args)
end

end
1 change: 0 additions & 1 deletion lib/apiary/cmd.rb
Expand Up @@ -5,7 +5,6 @@
module Apiary
module Command
class CommandFailed < RuntimeError; end

def self.commands
@@commands ||= {}
end
Expand Down
6 changes: 2 additions & 4 deletions lib/apiary/commands/base.rb
@@ -1,9 +1,8 @@
class Apiary::Command::Base

attr_reader :args
attr_reader :options

def initialize(args=[], options={})
def initialize(args = [], options = {})
@args = args
@options = options
end
Expand All @@ -22,7 +21,7 @@ def self.method_added(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(":")
command = [self.namespace, resolved_method].compact.join(":")
# banner = extract_banner(help) || command

Apiary::Command.register_command(
Expand All @@ -37,5 +36,4 @@ def self.method_added(method)
# :options => extract_options(help)
)
end

end
19 changes: 8 additions & 11 deletions lib/apiary/commands/preview.rb
@@ -1,27 +1,24 @@
require "apiary/commands/base"

# Display preview of local blueprint file
#
class Apiary::Command::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" }

api_server = ENV['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

aFile = File.new("/tmp/apiarypreview.html", "w")
aFile.write(response)
aFile.close
file = File.new("/tmp/apiarypreview.html", "w")
file.write(response)
file.close

Launchy.open("file:///tmp/apiarypreview.html")
end

end
2 changes: 1 addition & 1 deletion lib/apiary/version.rb
@@ -1,3 +1,3 @@
module Apiary
VERSION = "0.0.1"
VERSION ||= "0.0.1"
end

0 comments on commit 4841827

Please sign in to comment.