Skip to content

Commit

Permalink
Refactors stringify_keys to a utils file
Browse files Browse the repository at this point in the history
  • Loading branch information
inf0rmer committed Feb 10, 2015
1 parent 986422f commit 0ceb6dd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 5 additions & 0 deletions lib/blanket/utils.rb
@@ -0,0 +1,5 @@
module Blanket
def self.stringify_keys(hash)
hash.inject({}) {|memo,(k,v)| memo[k.to_s] = v; memo}
end
end
10 changes: 4 additions & 6 deletions lib/blanket/wrapper.rb
@@ -1,3 +1,5 @@
require_relative "utils"

module Blanket
class Wrapper
class << self
Expand Down Expand Up @@ -61,7 +63,7 @@ def request(method, id=nil, options={})
id = nil
end

headers = merged_headers(options[:headers])
headers = Blanket.stringify_keys merged_headers(options[:headers])
params = merged_params(options[:params])
uri = uri_from_parts([id])

Expand All @@ -71,7 +73,7 @@ def request(method, id=nil, options={})

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

Expand All @@ -94,9 +96,5 @@ 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

0 comments on commit 0ceb6dd

Please sign in to comment.