Kouhei Sutou
null+****@clear*****
Mon Jan 20 16:30:46 JST 2014
Kouhei Sutou 2014-01-20 16:30:46 +0900 (Mon, 20 Jan 2014) New Revision: 3a5164da44ad0634536af323b126fff4d7c3118b https://github.com/droonga/droonga-client-ruby/commit/3a5164da44ad0634536af323b126fff4d7c3118b Message: http: use "GET" as the default HTTP method Modified files: lib/droonga/client/connection/http.rb Modified: lib/droonga/client/connection/http.rb (+9 -3) =================================================================== --- lib/droonga/client/connection/http.rb 2014-01-20 15:51:45 +0900 (af1f61b) +++ lib/droonga/client/connection/http.rb 2014-01-20 16:30:46 +0900 (727f378) @@ -126,14 +126,15 @@ module Droonga http.read_timeout = read_timeout http.start do request = nil - case message["method"] + method = http_method(message) + case method when "POST" request = Net::HTTP::Post.new(build_path(message), build_headers(message)) request.body = JSON.generate(message["body"]) when "GET" request = Net::HTTP::Get.new(build_path(message), build_headers(message)) else - raise ArgumentError.new("Unsupport HTTP Method: #{message["method"]}, " + + raise ArgumentError.new("Unsupport HTTP Method: #{method}, " + "in the message: #{JSON.generate(message)}") end http.request(request) do |response| @@ -152,10 +153,11 @@ module Droonga def build_path(message) type = message["type"] body = message["body"] || {} + method = http_method(message) base_path = message["path"] || "/#{type}" if body.empty? base_path - elsif message["method"] == "GET" + elsif method == "GET" "#{base_path}?#{Rack::Utils.build_nested_query(body)}" else base_path @@ -165,6 +167,10 @@ module Droonga def build_headers(message) message["headers"] || {} end + + def http_method(message) + message["method"] || "GET" + end end end end -------------- next part -------------- HTML����������������������������...下載