diff options
author | Brett Walker <bwalker@gitlab.com> | 2018-01-06 14:33:26 +0100 |
---|---|---|
committer | Brett Walker <bwalker@gitlab.com> | 2018-01-22 17:25:10 +0100 |
commit | 30e61dbddca3a7ac4c9b398703922bc25960a70c (patch) | |
tree | 0609413fa6ded44113b5098a21bed11efe617236 | |
parent | 590956d0d14678a3498c077737aaa2508f267520 (diff) | |
download | gitlab-ce-30e61dbddca3a7ac4c9b398703922bc25960a70c.tar.gz |
can now call QA api with values for query string
-rw-r--r-- | qa/qa/runtime/api.rb | 20 |
1 files 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 |