Skip to content

Commit 6325791

Browse files
committed
RUBYAPI-40 final touches
1 parent ba12f51 commit 6325791

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

lib/spark_api/connection.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,29 @@ def connection(force_ssl = false)
3333

3434
# HTTP request headers for client requests
3535
def headers
36+
if self.middleware.to_sym == :reso_api
37+
reso_headers
38+
else
39+
spark_headers
40+
end
41+
end
42+
43+
def spark_headers
3644
{
3745
:accept => 'application/json',
3846
:content_type => 'application/json',
3947
:user_agent => Configuration::DEFAULT_USER_AGENT,
4048
Configuration::X_SPARK_API_USER_AGENT => user_agent
4149
}
4250
end
51+
52+
def reso_headers
53+
{
54+
:accept => 'application/json, application/xml',
55+
:user_agent => Configuration::DEFAULT_USER_AGENT,
56+
Configuration::X_SPARK_API_USER_AGENT => user_agent
57+
}
58+
end
4359

4460
end
4561
end

lib/spark_api/request.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def request(method, path, body, options)
6565
begin
6666
request_opts = {}
6767
request_opts.merge!(options)
68-
request_path = if middleware == :reso_api
68+
request_path = if middleware.to_sym == :reso_api
6969
"/Reso/OData#{path}"
7070
else
7171
"/#{version}#{path}"

lib/spark_api/reso_faraday_middleware.rb

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,22 @@ class ResoFaradayMiddleware < FaradayMiddleware
66
def on_complete(env)
77

88
body = decompress_body(env)
9-
body = MultiJson.decode(body)
109

11-
if body["D"]
12-
puts "D contains #{body['D'].inspect}"
13-
super(env)
14-
return
10+
begin
11+
body = MultiJson.decode(body)
12+
13+
if body["D"]
14+
super(env)
15+
return
16+
end
17+
18+
env[:body] = body
19+
rescue MultiJson::ParseError => e
20+
# We will allow the client to choose their XML parser, but should do
21+
# some minor format verification
22+
raise e if body.strip[/\A<\?xml/].nil?
1523
end
1624

17-
env[:body] = body
1825
end
1926

2027
end

0 commit comments

Comments
 (0)