From 30e61dbddca3a7ac4c9b398703922bc25960a70c Mon Sep 17 00:00:00 2001 From: Brett Walker Date: Sat, 6 Jan 2018 14:33:26 +0100 Subject: can now call QA api with values for query string --- qa/qa/runtime/api.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/qa/qa/runtime/api.rb b/qa/qa/runtime/api.rb index 03b17354982..a2b4210f910 100644 --- a/qa/qa/runtime/api.rb +++ b/qa/qa/runtime/api.rb @@ -9,18 +9,34 @@ module QA # Example: # # get(:gitlab, api('/users', personal_access_token: 'something')) + # get(:gitlab, api('/users', personal_access_token: 'something'), username: value, ...) # get('http://gitlab.example', '/api/v4/users?private_token=something') # # In case of an address that is a symbol we will try to guess address # based on `Runtime::Scenario#something_address`. - def self.get(address, page) - Faraday.get API::Session.new(address, page).address + def self.get(address, page, *args) + page = self.add_query_values(page, args) + response = Faraday.get(API::Session.new(address, page).address) + json = response.status == 200 ? JSON.parse(response.body) : nil + return response, json end def self.version 'v4' end + def self.add_query_values(path, args) + if args.any? + query_string = Hash(*args).map { |key, value| "#{key}=#{value}" }.join('&') + + if query_string + path << (path.index('?') ? '&' : '?') + path << query_string + end + end + path + end + class Session def initialize(instance, page = nil) @instance = instance -- cgit v1.2.1