apiaryio 0.0.9 → 0.1.0

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.
@@ -191,7 +191,7 @@
191
191
  </div>
192
192
 
193
193
  <div id="footer">
194
- Generated on Sat Jan 25 12:41:41 2014 by
194
+ Generated on Thu Apr 17 13:30:52 2014 by
195
195
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
196
196
  0.8.7.3 (ruby-2.1.0).
197
197
  </div>
@@ -191,7 +191,7 @@
191
191
  </div>
192
192
 
193
193
  <div id="footer">
194
- Generated on Sat Jan 25 12:41:41 2014 by
194
+ Generated on Thu Apr 17 13:30:52 2014 by
195
195
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
196
196
  0.8.7.3 (ruby-2.1.0).
197
197
  </div>
data/doc/_index.html CHANGED
@@ -205,7 +205,7 @@
205
205
  </div>
206
206
 
207
207
  <div id="footer">
208
- Generated on Sat Jan 25 12:41:41 2014 by
208
+ Generated on Thu Apr 17 13:30:51 2014 by
209
209
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
210
210
  0.8.7.3 (ruby-2.1.0).
211
211
  </div>
data/doc/file.README.html CHANGED
@@ -89,12 +89,13 @@ Currently available apiary commands are:
89
89
 
90
90
  preview Show API documentation in default browser
91
91
  preview --browser [chrome|safari|firefox] Show API documentation in specified browser
92
+ preview --output [FILE] Write generated HTML into specified file
92
93
  preview --path [PATH] Specify path to blueprint file
93
94
  preview --api_host [HOST] Specify apiary host
94
95
  preview --server Start standalone web server on port 8080
95
96
  preview --server --port [PORT] Start standalone web server on specified port
96
- publish --api-name [API_NAME] Publish apiary.apib on docs.API_NAME.apiary.io&quot;
97
- fetch --api-name [API_NAME] Fetch apiary.apib from API_NAME.apiary.io&quot;
97
+ publish --api-name [API_NAME] Publish apiary.apib on docs.API_NAME.apiary.io
98
+ fetch --api-name [API_NAME] Fetch apiary.apib from API_NAME.apiary.io
98
99
 
99
100
  help Show help
100
101
 
@@ -125,7 +126,7 @@ Currently available apiary commands are:
125
126
  </div></div>
126
127
 
127
128
  <div id="footer">
128
- Generated on Sat Jan 25 12:41:41 2014 by
129
+ Generated on Thu Apr 17 13:30:51 2014 by
129
130
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
130
131
  0.8.7.3 (ruby-2.1.0).
131
132
  </div>
data/doc/index.html CHANGED
@@ -89,12 +89,13 @@ Currently available apiary commands are:
89
89
 
90
90
  preview Show API documentation in default browser
91
91
  preview --browser [chrome|safari|firefox] Show API documentation in specified browser
92
+ preview --output [FILE] Write generated HTML into specified file
92
93
  preview --path [PATH] Specify path to blueprint file
93
94
  preview --api_host [HOST] Specify apiary host
94
95
  preview --server Start standalone web server on port 8080
95
96
  preview --server --port [PORT] Start standalone web server on specified port
96
- publish --api-name [API_NAME] Publish apiary.apib on docs.API_NAME.apiary.io&quot;
97
- fetch --api-name [API_NAME] Fetch apiary.apib from API_NAME.apiary.io&quot;
97
+ publish --api-name [API_NAME] Publish apiary.apib on docs.API_NAME.apiary.io
98
+ fetch --api-name [API_NAME] Fetch apiary.apib from API_NAME.apiary.io
98
99
 
99
100
  help Show help
100
101
 
@@ -125,7 +126,7 @@ Currently available apiary commands are:
125
126
  </div></div>
126
127
 
127
128
  <div id="footer">
128
- Generated on Sat Jan 25 12:41:41 2014 by
129
+ Generated on Thu Apr 17 13:30:51 2014 by
129
130
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
130
131
  0.8.7.3 (ruby-2.1.0).
131
132
  </div>
data/doc/method_list.html CHANGED
@@ -72,14 +72,14 @@
72
72
 
73
73
 
74
74
  <li class="r1 ">
75
- <span class='object_link'><a href="Apiary/Command/Fetch.html#execute-class_method" title="Apiary::Command::Fetch.execute (method)">execute</a></span>
76
- <small>Apiary::Command::Fetch</small>
75
+ <span class='object_link'><a href="Apiary/Command/Help.html#execute-class_method" title="Apiary::Command::Help.execute (method)">execute</a></span>
76
+ <small>Apiary::Command::Help</small>
77
77
  </li>
78
78
 
79
79
 
80
80
  <li class="r2 ">
