class ApiHammer::Weblink

a RFC5988 Web Link

tools.ietf.org/html/rfc5988

Attributes

attributes[R]

link attributes

context_iri[R]

the context uri of the link, as an Addressable URI. this URI must be absolute, and the target_uri may be resolved against it. this is most typically the request URI of a request to a service

context_uri[R]

the context uri of the link, as an Addressable URI. this URI must be absolute, and the target_uri may be resolved against it. this is most typically the request URI of a request to a service

target_iri[R]

returns the target URI as an Addressable::URI

target_uri[R]

returns the target URI as an Addressable::URI

Public Class Methods

new(target_uri, attributes, context_uri=nil) click to toggle source
# File lib/api_hammer/weblink.rb, line 54
def initialize(target_uri, attributes, context_uri=nil)
  @target_uri = to_addressable_uri(target_uri)
  @attributes = attributes
  @context_uri = to_addressable_uri(context_uri)
end

Public Instance Methods

[](attribute_key) click to toggle source

subscript returns an attribute of this Link, if defined, otherwise nil

# File lib/api_hammer/weblink.rb, line 88
def [](attribute_key)
  @attributes[attribute_key]
end
absolute_target_uri() click to toggle source

attempts to make target_uri absolute, using context_uri if available. raises if there is not information available to make an absolute target URI

# File lib/api_hammer/weblink.rb, line 74
def absolute_target_uri
  if target_uri.absolute?
    target_uri
  elsif context_uri
    context_uri + target_uri
  else
    raise NoContextError, "Target URI is relative but no Context URI given - cannot determine absolute target URI"
  end
end
rel() click to toggle source

link rel attribute

# File lib/api_hammer/weblink.rb, line 93
def rel
  self['rel']
end
Also aliased as: relation_type
rel?(other_rel) click to toggle source

compares relation types in a case-insensitive manner as mandated in tools.ietf.org/html/rfc5988#section-4.1

# File lib/api_hammer/weblink.rb, line 100
def rel?(other_rel)
  rel && other_rel && rel.downcase == other_rel.downcase
end
relation_type()
Alias for: rel
to_s() click to toggle source

a string of this weblink, appropriate for adding to a Link header

# File lib/api_hammer/weblink.rb, line 105
def to_s
  "<#{target_uri}>" + attributes.map { |k,v| %Q(; #{k}="#{v}") }.join('')
end

Private Instance Methods

to_addressable_uri(uri) click to toggle source

if uri is nil, returns nil; otherwise, tries to return a Addressable::URI

# File lib/api_hammer/weblink.rb, line 111
def to_addressable_uri(uri)
  uri.nil? || uri.is_a?(Addressable::URI) ? uri : Addressable::URI.parse(uri)
end