Class: QTest::REST::QueryBuilder
- Inherits:
-
Object
- Object
- QTest::REST::QueryBuilder
- Defined in:
- lib/qtest/rest/query_builder.rb
Constant Summary collapse
- RESOURCES =
[ :project, :test_case, :release, :test_cycle, :test_suite, :test_run, :test_step, :module ].freeze
Instance Method Summary collapse
- #build ⇒ Object
- #data(params = {}) ⇒ Object (also: #body)
- #determine_parent!(opts = {}) ⇒ Object
- #header(key, value) ⇒ Object
-
#initialize(*opts) ⇒ QueryBuilder
constructor
A new instance of QueryBuilder.
- #options(*opts) ⇒ Object
- #param(key, value) ⇒ Object
- #parent(value) ⇒ Object (also: #under)
- #with(*paths) ⇒ Object
Constructor Details
#initialize(*opts) ⇒ QueryBuilder
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/qtest/rest/query_builder.rb', line 17 def initialize(*opts) RESOURCES.each do |resource| define_resource(resource) define_resources(resource) end = opts @path = [] @body = {} @query = {} @headers = {} @parent = {} end |
Instance Method Details
#build ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/qtest/rest/query_builder.rb', line 90 def build unless .include?(:without_api_path) @path = [QTest::REST::API::BASE_PATH, @path].flatten end @query.merge!(@parent) sanitize_params! sanitize_body! encode_body! { path: @path.join('/'), query: @query, headers: @headers, body: @body } end |
#data(params = {}) ⇒ Object Also known as: body
65 66 67 68 69 |
# File 'lib/qtest/rest/query_builder.rb', line 65 def data(params = {}) @body.merge!(params) self end |
#determine_parent!(opts = {}) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/qtest/rest/query_builder.rb', line 78 def determine_parent!(opts = {}) if opts[:release] parent(release: opts[:release]) elsif opts[:test_suite] parent(test_suite: opts[:test_suite]) elsif opts[:test_cycle] parent(test_cycle: opts[:test_cycle]) end self end |
#header(key, value) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/qtest/rest/query_builder.rb', line 58 def header(key, value) key = encode_for_header(key) @headers[key] = value self end |
#options(*opts) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/qtest/rest/query_builder.rb', line 32 def (*opts) opts.each do |opt| << opt unless .include?(opt) end self end |
#param(key, value) ⇒ Object
72 73 74 75 76 |
# File 'lib/qtest/rest/query_builder.rb', line 72 def param(key, value) @query[key.to_s] = value self end |
#parent(value) ⇒ Object Also known as: under
47 48 49 50 51 52 53 54 55 |
# File 'lib/qtest/rest/query_builder.rb', line 47 def parent(value) key = value.keys[0] @parent = { 'parentType' => key.to_s.dasherize, 'parentId' => value[key] } self end |
#with(*paths) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/qtest/rest/query_builder.rb', line 40 def with(*paths) paths.map! { |path| path.to_s.tr('_', '-') } @path << paths self end |