restrack 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,7 +11,14 @@ module RESTRack
11
11
  @request_id = opts[:request_id] || get_request_id
12
12
  # Write input details to logs
13
13
  RESTRack.request_log.info "{#{@request_id}} #{@request.path_info} requested from #{@request.ip}"
14
- RESTRack.log.debug "{#{@request_id}} Reading POST Input"
14
+ end
15
+
16
+ def fulfill
17
+ self.prepare
18
+ return self.response
19
+ end
20
+
21
+ def prepare
15
22
  # Pull input data from POST body
16
23
  @input = parse_body( @request )
17
24
  @params = get_params( @request )
@@ -42,10 +49,6 @@ module RESTRack
42
49
  @active_controller = instantiate_controller( @active_resource_name )
43
50
  end
44
51
 
45
- def content_type
46
- @mime_type.to_s
47
- end
48
-
49
52
  # Send out the typed resource's output, this must occur after a call to run.
50
53
  def response
51
54
  RESTRack.log.debug "{#{@request_id}} Retrieving Output"
@@ -60,6 +63,10 @@ module RESTRack
60
63
  @active_controller.call
61
64
  end
62
65
 
66
+ def content_type
67
+ @mime_type.to_s
68
+ end
69
+
63
70
  private
64
71
  def get_request_id
65
72
  t = Time.now
@@ -79,7 +86,7 @@ module RESTRack
79
86
  input = YAML.parse( input )
80
87
  end
81
88
  end
82
- RESTRack.request_log.debug "{#{@request_id}} #{request_mime_type.to_s} data in\n" + input.pretty_inspect
89
+ RESTRack.log.debug "{#{@request_id}} #{request_mime_type.to_s} data in:\n" + input.pretty_inspect
83
90
  input
84
91
  end
85
92
 
@@ -1,3 +1,3 @@
1
1
  module RESTRack
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -14,7 +14,7 @@ module RESTRack
14
14
  request = Rack::Request.new(env)
15
15
  begin
16
16
  resource_request = RESTRack::ResourceRequest.new( :request => request )
17
- response = resource_request.response
17
+ response = resource_request.fulfill
18
18
  return valid resource_request, response
19
19
  rescue Exception => exception
20
20
  return caught resource_request, exception
@@ -25,15 +25,16 @@ module RESTRack
25
25
 
26
26
  # Return HTTP200OK SUCCESS
27
27
  def valid( resource_request, response )
28
- RESTRack.request_log.debug "'#{resource_request.mime_type.to_s}' response data (Request ID: #{resource_request.request_id})\n" + response.to_s unless not response.respond_to?( :to_s )
29
- RESTRack.request_log.info "HTTP200OK - (Request ID: #{resource_request.request_id})"
28
+ RESTRack.log.debug "(#{resource_request.request_id}) '#{resource_request.mime_type.to_s}' response data:\n" + response.to_s unless not response.respond_to?( :to_s )
29
+ RESTRack.request_log.info "(#{resource_request.request_id}) HTTP200OK"
30
30
  return [200, {'Content-Type' => resource_request.content_type}, response ]
31
31
  end
32
32
 
33
33
  # Return appropriate response code and messages per raised exception type.
34
34
  def caught( resource_request, exception )
35
+ # This will log the returned status code
35
36
  if resource_request && resource_request.request_id
36
- RESTRack.request_log.info exception.message + "(Request ID: #{resource_request.request_id})"
37
+ RESTRack.request_log.info "(#{resource_request.request_id}) " + exception.message
37
38
  else
38
39
  RESTRack.request_log.info exception.message
39
40
  end
@@ -55,7 +56,7 @@ module RESTRack
55
56
  else # HTTP500ServerError
56
57
  msg = exception.message + "\n\n" + exception.backtrace.join("\n")
57
58
  if resource_request && resource_request.request_id
58
- RESTRack.log.error msg + " (Request ID: #{resource_request.request_id})\n\n"
59
+ RESTRack.log.error "(#{resource_request.request_id})" + msg
59
60
  else
60
61
  RESTRack.log.error msg
61
62
  end
@@ -0,0 +1,3 @@
1
+ # Rails.root/config.ru
2
+ require File.join(File.dirname(__FILE__), 'loader')
3
+ run SampleApp::WebService.new
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: restrack
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.0
5
+ version: 1.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Chris St. John
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-18 00:00:00 -04:00
13
+ date: 2011-07-10 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -138,6 +138,7 @@ files:
138
138
  - lib/restrack/version.rb
139
139
  - lib/restrack/web_service.rb
140
140
  - restrack.gemspec
141
+ - test/sample_app_1/config.ru
141
142
  - test/sample_app_1/config/constants.yaml
142
143
  - test/sample_app_1/controllers/bat_controller.rb
143
144
  - test/sample_app_1/controllers/bata_controller.rb
@@ -211,6 +212,7 @@ signing_key:
211
212
  specification_version: 3
212
213
  summary: A lightweight MVC framework developed specifically for JSON (and XML) REST services.
213
214
  test_files:
215
+ - test/sample_app_1/config.ru
214
216
  - test/sample_app_1/config/constants.yaml
215
217
  - test/sample_app_1/controllers/bat_controller.rb
216
218
  - test/sample_app_1/controllers/bata_controller.rb