This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

renamed to avoid confusion, thanks Mark Tabler for the name suggestion

  • Loading branch information...
mattetti committed Apr 4, 2012
1 parent 5a66632 commit 9f8c65a8222cecbf8f14221fa424049c76b59214
View
@@ -1,4 +1,4 @@
source "http://rubygems.org"
-# Specify your gem's dependencies in wsdsl.gemspec
+# Specify your gem's dependencies in weasel_diesel.gemspec
gemspec
View
@@ -0,0 +1,38 @@
+PATH
+ remote: .
+ specs:
+ wsdsl (1.0.0)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ diff-lcs (1.1.3)
+ rack (1.4.1)
+ rack-protection (1.2.0)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rspec (2.9.0)
+ rspec-core (~> 2.9.0)
+ rspec-expectations (~> 2.9.0)
+ rspec-mocks (~> 2.9.0)
+ rspec-core (2.9.0)
+ rspec-expectations (2.9.1)
+ diff-lcs (~> 1.1.3)
+ rspec-mocks (2.9.0)
+ sinatra (1.3.2)
+ rack (~> 1.3, >= 1.3.6)
+ rack-protection (~> 1.2)
+ tilt (~> 1.3, >= 1.3.3)
+ tilt (1.3.3)
+ yard (0.7.5)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ rack-test
+ rspec
+ sinatra
+ wsdsl!
+ yard
View
@@ -1,4 +1,4 @@
-Copyright (c) 2011 Matt Aimonetti
+Copyright (c) 2012 Matt Aimonetti
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
View
@@ -1,9 +1,47 @@
# Web Service DSL
-WSDSL is a simple DSL allowing developers to simply describe and
-document their web APIS. For instance:
-
-
+Weasel Diesel is a simple DSL allowing developers to simply describe and
+document their web APIS.
+The DSL is already setup on top of Sinatra in this [example
+application](https://github.com/mattetti/sinatra-web-api-example) that
+you can simply fork and use as a base for your application.
+
+DSL examples:
+
+``` ruby
+describe_service "hello_world" do |service|
+ service.formats :json
+ service.http_verb :get
+ service.disable_auth # on by default
+
+ # INPUT
+ service.param.string :name, :default => 'World'
+
+ # OUTPUT
+ service.response do |response|
+ response.object do |obj|
+ obj.string :message, :doc => "The greeting message sent back. Defaults to 'World'"
+ obj.datetime :at, :doc => "The timestamp of when the message was dispatched"
+ end
+ end
+
+ # DOCUMENTATION
+ service.documentation do |doc|
+ doc.overall "This service provides a simple hello world implementation example."
+ doc.param :name, "The name of the person to greet."
+ doc.example "<code>curl -I 'http://localhost:9292/hello_world?name=Matt'</code>"
+ end
+
+ # ACTION/IMPLEMENTATION (specific to the sinatra app example, can
+ # instead be set to call a controller action)
+ service.implementation do
+ {:message => "Hello #{params[:name]}", :at => Time.now}.to_json
+ end
+
+end
+```
+
+``` ruby
describe_service "hello_world" do |service|
service.formats :xml
service.http_verb :get
@@ -24,10 +62,11 @@ document their web APIS. For instance:
end
end
-
+```
Or a more complex example:
+``` ruby
SpecOptions = ['RSpec', 'Bacon'] # usually pulled from a model
describe_service "wsdsl/test.xml" do |service|
@@ -85,14 +124,15 @@ Or a more complex example:
DOC
end
end
-
+```
## JSON APIs
This library was designed with XML responses in mind and JSON support
was added later on which explains why some response methods are aliases.
Consider the following JSON response:
+``` json
{ people: [
{
id : 1,
@@ -116,6 +156,7 @@ Consider the following JSON response:
It would be described as follows:
+``` ruby
describe_service "json_list" do |service|
service.formats :json
service.response do |response|
@@ -130,6 +171,7 @@ It would be described as follows:
end
end
end
+```
Nodes/elements can also use some meta attributes. Currently the
following meta attributes are available:
@@ -156,23 +198,27 @@ via the backports libary and some tweaks. However, because unlike in
ruby 1.9, the hash insert order isn't kept in 1.8 the following syntax
isn't supported and the alternative version needs to be used:
+``` ruby
service.response do |response|
response.element(:name => "player_creation_ratings") do |e|
e.attribute :id => :integer, :doc => "id doc"
e.attribute :is_accepted => :boolean, :doc => "is accepted doc"
e.attribute :name => :string, :doc => "name doc"
end
end
+```
Instead the following version should be used:
+``` ruby
service.response do |response|
response.element(:name => "player_creation_ratings") do |e|
e.integer :id, :doc => "id doc"
e.boolean :is_accepted, :doc => "is accepted doc"
e.string :name, :doc => "name doc"
end
end
+```
Both code snippets do the exact same thing but the first version is 1.9
only.
@@ -181,5 +227,5 @@ only.
## Copyright
-Copyright (c) 2011 Matt Aimonetti. See LICENSE for
+Copyright (c) 2012 Matt Aimonetti. See LICENSE for
further details.
View
@@ -1,4 +1,4 @@
-class WSDSL
+class WeaselDiesel
# Service documentation class
#
# @api public
@@ -1,8 +1,8 @@
-# Module used to extend {WSDSL} and add {#load_sinatra_route} to services.
-# This code is Sinatra specific and therefore lives outside the {WSDSL}
-# @see {WSDSL}
+# Module used to extend {WeaselDiesel} and add {#load_sinatra_route} to services.
+# This code is Sinatra specific and therefore lives outside the {WeaselDiesel}
+# @see {WeaselDiesel}
# @api public
-module WSDSLSinatraExtension
+module WeaselDieselSinatraExtension
# Defines a sinatra service route based on its settings
#
@@ -19,7 +19,7 @@ class SinatraServiceController
class AuthenticationFailed < StandardError; end
- # @return [WSDSL] The service served by this controller
+ # @return [WeaselDiesel] The service served by this controller
# @api public
attr_reader :service
@@ -46,7 +46,7 @@ class AuthenticationFailed < StandardError; end
attr_accessor :params
# @param [Sinatra::Application] app The Sinatra app used as a reference and to access request params
- # @param [WSDSL] service The service served by this controller
+ # @param [WeaselDiesel] service The service served by this controller
# @raise [ParamError, NoParamsDefined, MissingParam, UnexpectedParam, InvalidParamType, InvalidParamValue]
# If the params don't validate one of the {ParamsVerification} errors will be raised.
# @api public
@@ -1,4 +1,4 @@
-# include this module in WSDSL
+# include this module in WeaselDiesel
# to add response verification methods.
#
module JSONResponseVerification
@@ -49,7 +49,7 @@ def validate_hash_against_template_node(hash, node, nested=false, errors=[], arr
end
subhash ||= hash
- if node.is_a?(WSDSL::Response::Vector) && !array_item
+ if node.is_a?(WeaselDiesel::Response::Vector) && !array_item
errors << json_response_error(node, subhash, true) unless subhash.is_a?(Array)
subhash.each do |obj|
validate_hash_against_template_node(obj, node, true, errors, true)
@@ -72,7 +72,7 @@ def validate_hash_against_template_node(hash, node, nested=false, errors=[], arr
end
def json_response_error(el_or_attr, hash, type_error=false)
- if el_or_attr.is_a?(WSDSL::Response::Element)
+ if el_or_attr.is_a?(WeaselDiesel::Response::Element)
"#{el_or_attr.name || 'top level'} Node/Object/Element is missing"
elsif type_error
error = "#{el_or_attr.name || el_or_attr.inspect} was of wrong type, expected #{el_or_attr.type}"
Oops, something went wrong.

0 comments on commit 9f8c65a

Please sign in to comment.