restful_mapper 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77221199e858bff0473e341caeb476fab4a9f20f
4
- data.tar.gz: 012a9f9893e7fed2f917715ee605f08e7e3f5840
3
+ metadata.gz: 4def7cb059ec464db5be3af8fb180d53b690ab6a
4
+ data.tar.gz: 7a32c4b054819cb9a7cf600c8ebffbe1812b324b
5
5
  SHA512:
6
- metadata.gz: 4c351450ae1850ba7a5c87aa7c0cc4b3af691dc6756aa62ae1ef0276fd14b9cf7b28de5486130f54b395d581c8aa28f8c1e7bf4b6ec9b50e0bcb83c05ce866d6
7
- data.tar.gz: 4cb445bb1cd7f9c60b9cfb5131a8ae9f50d083a5e38290351721403c0bebefa852b6c3572d9e0cc225bcd1cb7e9a3de98313528fa46c31e0ba6ea81561216fd7
6
+ metadata.gz: 6953032ca389e72bece8627a4c62d7d9a2f73e19006fd7d22ecb42b6e58ee058eff10106926c38f0be78406a8fdb367b305b95d279bab89c0ef4985f463ea435
7
+ data.tar.gz: 39b8a9b33b6b3d2fb0053c3c0248bb574887f6dcc9bb642a59bb583e82d963b43129c994845fe9a8480910024181c89ff7cefc57afe4582dcf390050809580c9
data/README.md CHANGED
@@ -112,6 +112,9 @@ TBD
112
112
  ### Raising Exception
113
113
  TBD
114
114
 
115
+ ## Missing Features
116
+ Logging
117
+
115
118
  ## Contributing
116
119
 
117
120
  1. Fork it ( http://github.com/<my-github-username>/restful_mapper/fork )
@@ -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
+ """
@@ -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 json && !json.empty?
93
- mapping.from_structure(MultiJson.load(json))
94
- else
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
 
@@ -1,3 +1,3 @@
1
1
  module RestfulMapper
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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.1
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-03-18 00:00:00.000000000 Z
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