apical 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +24 -0
  4. data/Gemfile.lock +70 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.rdoc +94 -0
  7. data/Rakefile +55 -0
  8. data/VERSION +1 -0
  9. data/apical.gemspec +122 -0
  10. data/bin/apical +7 -0
  11. data/examples/taco_truck/Gemfile +7 -0
  12. data/examples/taco_truck/Gemfile.lock +50 -0
  13. data/examples/taco_truck/app.rb +13 -0
  14. data/examples/taco_truck/taco_truck.apical +18 -0
  15. data/lib/apical.rb +30 -0
  16. data/lib/apical/adapter.rb +21 -0
  17. data/lib/apical/adapters/http_adapter.rb +30 -0
  18. data/lib/apical/adapters/rack_adapter.rb +16 -0
  19. data/lib/apical/cli.rb +36 -0
  20. data/lib/apical/content_types.rb +62 -0
  21. data/lib/apical/resource.rb +138 -0
  22. data/lib/apical/resource_types.rb +36 -0
  23. data/lib/apical/runner.rb +104 -0
  24. data/lib/apical/writers/console_writer.rb +26 -0
  25. data/lib/apical/writers/html_writer.rb +37 -0
  26. data/spec/apical/adapters/http_adapter_spec.rb +24 -0
  27. data/spec/apical/cli_spec.rb +81 -0
  28. data/spec/apical/content_types_spec.rb +9 -0
  29. data/spec/apical/rack_adapter_spec.rb +12 -0
  30. data/spec/apical_spec.rb +360 -0
  31. data/spec/before_and_after_spec.rb +211 -0
  32. data/spec/fixtures/cli_example_1.rb +7 -0
  33. data/spec/fixtures/cli_example_2.rb +8 -0
  34. data/spec/fixtures/example_require.rb +3 -0
  35. data/spec/fixtures/load_paths_example.apical +1 -0
  36. data/spec/html_writer_spec.rb +117 -0
  37. data/spec/http_apical_spec.rb +23 -0
  38. data/spec/load_paths_spec.rb +12 -0
  39. data/spec/spec_helper.rb +19 -0
  40. data/spec/support/test_apps.rb +34 -0
  41. data/templates/apical_helper.rb +11 -0
  42. data/templates/layout.mustache +180 -0
  43. data/templates/resource.mustache +14 -0
  44. metadata +248 -0
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem 'thor'
7
+ gem 'mustache'
8
+ gem 'rack-test'
9
+ gem "httparty"
10
+ gem 'mustache'
11
+ gem 'kramdown'
12
+
13
+ # Add dependencies to develop your gem here.
14
+ # Include everything needed to run rake, tests, features, etc.
15
+ group :development do
16
+ gem "rspec", "~> 2.8.0"
17
+ gem "rdoc", "~> 3.12"
18
+ gem "bundler", ">= 1.0.0"
19
+ gem "jeweler", "~> 1.8.3"
20
+ gem "json"
21
+ gem "sinatra"
22
+ gem "webmock"
23
+ end
24
+ gem "pry"
@@ -0,0 +1,70 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.2.6)
5
+ coderay (1.0.6)
6
+ crack (0.3.1)
7
+ diff-lcs (1.1.3)
8
+ git (1.2.5)
9
+ httparty (0.8.1)
10
+ multi_json
11
+ multi_xml
12
+ jeweler (1.8.3)
13
+ bundler (~> 1.0)
14
+ git (>= 1.2.5)
15
+ rake
16
+ rdoc
17
+ json (1.7.3)
18
+ kramdown (0.13.5)
19
+ method_source (0.7.1)
20
+ multi_json (1.0.4)
21
+ multi_xml (0.4.1)
22
+ mustache (0.99.4)
23
+ pry (0.9.9.6)
24
+ coderay (~> 1.0.5)
25
+ method_source (~> 0.7.1)
26
+ slop (>= 2.4.4, < 3)
27
+ rack (1.4.0)
28
+ rack-protection (1.2.0)
29
+ rack
30
+ rack-test (0.6.1)
31
+ rack (>= 1.0)
32
+ rake (0.9.2.2)
33
+ rdoc (3.12)
34
+ json (~> 1.4)
35
+ rspec (2.8.0)
36
+ rspec-core (~> 2.8.0)
37
+ rspec-expectations (~> 2.8.0)
38
+ rspec-mocks (~> 2.8.0)
39
+ rspec-core (2.8.0)
40
+ rspec-expectations (2.8.0)
41
+ diff-lcs (~> 1.1.2)
42
+ rspec-mocks (2.8.0)
43
+ sinatra (1.3.2)
44
+ rack (~> 1.3, >= 1.3.6)
45
+ rack-protection (~> 1.2)
46
+ tilt (~> 1.3, >= 1.3.3)
47
+ slop (2.4.4)
48
+ thor (0.15.2)
49
+ tilt (1.3.3)
50
+ webmock (1.7.10)
51
+ addressable (~> 2.2, > 2.2.5)
52
+ crack (>= 0.1.7)
53
+
54
+ PLATFORMS
55
+ ruby
56
+
57
+ DEPENDENCIES
58
+ bundler (>= 1.0.0)
59
+ httparty
60
+ jeweler (~> 1.8.3)
61
+ json
62
+ kramdown
63
+ mustache
64
+ pry
65
+ rack-test
66
+ rdoc (~> 3.12)
67
+ rspec (~> 2.8.0)
68
+ sinatra
69
+ thor
70
+ webmock
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 T.J. VanSlyke
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,94 @@
1
+ = apical
2
+
3
+ Minimalist API documentation generator for Rack and HTTP applications.
4
+
5
+ == Motivation
6
+
7
+ After searching for similar API documentation solutions and coming up dry, I
8
+ stumbled upon http://apiary.io. While I appreciate the motivation for this
9
+ project, I really wanted an API documentation tool that is:
10
+
11
+ 1. Example based: Show me what a _real_ request looks like with _real_ data.
12
+ 2. Self-testing and replicable: Build API documentation as part of your CI build, and know it's up-to-date because it ran real requests against your application.
13
+ 3. Minimalist: `apical` is designed to make requests using the content type of your choice and display the request, response and a short description. Nothing more.
14
+
15
+
16
+ == Install
17
+
18
+ $ gem install apical
19
+
20
+ == Use
21
+
22
+ # my_apical.rb
23
+ require 'path/to/my/app'
24
+
25
+ # Use a Rack app
26
+ adapter :rack, app: TacoApp
27
+
28
+ # Or use a real HTTP server
29
+ adapter :http, base_uri: "http://mysite.com"
30
+
31
+ # Give your API document an optional name and description
32
+ name "The Great Taco API"
33
+ desc "Make em and eat em!"
34
+
35
+ # Declare a global accept type. This will be used to process the
36
+ # incoming request parameters before sending them to the server.
37
+ accept :json
38
+
39
+ # Declare a global content type. This will be used to parse the
40
+ # response from the server before displaying in your apical.
41
+ content_type :json
42
+
43
+ # Resources are specified by their request method
44
+ get '/tacos.json' do
45
+
46
+ # Each resource can be given an optional description
47
+ desc "Get all tacos owned by this user"
48
+ end
49
+
50
+ get '/tacos.xml' do
51
+
52
+ # Accept and content types can be overridden in individual resources.
53
+ accept :xml
54
+ content_type :xml
55
+
56
+ desc "Get all tacos as XML. Not sure why you'd want to do that, though."
57
+ end
58
+
59
+ post "/tacos.json" do
60
+ desc "Make a fresh, delicious new taco"
61
+
62
+ # You can also specify parameters to feed the resource.
63
+ # The resulting response will be printed to your apical.
64
+ params do
65
+ { meat: 'fish', sour_cream: true }
66
+ end
67
+ end
68
+
69
+
70
+ $ bundle exec apical compile my_apical.rb
71
+
72
+ For help with the apical command, run
73
+
74
+ $ apical help
75
+
76
+ See the examples folder for more examples.
77
+
78
+ For Rails apps, it's probably a good idea to set the env to 'test' before loading your app: ENV['RAILS_ENV']=test
79
+
80
+ == Contributing to apical
81
+
82
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
83
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
84
+ * Fork the project.
85
+ * Start a feature/bugfix branch.
86
+ * Commit and push until you are happy with your contribution.
87
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
88
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
89
+
90
+ == Copyright
91
+
92
+ Copyright (c) 2012 Turing. See LICENSE.txt for
93
+ further details.
94
+
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "apical"
18
+ gem.homepage = "http://github.com/turingstudio/apical"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Minimalist API documentation generator for Rack applications.}
21
+ gem.description = %Q{Minimalist API documentation generator for Rack applications.}
22
+ gem.email = "tj@turing.com"
23
+ gem.authors = ["T.J. VanSlyke"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "apical #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
50
+
51
+ task :examples do
52
+ `ruby examples/tacos_api.rb > examples/tacos_api.html`
53
+ `ruby examples/burritos_api.rb > examples/burritos_api.html`
54
+ end
55
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.4
@@ -0,0 +1,122 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "apical"
8
+ s.version = "0.1.4"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["T.J. VanSlyke"]
12
+ s.date = "2012-06-15"
13
+ s.description = "Minimalist API documentation generator for Rack applications."
14
+ s.email = "tj@turing.com"
15
+ s.executables = ["apical"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".rspec",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "apical.gemspec",
30
+ "bin/apical",
31
+ "examples/taco_truck/Gemfile",
32
+ "examples/taco_truck/Gemfile.lock",
33
+ "examples/taco_truck/app.rb",
34
+ "examples/taco_truck/taco_truck.apical",
35
+ "lib/apical.rb",
36
+ "lib/apical/adapter.rb",
37
+ "lib/apical/adapters/http_adapter.rb",
38
+ "lib/apical/adapters/rack_adapter.rb",
39
+ "lib/apical/cli.rb",
40
+ "lib/apical/content_types.rb",
41
+ "lib/apical/resource.rb",
42
+ "lib/apical/resource_types.rb",
43
+ "lib/apical/runner.rb",
44
+ "lib/apical/writers/console_writer.rb",
45
+ "lib/apical/writers/html_writer.rb",
46
+ "spec/apical/adapters/http_adapter_spec.rb",
47
+ "spec/apical/cli_spec.rb",
48
+ "spec/apical/content_types_spec.rb",
49
+ "spec/apical/rack_adapter_spec.rb",
50
+ "spec/apical_spec.rb",
51
+ "spec/before_and_after_spec.rb",
52
+ "spec/fixtures/cli_example_1.rb",
53
+ "spec/fixtures/cli_example_2.rb",
54
+ "spec/fixtures/example_require.rb",
55
+ "spec/fixtures/load_paths_example.apical",
56
+ "spec/html_writer_spec.rb",
57
+ "spec/http_apical_spec.rb",
58
+ "spec/load_paths_spec.rb",
59
+ "spec/spec_helper.rb",
60
+ "spec/support/test_apps.rb",
61
+ "templates/apical_helper.rb",
62
+ "templates/layout.mustache",
63
+ "templates/resource.mustache"
64
+ ]
65
+ s.homepage = "http://github.com/turingstudio/apical"
66
+ s.licenses = ["MIT"]
67
+ s.require_paths = ["lib"]
68
+ s.rubygems_version = "1.8.10"
69
+ s.summary = "Minimalist API documentation generator for Rack applications."
70
+
71
+ if s.respond_to? :specification_version then
72
+ s.specification_version = 3
73
+
74
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
75
+ s.add_runtime_dependency(%q<thor>, [">= 0"])
76
+ s.add_runtime_dependency(%q<mustache>, [">= 0"])
77
+ s.add_runtime_dependency(%q<rack-test>, [">= 0"])
78
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
79
+ s.add_runtime_dependency(%q<mustache>, [">= 0"])
80
+ s.add_runtime_dependency(%q<kramdown>, [">= 0"])
81
+ s.add_runtime_dependency(%q<pry>, [">= 0"])
82
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
83
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
84
+ s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
85
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
86
+ s.add_development_dependency(%q<json>, [">= 0"])
87
+ s.add_development_dependency(%q<sinatra>, [">= 0"])
88
+ s.add_development_dependency(%q<webmock>, [">= 0"])
89
+ else
90
+ s.add_dependency(%q<thor>, [">= 0"])
91
+ s.add_dependency(%q<mustache>, [">= 0"])
92
+ s.add_dependency(%q<rack-test>, [">= 0"])
93
+ s.add_dependency(%q<httparty>, [">= 0"])
94
+ s.add_dependency(%q<mustache>, [">= 0"])
95
+ s.add_dependency(%q<kramdown>, [">= 0"])
96
+ s.add_dependency(%q<pry>, [">= 0"])
97
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
98
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
99
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
100
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
101
+ s.add_dependency(%q<json>, [">= 0"])
102
+ s.add_dependency(%q<sinatra>, [">= 0"])
103
+ s.add_dependency(%q<webmock>, [">= 0"])
104
+ end
105
+ else
106
+ s.add_dependency(%q<thor>, [">= 0"])
107
+ s.add_dependency(%q<mustache>, [">= 0"])
108
+ s.add_dependency(%q<rack-test>, [">= 0"])
109
+ s.add_dependency(%q<httparty>, [">= 0"])
110
+ s.add_dependency(%q<mustache>, [">= 0"])
111
+ s.add_dependency(%q<kramdown>, [">= 0"])
112
+ s.add_dependency(%q<pry>, [">= 0"])
113
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
114
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
115
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
116
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
117
+ s.add_dependency(%q<json>, [">= 0"])
118
+ s.add_dependency(%q<sinatra>, [">= 0"])
119
+ s.add_dependency(%q<webmock>, [">= 0"])
120
+ end
121
+ end
122
+
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'apical'
5
+
6
+ Apical::CLI.start
7
+
@@ -0,0 +1,7 @@
1
+ # A sample Gemfile
2
+ source "http://rubygems.org"
3
+
4
+ gem "sinatra"
5
+ gem "json"
6
+ gem "apical", git: "https://github.com/turingstudio/apical.git"
7
+
@@ -0,0 +1,50 @@
1
+ GIT
2
+ remote: https://github.com/turingstudio/apical.git
3
+ revision: 9c752a7d0e229df8462240ee591c8c73879ca22b
4
+ specs:
5
+ apical (0.1.3)
6
+ httparty
7
+ kramdown
8
+ mustache
9
+ mustache
10
+ pry
11
+ rack-test
12
+ thor
13
+
14
+ GEM
15
+ remote: http://rubygems.org/
16
+ specs:
17
+ coderay (1.0.6)
18
+ httparty (0.8.3)
19
+ multi_json (~> 1.0)
20
+ multi_xml
21
+ json (1.7.3)
22
+ kramdown (0.13.7)
23
+ method_source (0.7.1)
24
+ multi_json (1.3.6)
25
+ multi_xml (0.5.1)
26
+ mustache (0.99.4)
27
+ pry (0.9.9.6)
28
+ coderay (~> 1.0.5)
29
+ method_source (~> 0.7.1)
30
+ slop (>= 2.4.4, < 3)
31
+ rack (1.4.1)
32
+ rack-protection (1.2.0)
33
+ rack
34
+ rack-test (0.6.1)
35
+ rack (>= 1.0)
36
+ sinatra (1.3.2)
37
+ rack (~> 1.3, >= 1.3.6)
38
+ rack-protection (~> 1.2)
39
+ tilt (~> 1.3, >= 1.3.3)
40
+ slop (2.4.4)
41
+ thor (0.15.2)
42
+ tilt (1.3.3)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ apical!
49
+ json
50
+ sinatra