81
- <span class='object_link'><a href="Apiary/Command/Preview.html#execute-class_method" title="Apiary::Command::Preview.execute (method)">execute</a></span>
82
- <small>Apiary::Command::Preview</small>
81
+ <span class='object_link'><a href="Apiary/Command/Publish.html#execute-class_method" title="Apiary::Command::Publish.execute (method)">execute</a></span>
82
+ <small>Apiary::Command::Publish</small>
83
83
  </li>
84
84
 
85
85
 
@@ -90,14 +90,14 @@
90
90
 
91
91
 
92
92
  <li class="r2 ">
93
- <span class='object_link'><a href="Apiary/Command/Help.html#execute-class_method" title="Apiary::Command::Help.execute (method)">execute</a></span>
94
- <small>Apiary::Command::Help</small>
93
+ <span class='object_link'><a href="Apiary/Command/Preview.html#execute-class_method" title="Apiary::Command::Preview.execute (method)">execute</a></span>
94
+ <small>Apiary::Command::Preview</small>
95
95
  </li>
96
96
 
97
97
 
98
98
  <li class="r1 ">
99
- <span class='object_link'><a href="Apiary/Command/Publish.html#execute-class_method" title="Apiary::Command::Publish.execute (method)">execute</a></span>
100
- <small>Apiary::Command::Publish</small>
99
+ <span class='object_link'><a href="Apiary/Command/Fetch.html#execute-class_method" title="Apiary::Command::Fetch.execute (method)">execute</a></span>
100
+ <small>Apiary::Command::Fetch</small>
101
101
  </li>
102
102
 
103
103
 
@@ -114,14 +114,14 @@
114
114
 
115
115
 
116
116
  <li class="r2 ">
117
- <span class='object_link'><a href="Apiary/Command/Fetch.html#initialize-instance_method" title="Apiary::Command::Fetch#initialize (method)">#initialize</a></span>
118
- <small>Apiary::Command::Fetch</small>
117
+ <span class='object_link'><a href="Apiary/Command/Publish.html#initialize-instance_method" title="Apiary::Command::Publish#initialize (method)">#initialize</a></span>
118
+ <small>Apiary::Command::Publish</small>
119
119
  </li>
120
120
 
121
121
 
122
122
  <li class="r1 ">
123
- <span class='object_link'><a href="Apiary/Command/Publish.html#initialize-instance_method" title="Apiary::Command::Publish#initialize (method)">#initialize</a></span>
124
- <small>Apiary::Command::Publish</small>
123
+ <span class='object_link'><a href="Apiary/CLI.html#initialize-instance_method" title="Apiary::CLI#initialize (method)">#initialize</a></span>
124
+ <small>Apiary::CLI</small>
125
125
  </li>
126
126
 
127
127
 
@@ -132,8 +132,8 @@
132
132
 
133
133
 
134
134
  <li class="r1 ">
135
- <span class='object_link'><a href="Apiary/CLI.html#initialize-instance_method" title="Apiary::CLI#initialize (method)">#initialize</a></span>
136
- <small>Apiary::CLI</small>
135
+ <span class='object_link'><a href="Apiary/Command/Fetch.html#initialize-instance_method" title="Apiary::Command::Fetch#initialize (method)">#initialize</a></span>
136
+ <small>Apiary::Command::Fetch</small>
137
137
  </li>
138
138
 
139
139
 
@@ -144,20 +144,20 @@
144
144
 
145
145
 
146
146
  <li class="r1 ">
147
- <span class='object_link'><a href="Apiary/Command/Fetch.html#options-instance_method" title="Apiary::Command::Fetch#options (method)">#options</a></span>
148
- <small>Apiary::Command::Fetch</small>
147
+ <span class='object_link'><a href="Apiary/Command/Preview.html#options-instance_method" title="Apiary::Command::Preview#options (method)">#options</a></span>
148
+ <small>Apiary::Command::Preview</small>
149
149
  </li>
150
150
 
151
151
 
152
152
  <li class="r2 ">
153
- <span class='object_link'><a href="Apiary/Command/Preview.html#options-instance_method" title="Apiary::Command::Preview#options (method)">#options</a></span>
154
- <small>Apiary::Command::Preview</small>
153
+ <span class='object_link'><a href="Apiary/Command/Publish.html#options-instance_method" title="Apiary::Command::Publish#options (method)">#options</a></span>
154
+ <small>Apiary::Command::Publish</small>
155
155
  </li>
156
156
 
157
157
 
158
158
  <li class="r1 ">
