Class: Pact::PactBroker::FetchPacts

Inherits:
Object
  • Object
show all
Defined in:
lib/pact/pact_broker/fetch_pacts.rb

Constant Summary collapse

ALL_PROVIDER_TAG_RELATION =
'pb:provider-pacts-with-tag'.freeze
LATEST_PROVIDER_TAG_RELATION =
'pb:latest-provider-pacts-with-tag'.freeze
LATEST_PROVIDER_RELATION =
'pb:latest-provider-pacts'.freeze
PACTS =
'pacts'.freeze
PB_PACTS =
'pb:pacts'.freeze
HREF =
'href'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provider, tags, broker_base_url, http_client_options) ⇒ FetchPacts

Returns a new instance of FetchPacts.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pact/pact_broker/fetch_pacts.rb', line 18

def initialize(provider, tags, broker_base_url, http_client_options)
  @provider = provider
  @tags = (tags || []).collect do |tag|
    if tag.is_a?(String)
      { name: tag, all: false, fallback: nil }
    else
      tag
    end
  end
  @http_client_options = http_client_options
  @broker_base_url = broker_base_url
  @http_client = Pact::Hal::HttpClient.new(http_client_options)
end

Instance Attribute Details

#broker_base_urlObject (readonly)

Returns the value of attribute broker_base_url.



9
10
11
# File 'lib/pact/pact_broker/fetch_pacts.rb', line 9

def broker_base_url
  @broker_base_url
end

#http_clientObject (readonly)

Returns the value of attribute http_client.



9
10
11
# File 'lib/pact/pact_broker/fetch_pacts.rb', line 9

def http_client
  @http_client
end

#http_client_optionsObject (readonly)

Returns the value of attribute http_client_options.



9
10
11
# File 'lib/pact/pact_broker/fetch_pacts.rb', line 9

def http_client_options
  @http_client_options
end

#index_entityObject (readonly)

Returns the value of attribute index_entity.



9
10
11
# File 'lib/pact/pact_broker/fetch_pacts.rb', line 9

def index_entity
  @index_entity
end

#providerObject (readonly)

Returns the value of attribute provider.



9
10
11
# File 'lib/pact/pact_broker/fetch_pacts.rb', line 9

def provider
  @provider
end

#tagsObject (readonly)

Returns the value of attribute tags.



9
10
11
# File 'lib/pact/pact_broker/fetch_pacts.rb', line 9

def tags
  @tags
end

Class Method Details

.call(provider, tags, broker_base_url, http_client_options) ⇒ Object



32
33
34
# File 'lib/pact/pact_broker/fetch_pacts.rb', line 32

def self.call(provider, tags, broker_base_url, http_client_options)
  new(provider, tags, broker_base_url, http_client_options).call
end

Instance Method Details

#callObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pact/pact_broker/fetch_pacts.rb', line 36

def call
  log_message
  if index.success?
    if any_tags?
      tagged_pacts_for_provider
    else
      latest_pacts_for_provider
    end
  else
    raise Pact::Error.new("Error retrieving #{broker_base_url} status=#{index_entity.response.code} #{index_entity.response.raw_body}")
  end
end