class PactBroker::Client::Hal::Link
Attributes
href[R]
request_method[R]
Public Class Methods
new(attrs, http_client)
click to toggle source
# 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
Public Instance Methods
delete(payload = nil, headers = {})
click to toggle source
# 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)
click to toggle source
# File lib/pact_broker/client/hal/link.rb, line 76 def delete!(*args) delete(*args).assert_success! end
expand(params)
click to toggle source
# 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 = {})
click to toggle source
# 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)
click to toggle source
# File lib/pact_broker/client/hal/link.rb, line 44 def get!(*args) get(*args).assert_success! end
name()
click to toggle source
# File lib/pact_broker/client/hal/link.rb, line 36 def name @attrs['name'] end
patch(payload = nil, headers = {})
click to toggle source
# 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)
click to toggle source
# File lib/pact_broker/client/hal/link.rb, line 68 def patch!(*args) patch(*args).assert_success! end
post(payload = nil, headers = {})
click to toggle source
# 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)
click to toggle source
# File lib/pact_broker/client/hal/link.rb, line 60 def post!(*args) post(*args).assert_success! end
put(payload = nil, headers = {})
click to toggle source
# 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)
click to toggle source
# File lib/pact_broker/client/hal/link.rb, line 52 def put!(*args) put(*args).assert_success! end
run(payload = nil)
click to toggle source
# 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()
click to toggle source
# File lib/pact_broker/client/hal/link.rb, line 32 def title @attrs['title'] end
title_or_name()
click to toggle source
# File lib/pact_broker/client/hal/link.rb, line 28 def title_or_name title || name end
Private Instance Methods
expand_url(params, url)
click to toggle source
# File lib/pact_broker/client/hal/link.rb, line 102 def expand_url(params, url) params.inject(url) do | url, (key, value) | url.gsub('{' + key.to_s + '}', ERB::Util.url_encode(value)) end end
wrap_response(href, http_response)
click to toggle source
# File lib/pact_broker/client/hal/link.rb, line 88 def wrap_response(href, http_response) require "pact_broker/client/hal/entity" # avoid circular reference if http_response.success? Entity.new(href, http_response.body, @http_client, http_response) else body = begin http_response.header("Content-Type") && http_response.header("Content-Type").include?("json") ? http_response.body : http_response.raw_body rescue http_response.raw_body end ErrorEntity.new(href, body, @http_client, http_response) end end