lib/nightcrawler_swift/command.rb in nightcrawler_swift-0.5.0 vs lib/nightcrawler_swift/command.rb in nightcrawler_swift-0.6.0

- old
+ new

@@ -17,28 +17,32 @@ end # :nocov: protected - def get url, params = {} - prepare_params params - Gateway.new(url).request {|r| r.get params[:headers]} + def get url, args = {} + prepare_args args + Gateway.new(url).request {|r| r.get headers_and_params(args)} end - def put url, params = {} - prepare_params params - Gateway.new(url).request {|r| r.put params[:body], params[:headers]} + def put url, args = {} + prepare_args args + Gateway.new(url).request {|r| r.put args[:body], headers_and_params(args)} end - def delete url, params - prepare_params params - Gateway.new(url).request {|r| r.delete params[:headers]} + def delete url, args = {} + prepare_args args + Gateway.new(url).request {|r| r.delete headers_and_params(args)} end private + def prepare_args args + args[:headers] ||= {} + args[:headers]["X-Storage-Token"] = connection.token_id + args[:params] ||= {} + end - def prepare_params params - params[:headers] ||= {} - params[:headers]["X-Storage-Token"] = connection.token_id + def headers_and_params args + args[:headers].merge(params: args[:params]) end end end