restrack 1.1.7 → 1.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,7 +9,7 @@ module RESTRack
9
9
  #
10
10
 
11
11
  class ResourceController
12
- attr_reader :action, :id
12
+ attr_reader :action, :id, :params
13
13
  class << self; attr_accessor :key_type; end
14
14
 
15
15
  # Base initialization method for resources and storage of request input
@@ -39,6 +39,10 @@ module RESTRack
39
39
  # all internal methods are protected rather than private so that calling methods *could* be overriden if necessary.
40
40
  protected
41
41
 
42
+ def package_error(error)
43
+ @output = @resource_request.package(error)[0] # TODO: Remove this if change line 97 in resource_request.rb
44
+ end
45
+
42
46
  # This method allows one to access a related resource, without providing a direct link to specific relation(s).
43
47
  def self.pass_through_to(entity, opts = {})
44
48
  entity_name = opts[:as] || entity
@@ -24,11 +24,12 @@ module RESTRack
24
24
  @get_params = parse_query_string( @request )
25
25
  @params = {}
26
26
  # TODO: Test this!
27
- if @post_params.is_a? Hash
27
+ if @post_params.respond_to?(:merge)
28
28
  @params = @post_params.merge( @get_params )
29
29
  else
30
30
  @params = @get_params
31
31
  end
32
+ RESTRack.log.debug 'combined params: ' + @params.inspect
32
33
  # Setup up the initial routing.
33
34
  @url_chain = @request.path_info.split('/')
34
35
  @url_chain.shift if @url_chain[0] == ''
@@ -74,6 +75,32 @@ module RESTRack
74
75
  @mime_type.to_s
75
76
  end
76
77
 
78
+ # This handles outputing properly formatted content based on the file extension in the URL.
79
+ def package(data)
80
+ if @mime_type.like?( RESTRack.mime_type_for( :JSON ) )
81
+ @output = data.to_json
82
+ elsif @mime_type.like?( RESTRack.mime_type_for( :XML ) )
83
+ if File.exists? builder_file
84
+ @output = builder_up(data)
85
+ elsif data.respond_to?(:to_xml)
86
+ @output = data.to_xml
87
+ else
88
+ @output = XmlSimple.xml_out(data, 'AttrPrefix' => true, 'XmlDeclaration' => true, 'NoIndent' => true)
89
+ end
90
+ elsif @mime_type.like?(RESTRack.mime_type_for( :YAML ) )
91
+ @output = YAML.dump(data)
92
+ elsif @mime_type.like?(RESTRack.mime_type_for( :TEXT ) )
93
+ @output = data.to_s
94
+ else
95
+ @output = data
96
+ end
97
+ if @output.respond_to?(:each) # TODO: Should this do this? Perhaps always bundle in array in web_service.rb
98
+ return @output
99
+ else
100
+ return [@output]
101
+ end
102
+ end
103
+
77
104
  private
78
105
  def get_request_id
79
106
  t = Time.now
@@ -100,6 +127,8 @@ module RESTRack
100
127
 
101
128
  def parse_query_string(request)
102
129
  get_params = request.GET
130
+ RESTRack.log.debug "{#{@request_id}} GET data in:\n" + get_params.pretty_inspect
131
+ get_params
103
132
  end
104
133
 
105
134
  # Determine the MIME type of the request from the extension provided.
@@ -127,32 +156,6 @@ module RESTRack
127
156
  end
128
157
  end
129
158
 
130
- # This handles outputing properly formatted content based on the file extension in the URL.
131
- def package(data)
132
- if @mime_type.like?( RESTRack.mime_type_for( :JSON ) )
133
- @output = data.to_json
134
- elsif @mime_type.like?( RESTRack.mime_type_for( :XML ) )
135
- if File.exists? builder_file
136
- @output = builder_up(data)
137
- elsif data.respond_to?(:to_xml)
138
- @output = data.to_xml
139
- else
140
- @output = XmlSimple.xml_out(data, 'AttrPrefix' => true, 'XmlDeclaration' => true, 'NoIndent' => true)
141
- end
142
- elsif @mime_type.like?(RESTRack.mime_type_for( :YAML ) )
143
- @output = YAML.dump(data)
144
- elsif @mime_type.like?(RESTRack.mime_type_for( :TEXT ) )
145
- @output = data.to_s
146
- else
147
- @output = data
148
- end
149
- if @output.respond_to?(:each)
150
- return @output
151
- else
152
- return [@output]
153
- end
154
- end
155
-
156
159
  # Use Builder to generate the XML.
