class KOSapiClient::Entity::Link

Attributes

Public Class Methods

new(title, href, rel, client = nil) click to toggle source
# File lib/kosapi_client/entity/link.rb, line 7
def initialize(title, href, rel, client = nil)
  @link_title = title
  @link_href = escape_url(href)
  @link_rel = rel
  @client = client
end
parse(contents) click to toggle source
# File lib/kosapi_client/entity/link.rb, line 14
def self.parse(contents)
  href = contents[:xlink_href] || contents[:href]
  new(contents[:__content__], href, contents[:rel])
end

Public Instance Methods

escape_url(url) click to toggle source
# File lib/kosapi_client/entity/link.rb, line 48
def escape_url(url)
  url.gsub(';','%3B')
end
follow() click to toggle source
# File lib/kosapi_client/entity/link.rb, line 23
def follow
  raise "HTTP client not set, cannot send request to #{link_href}" unless @client
  @client.send_request(:get, link_href)
end
inject_client(client) click to toggle source
# File lib/kosapi_client/entity/link.rb, line 28
def inject_client(client)
  @client = client
end
method_missing(method, *args, &block) click to toggle source
# File lib/kosapi_client/entity/link.rb, line 40
def method_missing(method, *args, &block)
  target.send(method, *args, &block)
end
respond_to_missing?(method_name, include_private = false) click to toggle source
# File lib/kosapi_client/entity/link.rb, line 44
def respond_to_missing?(method_name, include_private = false)
  target.respond_to?(method_name, include_private)
end
target() click to toggle source
# File lib/kosapi_client/entity/link.rb, line 32
def target
  @target ||= follow
end
to_hash() click to toggle source
# File lib/kosapi_client/entity/link.rb, line 36
def to_hash
  { href: link_href, rel: link_rel, title: link_title }
end