Skip to content

Expose link properties #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 23, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions lib/hyperclient/link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,36 @@ def url
@url ||= URITemplate.new(@link['href']).expand(@uri_variables)
end

# Public: Returns the type property of the Link
def type
@link['type']
end

# Public: Returns the name property of the Link
def name
@link['name']
end

# Public: Returns the deprecation property of the Link
def deprecation
@link['deprecation']
end

# Public: Returns the profile property of the Link
def profile
@link['profile']
end

# Public: Returns the title property of the Link
def title
@link['title']
end

# Public: Returns the hreflang property of the Link
def hreflang
@link['hreflang']
end

# Public: Returns the Resource which the Link is pointing to.
def resource
@resource ||=Resource.new(get.body, @entry_point)
Expand Down
14 changes: 14 additions & 0 deletions test/hyperclient/link_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ module Hyperclient
EntryPoint.new('http://api.example.org/')
end

%w(type deprecation name profile title hreflang).each do |prop|
describe prop do
it "returns the property value" do
link = Link.new({prop => 'value'}, entry_point)
link.send(prop).must_equal 'value'
end

it 'returns nil if the property is not present' do
link = Link.new({}, entry_point)
link.send(prop).must_equal nil
end
end
end

describe 'templated?' do
it 'returns true if the link is templated' do
link = Link.new({'templated' => true}, entry_point)
Expand Down