Skip to content

Commit

Permalink
Converts headers to a hash with stringified keys
Browse files Browse the repository at this point in the history
  • Loading branch information
inf0rmer committed Feb 10, 2015
1 parent 8c52f19 commit 986422f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/blanket/wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def request(method, id=nil, options={})

response = HTTParty.public_send(method, uri, {
query: params,
headers: headers,
headers: stringify_keys(headers),
body: options[:body]
}.reject { |_, value| value.nil? || value.empty? })

Expand All @@ -94,5 +94,9 @@ def merged_params(params)
def uri_from_parts(parts)
File.join @base_uri, *parts.compact.map(&:to_s)
end

def stringify_keys(hash)
hash.inject({}) {|memo,(k,v)| memo[k.to_s] = v; memo}
end
end
end
4 changes: 2 additions & 2 deletions spec/blanket/wrapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@
it 'allows sending headers in a request' do
api.users(55).get(headers: {foo: 'bar'})

expect(HTTParty).to have_received(:get).with('http://api.example.org/users/55', headers: {foo: 'bar'})
expect(HTTParty).to have_received(:get).with('http://api.example.org/users/55', headers: {"foo" => "bar"})
end

it 'allows setting headers globally' do
api = Blanket::wrap("http://api.example.org", headers: {token: 'my secret token'})
api.users(55).get()

expect(HTTParty).to have_received(:get).with('http://api.example.org/users/55', headers: {token: 'my secret token'})
expect(HTTParty).to have_received(:get).with('http://api.example.org/users/55', headers: {"token" => "my secret token"})
end
end

Expand Down

0 comments on commit 986422f

Please sign in to comment.