lib/paidy.rb in paidy-0.0.2 vs lib/paidy.rb in paidy-0.0.3

- old
+ new

@@ -31,24 +31,26 @@ end uri = api_uri(path: path) case method.to_s.downcase.to_sym - # when :get - # uri += (URI.parse(uri).query.present? ? '&' : '?') + query_parameter(params) + when :get + uri += (uri.query.present? ? '&' : '?') + query_parameter(params) if params.present? + req = Net::HTTP::Get.new(uri) when :post req = Net::HTTP::Post.new(uri) - req['Content-Type'] = 'application/json' - req['Paidy-Version'] = @api_version - req['Authorization'] = "Bearer #{secret_key}" req.body = params.to_json - - req_options = { - use_ssl: @use_ssl, - } end + req['Content-Type'] = 'application/json' + req['Paidy-Version'] = @api_version + req['Authorization'] = "Bearer #{secret_key}" + + req_options = { + use_ssl: @use_ssl, + } + response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http| http.request(req) end body = JSON.parse(response.body) @@ -63,12 +65,12 @@ private def self.query_parameter(params) params.map do |k, v| if v.is_a?(Array) - v.map{ |vv| "#{k}[]=#{CGI.encode(vv)}" }.join('&') + v.map{ |vv| "#{k}[]=#{CGI.escape(vv)}" }.join('&') else - "#{k}=#{CGI.encode(v)}" + "#{k}=#{CGI.escape(v)}" end end.join('&') end end