restful_mapper 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/features/non_json_response.feature +37 -0
- data/lib/restful_mapper.rb +12 -8
- data/lib/restful_mapper/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4def7cb059ec464db5be3af8fb180d53b690ab6a
|
4
|
+
data.tar.gz: 7a32c4b054819cb9a7cf600c8ebffbe1812b324b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6953032ca389e72bece8627a4c62d7d9a2f73e19006fd7d22ecb42b6e58ee058eff10106926c38f0be78406a8fdb367b305b95d279bab89c0ef4985f463ea435
|
7
|
+
data.tar.gz: 39b8a9b33b6b3d2fb0053c3c0248bb574887f6dcc9bb642a59bb583e82d963b43129c994845fe9a8480910024181c89ff7cefc57afe4582dcf390050809580c9
|
data/README.md
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
Feature: Handling Non-Json Response
|
2
|
+
|
3
|
+
|
4
|
+
@wip
|
5
|
+
Scenario: mapping to false
|
6
|
+
Given following service definition
|
7
|
+
"""
|
8
|
+
class ::FalseClass
|
9
|
+
def from_content(content_type, data)
|
10
|
+
false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class SimpleService < RestfulMapper::Service
|
15
|
+
base_url "http://localhost:8765"
|
16
|
+
|
17
|
+
get :simple_endpoint do
|
18
|
+
path "/simple"
|
19
|
+
|
20
|
+
responses 0 => false
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
"""
|
25
|
+
And the service endpoint at port 8765 responds with following http response:
|
26
|
+
"""
|
27
|
+
HTTP/1.1 200 OK
|
28
|
+
Connection: close
|
29
|
+
Content-Type: text/plain
|
30
|
+
|
31
|
+
whatever
|
32
|
+
"""
|
33
|
+
When I call service "SimpleService.simple_endpoint"
|
34
|
+
Then the result should be equal to:
|
35
|
+
"""
|
36
|
+
false
|
37
|
+
"""
|
data/lib/restful_mapper.rb
CHANGED
@@ -72,7 +72,7 @@ module RestfulMapper
|
|
72
72
|
status_class=@response_mapping[status]
|
73
73
|
status_class||=@response_mapping[0]
|
74
74
|
body=response.body
|
75
|
-
result=deserialize body, status_class
|
75
|
+
result=deserialize body, response.headers['Content-Type'], status_class
|
76
76
|
if Exception === result
|
77
77
|
raise result
|
78
78
|
end
|
@@ -88,15 +88,19 @@ module RestfulMapper
|
|
88
88
|
end
|
89
89
|
|
90
90
|
|
91
|
-
def deserialize json, mapping
|
92
|
-
if
|
93
|
-
|
94
|
-
|
95
|
-
if Hash == mapping || Array == mapping || mapping.is_a?(Class)
|
96
|
-
mapping.new
|
91
|
+
def deserialize json, content_type, mapping
|
92
|
+
if content_type.start_with?('application/json')
|
93
|
+
if json && !json.empty?
|
94
|
+
mapping.from_structure(MultiJson.load(json))
|
97
95
|
else
|
98
|
-
mapping
|
96
|
+
if Hash == mapping || Array == mapping || mapping.is_a?(Class)
|
97
|
+
mapping.new
|
98
|
+
else
|
99
|
+
mapping
|
100
|
+
end
|
99
101
|
end
|
102
|
+
else
|
103
|
+
mapping.from_content(content_type, json)
|
100
104
|
end
|
101
105
|
end
|
102
106
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restful_mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dragan Milic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -196,6 +196,7 @@ files:
|
|
196
196
|
- features/default_parameters.feature
|
197
197
|
- features/delete_request.feature
|
198
198
|
- features/get_request.feature
|
199
|
+
- features/non_json_response.feature
|
199
200
|
- features/post_request.feature
|
200
201
|
- features/put_request.feature
|
201
202
|
- features/raising_exceptions.feature
|
@@ -236,6 +237,7 @@ test_files:
|
|
236
237
|
- features/default_parameters.feature
|
237
238
|
- features/delete_request.feature
|
238
239
|
- features/get_request.feature
|
240
|
+
- features/non_json_response.feature
|
239
241
|
- features/post_request.feature
|
240
242
|
- features/put_request.feature
|
241
243
|
- features/raising_exceptions.feature
|