159
- <span class='object_link'><a href="Apiary/Command/Publish.html#options-instance_method" title="Apiary::Command::Publish#options (method)">#options</a></span>
160
- <small>Apiary::Command::Publish</small>
159
+ <span class='object_link'><a href="Apiary/Command/Fetch.html#options-instance_method" title="Apiary::Command::Fetch#options (method)">#options</a></span>
160
+ <small>Apiary::Command::Fetch</small>
161
161
  </li>
162
162
 
163
163
 
@@ -269,6 +269,12 @@
269
269
  </li>
270
270
 
271
271
 
272
+ <li class="r2 ">
273
+ <span class='object_link'><a href="Apiary/Command/Fetch.html#write_generated_path-instance_method" title="Apiary::Command::Fetch#write_generated_path (method)">#write_generated_path</a></span>
274
+ <small>Apiary::Command::Fetch</small>
275
+ </li>
276
+
277
+
272
278
  </ul>
273
279
  </div>
274
280
  </body>
@@ -103,7 +103,7 @@
103
103
  </div>
104
104
 
105
105
  <div id="footer">
106
- Generated on Sat Jan 25 12:41:41 2014 by
106
+ Generated on Thu Apr 17 13:30:51 2014 by
107
107
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
108
108
  0.8.7.3 (ruby-2.1.0).
109
109
  </div>
data/lib/apiary/cli.rb CHANGED
@@ -7,57 +7,70 @@ module Apiary
7
7
 
8
8
  def initialize(args)
9
9
  options = parse_options!(args)
10
- run(args, options)
10
+ @command = options.delete(:command)
11
+ run(options)
11
12
  end
12
13
 
13
- def run(args, options)
14
- command = args.first || :help
15
- command = @command if @command
16
- Apiary::Command::Runner.run(command, options)
14
+ def run(options)
15
+ Apiary::Command::Runner.run(@command, options)
17
16
  end
18
17
 
19
18
  def parse_options!(args)
20
- @command = nil
21
19
  options = {}
20
+ command = nil
21
+ if args.first && !args.first.start_with?("-")
22
+ command = args.first
23
+ end
24
+
22
25
  options_parser = OptionParser.new do |opts|
23
26
  opts.on("--path [PATH]") do |path|
27
+ raise OptionParser::InvalidOption unless ["fetch", "preview", "publish"].include? command
24
28
  options[:path] = path
25
29
  end
26
30
 
27
31
  opts.on("--output [PATH]") do |path|
28
- options[:output] = path
32
+ raise OptionParser::InvalidOption unless ["fetch", "preview"].include? command
33
+ options[:output] = path
29
34
  end
30
35
 
31
36
  opts.on("--api_host API_HOST") do |api_host|
37
+ raise OptionParser::InvalidOption unless ["fetch", "preview", "publish"].include? command
32
38
  options[:api_host] = api_host
33
39
  end
34
40
 
35
41
  opts.on("--api-name API_HOST") do |api_name|
42
+ raise OptionParser::InvalidOption unless ["fetch", "publish"].include? command
36
43
  options[:api_name] = api_name
37
44
  end
38
45
 
39
46
  opts.on("--browser BROWSER") do |browser|
47
+ raise OptionParser::InvalidOption if command != "preview"
40
48
  options[:browser] = browser
41
49
  end
42
50
 
43
51
  opts.on("--server") do
52
+ raise OptionParser::InvalidOption if command != "preview"
44
53
  options[:server] = true
45
54
  end
46
55
 
47
56
  opts.on("--port [PORT]") do |port|
57
+ raise OptionParser::InvalidOption unless ["fetch", "preview", "publish"].include? command
48
58
  options[:port] = port
49
59
  end
50
60
 
51
61
  opts.on('-v', '--version') do
52
- @command = :version
62
+ raise OptionParser::InvalidOption if command
63
+ command = :version
53
64
  end
54
65
 
55
66
  opts.on( '-h', '--help') do
56
- @command = :help
67
+ raise OptionParser::InvalidOption if command
68
+ command = :help
57
69
  end
58
70
  end
59
71
 
60
72
  options_parser.parse!
73
+ options[:command] = command || :help
61
74
  options
62
75
 
63
76
  rescue OptionParser::InvalidOption => e
@@ -19,15 +19,16 @@ module Apiary
19
19
  @options.port ||= 8080
20
20
  @options.api_name ||= false
21
21
  @options.api_key ||= ENV['APIARY_API_KEY']
22
+ @options.proxy ||= ENV['http_proxy']
22
23
  @options.headers ||= {
23
24
  :accept => "text/html",
24
25
  :content_type => "text/plain",
25
26
  :authentication => "Token #{@options.api_key}"
26
- }
27
+ }
27
28
  end
28
29
 
29
30
  def self.execute(args)
