wd_sinatra 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -58,10 +58,11 @@ To generate documentation for the APIs you created in the api folder.
58
58
  ### Testing
59
59
 
60
60
  TODO
61
+ see 'wd_sinatra/test_helpers'
61
62
 
62
63
  ## Writing a service
63
64
 
64
- TODO see Weasel Diesel for now.
65
+ TODO see Weasel Diesel for now and the generated service example.
65
66
 
66
67
  ## Config and hooks
67
68
 
@@ -86,21 +87,26 @@ being required before the specific env file.
86
87
 
87
88
  ### Hooks
88
89
 
89
- The request dispatcher offers 3 hooks which you can see demonstrated in
90
+ The request dispatcher offers a fews hooks which you can see demonstrated in
90
91
  `config/hooks.rb`.
91
92
 
92
93
  * `params_preprocessor_hook(params)`
93
94
  * `params_postprocessor_hook(params)`
95
+ * `params_exception_handler(exception)`
94
96
  * `pre_dispatch_hook`
95
97
 
96
98
  The two first hooks are used to process the params and when implemented
97
99
  are expected to return the params that will be used in the request.
98
100
 
101
+ The `params_exception_handler` hook allows you to overwrite the default
102
+ exception handling happening when an exception is raised while handling
103
+ the params (pre procssing, validation or post processing).
104
+
99
105
  The `pre_dispatch_hook` is called just before the request is dispatched
100
106
  to the service implementation. This is where you might want to implement
101
107
  an authentication verification system for instance.
102
108
 
103
- These 3 hooks have access to the entire request context, including the
109
+ These hooks have access to the entire request context, including the
104
110
  `service` being called. You can use the service `extra` option to set
105
111
  some custom settings that can then be used in this pre dispatch hook.
106
112
 
@@ -71,7 +71,11 @@ class WeaselDiesel
71
71
  rescue Exception => e
72
72
  LOGGER.error e.message
73
73
  LOGGER.error "passed params: #{app.params.inspect}"
74
- halt 400, {'Content-Type' => 'application/json'}, {:error => e.message}.to_json
74
+ if self.respond_to?(:params_exception_handler)
75
+ params_exception_handler(e)
76
+ else
77
+ halt 400, {'Content-Type' => 'application/json'}, {:error => e.message}.to_json
78
+ end
75
79
  end
76
80
 
77
81
  # Define WeaselDiesel::RequestHandler#authorization_check in your app if
@@ -1,5 +1,5 @@
1
1
  module WD
2
2
  module Sinatra
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
@@ -7,7 +7,7 @@ module BodyParser
7
7
  def parse(params, body, content_type)
8
8
  case content_type
9
9
  when JSON_TYPE
10
- params.merge(json_parser.parse(body.string))
10
+ params.merge(json_parser.parse(body.read))
11
11
  else
12
12
  params
13
13
  end
@@ -29,6 +29,18 @@ module WDSinatraHooks
29
29
  end
30
30
  end
31
31
 
32
+
33
+ # This hooks gets called when an exception is raised while preprocessing the params,
34
+ # verifying them or post processing them.
35
+ # If this method isn't defined, the default handler is used (a 400 error is returned with the
36
+ # exception message sent back as a json.
37
+ #
38
+ # @param [Exception] exception The exception that was rescued.
39
+ # def pre_dispatch_hook(exception)
40
+ # # example implementation:
41
+ # # halt 400, {'Content-Type' => 'application/json'}, {:error => e.message}.to_json
42
+ # end
43
+
32
44
  # This hook gets called after the params are being verified.
33
45
  # You can use this hook to modify the params before sending them to
34
46
  # your service.
@@ -68,6 +68,13 @@
68
68
  <span class='label important'>Authentication required</span>
69
69
  <% end %>
70
70
  <%= "<p>#{api.doc.desc}</p>" if api.doc.desc %>
71
+ <% unless api.doc.examples.empty? %>
72
+ <ul>
73
+ <% api.doc.examples.each do |example| %>
74
+ <li><code><%= example %></code></li>
75
+ <% end %>
76
+ </ul>
77
+ <% end %>
71
78
  <%# TODO support for namespaced params %>
72
79
  <% [["Required", :required_rules], ["Optional", :optional_rules]].each do |label,rule_meth| %>
73
80
  <% unless api.send(rule_meth).empty? %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wd_sinatra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-11 00:00:00.000000000 Z
12
+ date: 2012-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: weasel_diesel
16
- requirement: &70278796206600 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70278796206600
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: thor
27
- requirement: &70278796222300 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,7 +37,12 @@ dependencies:
32
37
  version: '0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70278796222300
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  description: Weasel-Diesel Sinatra app gem, allowing you to generate/update sinatra
37
47
  apps using the Weasel Diesel DSL
38
48
  email:
@@ -147,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
157
  version: '0'
148
158
  requirements: []
149
159
  rubyforge_project:
150
- rubygems_version: 1.8.16
160
+ rubygems_version: 1.8.24
151
161
  signing_key:
152
162
  specification_version: 3
153
163
  summary: Weasel-Diesel Sinatra app gem, allowing you to generate/update sinatra apps