Class: PactBroker::Client::Hal::Link

Inherits:
Object
  • Object
show all
Defined in:
lib/pact_broker/client/hal/link.rb

Direct Known Subclasses

EntryPoint

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs, http_client) ⇒ Link

Returns a new instance of Link.



10
11
12
13
14
15
# File 'lib/pact_broker/client/hal/link.rb', line 10

def initialize(attrs, http_client)
  @attrs = attrs
  @request_method = attrs.fetch(:method, :get).to_sym
  @href = attrs.fetch('href')
  @http_client = http_client
end

Instance Attribute Details

#hrefObject (readonly)

Returns the value of attribute href.



8
9
10
# File 'lib/pact_broker/client/hal/link.rb', line 8

def href
  @href
end

#request_methodObject (readonly)

Returns the value of attribute request_method.



8
9
10
# File 'lib/pact_broker/client/hal/link.rb', line 8

def request_method
  @request_method
end

Instance Method Details

#expand(params) ⇒ Object



60
61
62
63
64
# File 'lib/pact_broker/client/hal/link.rb', line 60

def expand(params)
  expanded_url = expand_url(params, href)
  new_attrs = @attrs.merge('href' => expanded_url)
  Link.new(new_attrs, @http_client)
end

#get(payload = {}, headers = {}) ⇒ Object



40
41
42
# File 'lib/pact_broker/client/hal/link.rb', line 40

def get(payload = {}, headers = {})
  wrap_response(href, @http_client.get(href, payload, headers))
end

#get!(*args) ⇒ Object



44
45
46
# File 'lib/pact_broker/client/hal/link.rb', line 44

def get!(*args)
  get(*args).assert_success!
end

#nameObject



36
37
38
# File 'lib/pact_broker/client/hal/link.rb', line 36

def name
  @attrs['name']
end

#patch(payload = nil, headers = {}) ⇒ Object



56
57
58
# File 'lib/pact_broker/client/hal/link.rb', line 56

def patch(payload = nil, headers = {})
  wrap_response(href, @http_client.patch(href, payload ? JSON.dump(payload) : nil, headers))
end

#post(payload = nil, headers = {}) ⇒ Object



52
53
54
# File 'lib/pact_broker/client/hal/link.rb', line 52

def post(payload = nil, headers = {})
  wrap_response(href, @http_client.post(href, payload ? JSON.dump(payload) : nil, headers))
end

#put(payload = nil, headers = {}) ⇒ Object



48
49
50
# File 'lib/pact_broker/client/hal/link.rb', line 48

def put(payload = nil, headers = {})
  wrap_response(href, @http_client.put(href, payload ? JSON.dump(payload) : nil, headers))
end

#run(payload = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/pact_broker/client/hal/link.rb', line 17

def run(payload = nil)
  response = case request_method
    when :get
      get(payload)
    when :put
      put(payload)
    when :post
      post(payload)
    end
end

#titleObject



32
33
34
# File 'lib/pact_broker/client/hal/link.rb', line 32

def title
  @attrs['title']
end

#title_or_nameObject



28
29
30
# File 'lib/pact_broker/client/hal/link.rb', line 28

def title_or_name
  title || name
end