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

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



72
73
74
# File 'lib/pact_broker/client/hal/link.rb', line 72

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

#delete!(*args) ⇒ Object



76
77
78
# File 'lib/pact_broker/client/hal/link.rb', line 76

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

#expand(params) ⇒ Object



80
81
82
83
84
# File 'lib/pact_broker/client/hal/link.rb', line 80

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



64
65
66
# File 'lib/pact_broker/client/hal/link.rb', line 64

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

#patch!(*args) ⇒ Object



68
69
70
# File 'lib/pact_broker/client/hal/link.rb', line 68

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

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



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

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

#post!(*args) ⇒ Object



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

def post!(*args)
  post(*args).assert_success!
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

#put!(*args) ⇒ Object



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

def put!(*args)
  put(*args).assert_success!
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