lib/securitytrails/client.rb in securitytrails-0.1.3 vs lib/securitytrails/client.rb in securitytrails-0.1.4
- old
+ new
@@ -8,10 +8,11 @@
attr_reader :api_key
HOST = "api.securitytrails.com"
VERSION = 1
URL = "https://#{HOST}/v#{VERSION}"
+ API_KEY_HEADER = "apikey"
def initialize(api_key)
@api_key = api_key
end
@@ -46,22 +47,22 @@
end
end
def get(path, params = {}, &block)
url = url_for(path)
- params["apikey"] = api_key
url.query = URI.encode_www_form(params)
get = Net::HTTP::Get.new(url)
+ get.add_field(API_KEY_HEADER, api_key)
request(get, &block)
end
def post(path, params = {}, &block)
url = url_for(path)
- url.query = "apikey=#{api_key}"
post = Net::HTTP::Post.new(url)
post.body = params.is_a?(Hash) ? params.to_json : params.to_s
+ post.add_field(API_KEY_HEADER, api_key)
request(post, &block)
end
end
end