30
- response = new(args).fetch_from_apiary
31
+ response = new(args).fetch_from_apiary
31
32
  if response.instance_of? String
32
33
  puts response
33
34
  end
@@ -56,10 +57,14 @@ module Apiary
56
57
 
57
58
  def query_apiary(host, path)
58
59
  url = "https://#{host}/blueprint/get/#{@options.api_name}"
59
- response = RestClient.get url, @options.headers
60
- unless (200..299).include? response.code
61
- abort "Request failed with code #{response.code}"
62
- end
60
+ RestClient.proxy = @options.proxy
61
+
62
+ begin
63
+ response = RestClient.get url, @options.headers
64
+ rescue RestClient::Exception => e
65
+ abort "Apiary service responded with an error: #{e.message}"
66
+ end
67
+
63
68
  JSON.parse response.body
64
69
  end
65
70
 
@@ -2,6 +2,7 @@
2
2
  require 'rest_client'
3
3
  require 'rack'
4
4
  require 'ostruct'
5
+ require 'json'
5
6
 
6
7
  module Apiary
7
8
  module Command
@@ -23,6 +24,7 @@ module Apiary
23
24
  @options.api_host ||= "api.apiary.io"
24
25
  @options.headers ||= {:accept => "text/html", :content_type => "text/plain"}
25
26
  @options.port ||= 8080
27
+ @options.proxy ||= ENV['http_proxy']
26
28
  end
27
29
 
28
30
  def self.execute(args)
@@ -73,7 +75,20 @@ module Apiary
73
75
  def query_apiary(host, path)
74
76
  url = "https://#{host}/blueprint/generate"
75
77
  data = File.read(path)
76
- RestClient.post(url, data, @options.headers)
78
+ RestClient.proxy = @options.proxy
79
+
80
+ begin
81
+ RestClient.post(url, data, @options.headers)
82
+ rescue RestClient::BadRequest => e
83
+ err = JSON.parse e.response
84
+ if err.has_key? 'parserError'
85
+ abort "#{err['message']}: #{err['parserError']}"
86
+ else
87
+ abort "Apiary service responded with an error: #{err['message']}"
88
+ end
89
+ rescue RestClient::Exception => e
90
+ abort "Apiary service responded with an error: #{e.message}"
91
+ end
77
92
  end
78
93
 
79
94
  # TODO: add linux and windows systems
@@ -2,6 +2,7 @@
2
2
  require 'rest_client'
3
3
  require 'rack'
4
4
  require 'ostruct'
5
+ require 'json'
5
6
 
6
7
  module Apiary
7
8
  module Command
@@ -18,6 +19,7 @@ module Apiary
18
19
  @options.port ||= 8080
19
20
  @options.api_name ||= false
20
21
  @options.api_key ||= ENV['APIARY_API_KEY']
22
+ @options.proxy ||= ENV['http_proxy']
21
23
  @options.headers ||= {
22
24
  :accept => "text/html",
23
25
  :content_type => "text/plain",
@@ -57,10 +59,19 @@ module Apiary
57
59
  data = {
58
60
  :code => File.read(path)
59
61
  }
60
- response = RestClient.post url, data, @options.headers
62
+ RestClient.proxy = @options.proxy
61
63
 
62
- unless (200..299).include? response.code
63
- abort "Request failed with code #{response.code}"
64
+ begin
65
+ RestClient.post url, data, @options.headers
66
+ rescue RestClient::BadRequest => e
67
+ err = JSON.parse e.response
68
+ if err.has_key? 'parserError'
69
+ abort "#{err['message']}: #{err['parserError']}"
70
+ else
71
+ abort "Apiary service responded with an error: #{err['message']}"
72
+ end
73
+ rescue RestClient::Exception => e
74
+ abort "Apiary service responded with an error: #{e.message}"
64
75
  end
65
76
  end
66
77
 
@@ -1,3 +1,3 @@
1
1
  module Apiary
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apiaryio
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 9
10
- version: 0.0.9
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Apiary Ltd.
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2014-01-27 00:00:00 Z
18
+ date: 2014-04-17 00:00:00 +00:00
19
+ default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: rest-client
@@ -167,6 +168,7 @@ files:
167
168
  - spec/cli_spec.rb
168
169
  - spec/command/fetch_spec.rb
169
170
  - spec/spec_helper.rb
171
+ has_rdoc: true
170
172
  homepage: http://apiary.io
171
173
  licenses:
172
174
  - MIT
@@ -196,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
198
  requirements: []
197
199
 
198
200
  rubyforge_project:
199
- rubygems_version: 1.8.15
201
+ rubygems_version: 1.6.2
200
202
  signing_key:
201
203
  specification_version: 3
202
204
  summary: Apiary.io CLI