Class: PactBroker::Client::BaseClient
- Inherits:
-
Object
- Object
- PactBroker::Client::BaseClient
show all
- Includes:
- HTTParty, StringToSymbol, UrlHelpers
- Defined in:
- lib/pact_broker/client/base_client.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
#string_keys_to_symbols
Methods included from UrlHelpers
#encode_param
Constructor Details
#initialize(options) ⇒ BaseClient
Returns a new instance of BaseClient.
31
32
33
34
35
36
|
# File 'lib/pact_broker/client/base_client.rb', line 31
def initialize options
@base_url = options[:base_url]
@client_options = options[:client_options] || {}
self.class.base_uri base_url
self.class.basic_auth(client_options[:basic_auth][:username], client_options[:basic_auth][:password]) if client_options[:basic_auth]
end
|
Instance Attribute Details
#base_url ⇒ Object
Returns the value of attribute base_url.
29
30
31
|
# File 'lib/pact_broker/client/base_client.rb', line 29
def base_url
@base_url
end
|
#client_options ⇒ Object
Returns the value of attribute client_options.
29
30
31
|
# File 'lib/pact_broker/client/base_client.rb', line 29
def client_options
@client_options
end
|
Instance Method Details
42
43
44
|
# File 'lib/pact_broker/client/base_client.rb', line 42
def
end
|
46
47
48
|
# File 'lib/pact_broker/client/base_client.rb', line 46
def
.merge('Content-Type' => 'application/json')
end
|
50
51
52
|
# File 'lib/pact_broker/client/base_client.rb', line 50
def
.merge('Content-Type' => 'application/json')
end
|
38
39
40
|
# File 'lib/pact_broker/client/base_client.rb', line 38
def
{'Accept' => 'application/json'}
end
|
#get(url, *args) ⇒ Object
72
73
74
|
# File 'lib/pact_broker/client/base_client.rb', line 72
def get url, *args
self.class.get(url, *args)
end
|
#handle_response(response) ⇒ Object
54
55
56
57
58
59
60
61
62
|
# File 'lib/pact_broker/client/base_client.rb', line 54
def handle_response response
if response.success?
yield
elsif response.code == 404
nil
else
raise response.body
end
end
|
#patch(url, options) ⇒ Object
64
65
66
|
# File 'lib/pact_broker/client/base_client.rb', line 64
def patch url, options
self.class.patch(url, options.merge(body: options[:body].to_json))
end
|
#put(url, *args) ⇒ Object
68
69
70
|
# File 'lib/pact_broker/client/base_client.rb', line 68
def put url, *args
self.class.put(url, *args)
end
|