Permalink
Browse files

[apied] flesh out other app methods

  • Loading branch information...
1 parent e5e8322 commit 5e49c80c75a7b8fb0cb35ef4775328b6ca7f5d60 @geemus committed Aug 31, 2012
Showing with 212 additions and 19 deletions.
  1. +99 −2 apied/apps.rb
  2. +21 −12 apied/endpoint.rb
  3. +84 −2 apied/output/apps.md
  4. +8 −3 apied/output/apps.rb
View
@@ -4,21 +4,92 @@ class Apps < Endpoint
delete('/:app') do
description('Delete an app')
+
+ response do
+ response = heroku.delete_app(params[:app])
+ status(response.status)
+ body(response.body.to_json)
+ end
+
+ sample(<<-SAMPLE)
+{
+ "id": "app123@heroku.com",
+ "owner_id": "user123@heroku.com",
+ "name": "myapp",
+ "created_at": "2012-01-01T12:00:00-00:00",
+ "released_at": "2012-01-01T12:00:00-00:00",
+ "repo_size": 1024,
+ "slug_size": 1450,
+ "stack": "cedar",
+ "web_url": "http://myapp.herokuapp.com",
+ "git_url": "git@heroku.com:myapp.git",
+ "buildpack_provided_description": "Ruby/Rails",
+ "maintenance": false,
+}
+ SAMPLE
end
get do
description('Get a listing of your apps.')
+
+ response do
+ response = heroku.get_apps
+ status(response.status)
+ body(response.body.to_json)
+ end
+
+ sample(<<-SAMPLE)
+[
+ {
+ "id": "app123@heroku.com",
+ "owner_id": "user123@heroku.com",
+ "name": "myapp",
+ "created_at": "2012-01-01T12:00:00-00:00",
+ "released_at": "2012-01-01T12:00:00-00:00",
+ "repo_size": 1024,
+ "slug_size": 1450,
+ "stack": "cedar",
+ "web_url": "http://myapp.herokuapp.com",
+ "git_url": "git@heroku.com:myapp.git",
+ "buildpack_provided_description": "Ruby/Rails",
+ "maintenance": false,
+ }
+]
+ SAMPLE
end
get('/:app') do
description('Get details for an app.')
+
+ response do
+ response = heroku.get_app(params[:app])
+ status(response.status)
+ body(response.body.to_json)
+ end
+
+ sample(<<-SAMPLE)
+{
+ "id": "app123@heroku.com",
+ "owner_id": "user123@heroku.com",
+ "name": "myapp",
+ "created_at": "2012-01-01T12:00:00-00:00",
+ "released_at": "2012-01-01T12:00:00-00:00",
+ "repo_size": 1024,
+ "slug_size": 1450,
+ "stack": "cedar",
+ "web_url": "http://myapp.herokuapp.com",
+ "git_url": "git@heroku.com:myapp.git",
+ "buildpack_provided_description": "Ruby/Rails",
+ "maintenance": false,
+}
+ SAMPLE
end
post do
description('Create a new app.')
- accepts(:name, 'identifier for app (default: randomly generated name).')
- accepts(:stack, 'technology stack to run app on (default: cedar).')
+ accepts(:name, 'The String name for the app (default: randomly generated name).')
+ accepts(:stack, 'The String technology stack to run app on (default: cedar).')
response do
response = heroku.post_app(data)
@@ -48,6 +119,32 @@ class Apps < Endpoint
put('/:app') do
description('Update an existing app.')
+
+ accepts(:name, 'The new String name for app.')
+ accepts(:maintenance, 'The Boolean maintenance mode status.')
+
+ response do
+ response = heroku.put_app(params[:app], request.body)
+ status(response.status)
+ body(response.body.to_json)
+ end
+
+ sample(<<-SAMPLE)
+{
+ "id": "app123@heroku.com",
+ "owner_id": "user123@heroku.com",
+ "name": "myapp",
+ "created_at": "2012-01-01T12:00:00-00:00",
+ "released_at": "2012-01-01T12:00:00-00:00",
+ "repo_size": 1024,
+ "slug_size": 1450,
+ "stack": "cedar",
+ "web_url": "http://myapp.herokuapp.com",
+ "git_url": "git@heroku.com:myapp.git",
+ "buildpack_provided_description": "Ruby/Rails",
+ "maintenance": false,
+}
+ SAMPLE
end
p data
View
@@ -34,16 +34,26 @@ def heroku
class Endpoint
def self.data
- @data ||= []
+ @data ||= {}
+ end
+
+ def self.current
+ @current
+ end
+
+ def self.current=(new_current)
+ @current = new_current
end
%w{delete get post put}.each do |method|
class_eval <<-DEF, __FILE__, __LINE__ + 1
def self.#{method}(path = nil, &block)
- data << {
+ full_path = '/' << [name.downcase, path].compact.join
+ self.current = ['#{method.upcase}', full_path].join(' ')
+ self.data[current] = {
:accepts => {},
:method => :#{method},
- :path => '/' << [name.downcase, path].compact.join,
+ :path => full_path,
:requires => {}
}
if block_given?
@@ -56,32 +66,31 @@ def self.#{method}(path = nil, &block)
# dsl!
def self.description(description)
- data.last[:description] = description
+ data[current][:description] = description
end
def self.accepts(name, description)
- data.last[:accepts][name] = description
+ data[current][:accepts][name] = description
end
def self.requires(name, description)
- data.last[:requires][name] = description
+ data[current][:requires][name] = description
end
def self.response(&block)
- data.last[:response] = block
- Endpoint::Server.send(data.last[:method], data.last[:path], &block)
+ Endpoint::Server.send(data[current][:method], data[current][:path], &block)
end
def self.sample(sample)
- data.last[:sample] = sample
+ data[current][:sample] = sample
end
# output
def self.to_client
client = ["class Client\n"]
- data.each do |datum|
+ data.each do |key, datum|
endpoint = name.downcase
client << " # Public: #{datum[:description]}"
client << ' #'
@@ -145,7 +154,7 @@ def self.to_html
def self.to_md
docs = ["# #{name}"]
- data.each do |datum|
+ data.each do |key, datum|
path = datum[:path]
docs << "## #{datum[:method].upcase} #{path}\n"
@@ -161,7 +170,7 @@ def self.to_md
unless datum[type].empty?
docs << "#### #{type.capitalize}\n"
datum[type].each do |key, value|
- docs << "* `#{key}` #{value}"
+ docs << "* `#{key}` - #{value}"
end
end
end
View
@@ -3,14 +3,70 @@
*Delete an app*
+### Sample Response
+
+```
+{
+ "id": "app123@heroku.com",
+ "owner_id": "user123@heroku.com",
+ "name": "myapp",
+ "created_at": "2012-01-01T12:00:00-00:00",
+ "released_at": "2012-01-01T12:00:00-00:00",
+ "repo_size": 1024,
+ "slug_size": 1450,
+ "stack": "cedar",
+ "web_url": "http://myapp.herokuapp.com",
+ "git_url": "git@heroku.com:myapp.git",
+ "buildpack_provided_description": "Ruby/Rails",
+ "maintenance": false,
+}
+```
## GET /apps
*Get a listing of your apps.*
+### Sample Response
+
+```
+[
+ {
+ "id": "app123@heroku.com",
+ "owner_id": "user123@heroku.com",
+ "name": "myapp",
+ "created_at": "2012-01-01T12:00:00-00:00",
+ "released_at": "2012-01-01T12:00:00-00:00",
+ "repo_size": 1024,
+ "slug_size": 1450,
+ "stack": "cedar",
+ "web_url": "http://myapp.herokuapp.com",
+ "git_url": "git@heroku.com:myapp.git",
+ "buildpack_provided_description": "Ruby/Rails",
+ "maintenance": false,
+ }
+]
+```
## GET /apps/:app
*Get details for an app.*
+### Sample Response
+
+```
+{
+ "id": "app123@heroku.com",
+ "owner_id": "user123@heroku.com",
+ "name": "myapp",
+ "created_at": "2012-01-01T12:00:00-00:00",
+ "released_at": "2012-01-01T12:00:00-00:00",
+ "repo_size": 1024,
+ "slug_size": 1450,
+ "stack": "cedar",
+ "web_url": "http://myapp.herokuapp.com",
+ "git_url": "git@heroku.com:myapp.git",
+ "buildpack_provided_description": "Ruby/Rails",
+ "maintenance": false,
+}
+```
## POST /apps
*Create a new app.*
@@ -19,8 +75,8 @@
#### Accepts
-* `name` identifier for app (default: randomly generated name).
-* `stack` technology stack to run app on (default: cedar).
+* `name` - The String name for the app (default: randomly generated name).
+* `stack` - The String technology stack to run app on (default: cedar).
### Sample Response
@@ -45,3 +101,29 @@
## PUT /apps/:app
*Update an existing app.*
+
+### Params
+
+#### Accepts
+
+* `name` - The new String name for app.
+* `maintenance` - The Boolean maintenance mode status.
+
+### Sample Response
+
+```
+{
+ "id": "app123@heroku.com",
+ "owner_id": "user123@heroku.com",
+ "name": "myapp",
+ "created_at": "2012-01-01T12:00:00-00:00",
+ "released_at": "2012-01-01T12:00:00-00:00",
+ "repo_size": 1024,
+ "slug_size": 1450,
+ "stack": "cedar",
+ "web_url": "http://myapp.herokuapp.com",
+ "git_url": "git@heroku.com:myapp.git",
+ "buildpack_provided_description": "Ruby/Rails",
+ "maintenance": false,
+}
+```
View
@@ -30,8 +30,8 @@ def get_apps(app)
# Public: Create a new app.
#
# options - hash of options for operation (default: {})
- # :name - identifier for app (default: randomly generated name).
- # :stack - technology stack to run app on (default: cedar).
+ # :name - The String name for the app (default: randomly generated name).
+ # :stack - The String technology stack to run app on (default: cedar).
#
def post_apps(options = {})
connection.request(
@@ -43,8 +43,13 @@ def post_apps(options = {})
# Public: Update an existing app.
#
- def put_apps(app)
+ # options - hash of options for operation (default: {})
+ # :name - The new String name for app.
+ # :maintenance - The Boolean maintenance mode status.
+ #
+ def put_apps(app, options = {})
connection.request(
+ :body => options,
:method => :put,
:path => "/apps/#{app}"
)

0 comments on commit 5e49c80

Please sign in to comment.