157
160
  def builder_up(data)
158
161
  buffer = ''
@@ -1,3 +1,3 @@
1
1
  module RESTRack
2
- VERSION = "1.1.7"
2
+ VERSION = "1.1.8"
3
3
  end
@@ -12,35 +12,35 @@ class SampleApp::ErrorsController < RESTRack::ResourceController
12
12
  #end
13
13
 
14
14
  def bad_request
15
- raise HTTP400BadRequest, 'tester'
15
+ raise HTTP400BadRequest, package_error('tester')
16
16
  end
17
17
 
18
18
  def unauthorized
19
- raise HTTP401Unauthorized, 'tester'
19
+ raise HTTP401Unauthorized, package_error('tester')
20
20
  end
21
21
 
22
22
  def forbidden
23
- raise HTTP403Forbidden, 'tester'
23
+ raise HTTP403Forbidden, package_error('tester')
24
24
  end
25
25
 
26
26
  def resource_not_found
27
- raise HTTP404ResourceNotFound, 'tester'
27
+ raise HTTP404ResourceNotFound, package_error('tester')
28
28
  end
29
29
 
30
30
  def method_not_allowed
31
- raise HTTP405MethodNotAllowed, 'tester'
31
+ raise HTTP405MethodNotAllowed, package_error('tester')
32
32
  end
33
33
 
34
34
  def conflict
35
- raise HTTP409Conflict, 'tester'
35
+ raise HTTP409Conflict, package_error('tester')
36
36
  end
37
37
 
38
38
  def gone
39
- raise HTTP410Gone, 'tester'
39
+ raise HTTP410Gone, package_error('tester')
40
40
  end
41
41
 
42
42
  def server_error
43
- raise HTTP500ServerError, 'tester'
43
+ raise HTTP500ServerError, package_error('tester')
44
44
  end
45
45
 
46
46
  end
@@ -31,8 +31,7 @@ class SampleApp::TestControllerActions < Test::Unit::TestCase
31
31
  output = @ws.call(env)
32
32
  end
33
33
  assert_equal response_code, output[0]
34
- assert_equal 'tester', output[2][0]
35
- puts output.inspect
34
+ assert_equal 'tester'.to_json, output[2][0]
36
35
  end
37
36
 
38
37
  def test_unauthorized
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restrack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.7
4
+ version: 1.1.8
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: 2011-09-16 00:00:00.000000000Z
12
+ date: 2011-09-22 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
16
- requirement: &8022520 !ruby/object:Gem::Requirement
16
+ requirement: &7018500 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *8022520
24
+ version_requirements: *7018500
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rack-test
27
- requirement: &8021980 !ruby/object:Gem::Requirement
27
+ requirement: &7017840 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *8021980
35
+ version_requirements: *7017840
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: i18n
38
- requirement: &8021380 !ruby/object:Gem::Requirement
38
+ requirement: &7017160 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *8021380
46
+ version_requirements: *7017160
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: json
49
- requirement: &8020780 !ruby/object:Gem::Requirement
49
+ requirement: &7016600 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *8020780
57
+ version_requirements: *7016600
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: xml-simple
60
- requirement: &8019800 !ruby/object:Gem::Requirement
60
+ requirement: &7015960 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.0.13
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *8019800
68
+ version_requirements: *7015960
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: builder
71
- requirement: &8018620 !ruby/object:Gem::Requirement
71
+ requirement: &7015380 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *8018620
79
+ version_requirements: *7015380
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: activesupport
82
- requirement: &8018120 !ruby/object:Gem::Requirement
82
+ requirement: &7014700 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *8018120
90
+ version_requirements: *7014700
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: mime-types
93
- requirement: &8017480 !ruby/object:Gem::Requirement
93
+ requirement: &7014080 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *8017480
101
+ version_requirements: *7014080
102
102
  description: ! "\nRESTRack is a Rack-based MVC framework that makes it extremely easy
103
103
  to develop RESTful data services. It is inspired by\nRails, and follows a few of
104
104
  its conventions. But it has no routes file, routing relationships are done through\nsupplying