Class: SirenClient::Link

Inherits:
Object
  • Object
show all
Includes:
Modules::WithRawResponse
Defined in:
lib/siren_client/link.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Modules::WithRawResponse

#disable_raw_response, #next_response_is_raw?, #with_raw_response

Constructor Details

#initialize(data, config = {}) ⇒ Link

Returns a new instance of Link.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/siren_client/link.rb', line 8

def initialize(data, config={})
  super()
  if data.class != Hash
    raise ArgumentError, "You must pass in a Hash to SirenClient::Link.new"
  end
  @payload = data
  @config = { format: :json }.merge config

  @rels  = @payload['rel']   || []
  @href  = @payload['href']  || ''
  @title = @payload['title'] || ''
  @type  = @payload['type']  || ''
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/siren_client/link.rb', line 6

def config
  @config
end

#hrefObject

Returns the value of attribute href.



5
6
7
# File 'lib/siren_client/link.rb', line 5

def href
  @href
end

#payloadObject (readonly)

Returns the value of attribute payload.



6
7
8
# File 'lib/siren_client/link.rb', line 6

def payload
  @payload
end

#relsObject (readonly)

Returns the value of attribute rels.



6
7
8
# File 'lib/siren_client/link.rb', line 6

def rels
  @rels
end

#titleObject (readonly)

Returns the value of attribute title.



6
7
8
# File 'lib/siren_client/link.rb', line 6

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/siren_client/link.rb', line 6

def type
  @type
end

Instance Method Details

#goObject



22
23
24
25
26
27
28
29
# File 'lib/siren_client/link.rb', line 22

def go
  if next_response_is_raw?
    disable_raw_response
    generate_raw_response(:get, self.href, @config)
  else
    Entity.new(self.href, @config)
  end
end