Class: PactBroker::Client::Hal::Link
- Inherits:
-
Object
- Object
- PactBroker::Client::Hal::Link
- Defined in:
- lib/pact_broker/client/hal/link.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#request_method ⇒ Object
readonly
Returns the value of attribute request_method.
Instance Method Summary collapse
- #delete(payload = nil, headers = {}) ⇒ Object
- #delete!(*args) ⇒ Object
- #expand(params) ⇒ Object
- #get(payload = {}, headers = {}) ⇒ Object
- #get!(*args) ⇒ Object
-
#initialize(attrs, http_client) ⇒ Link
constructor
A new instance of Link.
- #name ⇒ Object
- #patch(payload = nil, headers = {}) ⇒ Object
- #patch!(*args) ⇒ Object
- #post(payload = nil, headers = {}) ⇒ Object
- #post!(*args) ⇒ Object
- #put(payload = nil, headers = {}) ⇒ Object
- #put!(*args) ⇒ Object
- #run(payload = nil) ⇒ Object
- #title ⇒ Object
- #title_or_name ⇒ Object
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
#href ⇒ Object (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_method ⇒ Object (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 (params) = (params, href) new_attrs = @attrs.merge('href' => ) 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 |
#name ⇒ Object
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 |
#title ⇒ Object
32 33 34 |
# File 'lib/pact_broker/client/hal/link.rb', line 32 def title @attrs['title'] end |
#title_or_name ⇒ Object
28 29 30 |
# File 'lib/pact_broker/client/hal/link.rb', line 28 def title_or_name title || name end |