Class: PactBroker::Client::Matrix
- Inherits:
-
BaseClient
- Object
- BaseClient
- PactBroker::Client::Matrix
- Defined in:
- lib/pact_broker/client/matrix.rb,
lib/pact_broker/client/matrix/query.rb,
lib/pact_broker/client/matrix/resource.rb,
lib/pact_broker/client/matrix/formatter.rb,
lib/pact_broker/client/matrix/json_formatter.rb,
lib/pact_broker/client/matrix/text_formatter.rb,
lib/pact_broker/client/matrix/abbreviate_version_number.rb
Defined Under Namespace
Classes: AbbreviateVersionNumber, Formatter, JsonFormatter, Query, Resource, TextFormatter
Constant Summary
Constants inherited from BaseClient
BaseClient::ERROR_CODE_MAPPING
Instance Attribute Summary
Attributes inherited from BaseClient
Instance Method Summary collapse
- #convert_selector_hashes_to_params(selectors) ⇒ Object
- #get(selectors, options = {}) ⇒ Object
- #handle_response(response) ⇒ Object
- #query_options(options, selectors) ⇒ Object
Methods inherited from BaseClient
#default_get_headers, #default_patch_headers, #default_put_headers, #default_request_headers, #initialize, #patch, #put, #url_for_relation, #verbose?
Methods included from StringToSymbol
Methods included from UrlHelpers
#encode_param, #encode_query_param
Constructor Details
This class inherits a constructor from PactBroker::Client::BaseClient
Instance Method Details
#convert_selector_hashes_to_params(selectors) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/pact_broker/client/matrix.rb', line 69 def convert_selector_hashes_to_params(selectors) selectors.collect do |selector| { pacticipant: selector[:pacticipant] }.tap do | hash | hash[:version] = selector[:version] if selector[:version] hash[:latest] = 'true' if selector[:latest] hash[:tag] = selector[:tag] if selector[:tag] hash[:branch] = selector[:branch] if selector[:branch] end end end |
#get(selectors, options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/pact_broker/client/matrix.rb', line 9 def get selectors, = {} latestby = selectors.size == 1 ? 'cvp' : 'cvpv' query = { q: convert_selector_hashes_to_params(selectors), latestby: latestby }.merge((, selectors)) response = self.class.get("/matrix", query: query, headers: default_get_headers) response = handle_response(response) do Matrix::Resource.new(JSON.parse(response.body, symbolize_names: true)) end end |
#handle_response(response) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/pact_broker/client/matrix.rb', line 21 def handle_response response if response.success? yield elsif response.code == 401 = "Authentication failed" if response.body && response.body.size > 0 = + ": #{response.body}" end raise Error.new() elsif response.code == 404 raise Error.new("Matrix resource not found at #{base_url}/matrix. Please upgrade your Broker to the latest version.") else = nil begin errors = JSON.parse(response.body)['errors'] = if errors.is_a?(Array) errors.join("\n") elsif errors.is_a?(Hash) errors.collect{ |key, value| "#{key}: #{value}" }.join("\n") else response.body end rescue raise Error.new("status=#{response.code} #{response.body}") end raise Error.new() end end |
#query_options(options, selectors) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/pact_broker/client/matrix.rb', line 50 def (, selectors) opts = {} if .key?(:success) opts[:success] = [*[:success]] end opts[:limit] = [:limit] if [:limit] opts[:environment] = [:to_environment] if [:to_environment] if [:to_tag] opts[:latest] = 'true' opts[:tag] = [:to_tag] elsif selectors.size == 1 && ![:to_environment] opts[:latest] = 'true' end if [:ignore_selectors] && [:ignore_selectors].any? opts[:ignore] = convert_selector_hashes_to_params([:ignore_selectors]) end opts end |