sawyer 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/lib/sawyer.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Sawyer
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
 
4
4
  class Error < StandardError; end
5
5
  end
@@ -15,7 +15,7 @@ module Sawyer
15
15
  @status = res.status
16
16
  @headers = res.headers
17
17
  @env = res.env
18
- @data = process_data(@agent.decode_body(res.body))
18
+ @data = @headers[:content_type] =~ /json|msgpack/ ? process_data(@agent.decode_body(res.body)) : res.body
19
19
  @rels = process_rels
20
20
  end
21
21
 
data/test/agent_test.rb CHANGED
@@ -24,7 +24,7 @@ module Sawyer
24
24
  @stubs.get '/a/' do |env|
25
25
  assert_equal 'foo.com', env[:url].host
26
26
 
27
- [200, {}, Sawyer::Agent.encode(
27
+ [200, {'Content-Type' => 'application/json'}, Sawyer::Agent.encode(
28
28
  :_links => {
29
29
  :users => {:href => '/users'}})]
30
30
  end
@@ -39,7 +39,7 @@ module Sawyer
39
39
  @stubs.get '/a/' do |env|
40
40
  assert_equal 'foo.com', env[:url].host
41
41
 
42
- [200, {}, Sawyer::Agent.encode(
42
+ [200, {'Content-Type' => 'application/json'}, Sawyer::Agent.encode(
43
43
  :url => '/',
44
44
  :users_url => '/users',
45
45
  :repos_url => '/repos')]
@@ -73,7 +73,7 @@ module Sawyer
73
73
  @stubs.get '/a/' do |env|
74
74
  assert_equal 'foo.com', env[:url].host
75
75
 
76
- [200, {}, Sawyer::Agent.encode(
76
+ [200, {'Content-Type' => 'application/json'}, Sawyer::Agent.encode(
77
77
  :_links => {
78
78
  :users => {:href => '/users'}})]
79
79
  end
@@ -134,6 +134,19 @@ module Sawyer
134
134
  decoded = decoded[:foo]
135
135
  end
136
136
  end
137
+
138
+ def test_does_not_encode_non_json_content_types
139
+ @stubs.get '/a/' do |env|
140
+ assert_equal 'foo.com', env[:url].host
141
+
142
+ [200, {'Content-Type' => 'text/plain'}, "This is plain text"]
143
+ end
144
+ res = @agent.call :get, '/a/',
145
+ :headers => {"Accept" => "text/plain"}
146
+ assert_equal 200, res.status
147
+
148
+ assert_equal "This is plain text", res.data
149
+ end
137
150
  end
138
151
  end
139
152
 
@@ -60,7 +60,7 @@ module Sawyer
60
60
 
61
61
  def test_makes_request_from_relation
62
62
  @stubs.post '/a' do
63
- [201, {}, ""]
63
+ [201, {'Content-Type' => 'application/json'}, ""]
64
64
  end
65
65
 
66
66
  res = @res.data.rels[:self].call
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sawyer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-15 00:00:00.000000000 Z
12
+ date: 2013-04-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday