apiaryio 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,14 @@
1
+ Apiary client
2
+ ===============
3
+
4
+ This will be CLI for Apiary API.
5
+
6
+ Please wait a while until it's useful.
7
+
8
+
9
+ Credits
10
+ ----------
11
+
12
+ Developed by Apiary Ltd.
13
+
14
+ Heavily inspired by Heroku CLI, (c) Heroku under MIT License.
data/bin/apiary ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ begin
5
+ require "pathname"
6
+ bin_file = Pathname.new(__FILE__).realpath
7
+
8
+ $:.unshift File.expand_path("../../lib", bin_file)
9
+
10
+ require "apiary/cli"
11
+ Apiary::CLI.start(*ARGV)
12
+ rescue Interrupt
13
+ puts("\n Cancelled.")
14
+ end
data/lib/apiary/cli.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "apiary"
2
+ require "apiary/cmd"
3
+
4
+ class Apiary::CLI
5
+
6
+ def self.start(*args)
7
+ command = args.shift.strip rescue "help"
8
+ Apiary::Command.load
9
+ Apiary::Command.run(command, args)
10
+ end
11
+
12
+ end
data/lib/apiary/cmd.rb ADDED
@@ -0,0 +1,63 @@
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
@@ -0,0 +1,41 @@
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
@@ -0,0 +1,27 @@
1
+ require "apiary/commands/base"
2
+
3
+ # Display preview of local blueprint file
4
+ #
5
+ class Apiary::Command::Preview < Apiary::Command::Base
6
+
7
+ # preview
8
+ #
9
+ # Launch web browser and display preview of local blueprint file
10
+ #
11
+ def index
12
+
13
+ api_server = ENV['APIARY_API_HOST'] || "api.apiary.io"
14
+ require 'launchy'
15
+ require 'rest_client'
16
+
17
+ headers = {:accept => "text/html",:content_type => "text/plain"}
18
+ response = RestClient.post "https://#{api_server}/blueprint/generate", IO.read('apiary.apib'), headers
19
+
20
+ aFile = File.new("/tmp/apiarypreview.html", "w")
21
+ aFile.write(response)
22
+ aFile.close
23
+
24
+ Launchy.open("file:///tmp/apiarypreview.html")
25
+ end
26
+
27
+ end
@@ -0,0 +1,3 @@
1
+ module Apiary
2
+ VERSION = "0.0.1"
3
+ end
data/lib/apiary.rb ADDED
@@ -0,0 +1,2 @@
1
+ module Apiary; end
2
+
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apiaryio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Apiary Ltd.
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.6.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.6.1
30
+ - !ruby/object:Gem::Dependency
31
+ name: launchy
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.3.2
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.3.2
46
+ description: Apiary.io API client
47
+ email: team@apiary.io
48
+ executables:
49
+ - apiary
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - README.md
54
+ - bin/apiary
55
+ - lib/apiary.rb
56
+ - lib/apiary/cli.rb
57
+ - lib/apiary/cmd.rb
58
+ - lib/apiary/commands/base.rb
59
+ - lib/apiary/commands/preview.rb
60
+ - lib/apiary/version.rb
61
+ homepage: http://apiary.io/
62
+ licenses:
63
+ - MIT
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.24
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Apiary.io API client
86
+ test_files: []