Skip to content
This repository has been archived by the owner on Aug 6, 2018. It is now read-only.

Commit

Permalink
Add support for Album/Artist image sizes (close #118)
Browse files Browse the repository at this point in the history
  • Loading branch information
Burgestrand committed May 26, 2012
1 parent 2f6e27f commit 5f8156c
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 9 deletions.
10 changes: 6 additions & 4 deletions lib/hallon/album.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,18 @@ def artist
end

# @see cover_link
# @param [Symbol] size (see {Image.sizes})
# @return [Image, nil] album cover as an Image.
def cover
cover = Spotify.album_cover(pointer)
def cover(size = :normal)
cover = Spotify.album_cover(pointer, size)
Image.from(cover)
end

# @see cover
# @param [Symbol] size (see {Image.sizes})
# @return [Link, nil] album cover as a spotify URI.
def cover_link
cover = Spotify.link_create_from_album_cover!(pointer)
def cover_link(size = :normal)
cover = Spotify.link_create_from_album_cover!(pointer, size)
Link.from(cover)
end

Expand Down
10 changes: 6 additions & 4 deletions lib/hallon/artist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,18 @@ def loaded?
end

# @see portrait_link
# @param [Symbol] size (see {Image.sizes})
# @return [Image, nil] artist portrait as an Image.
def portrait
portrait = Spotify.artist_portrait(pointer)
def portrait(size = :normal)
portrait = Spotify.artist_portrait(pointer, size)
Image.from(portrait)
end

# @see portrait
# @param [Symbol] size (see {Image.sizes})
# @return [Link, nil] artist portrait as a Link.
def portrait_link
portrait = Spotify.link_create_from_artist_portrait!(pointer)
def portrait_link(size = :normal)
portrait = Spotify.link_create_from_artist_portrait!(pointer, size)
Link.from(portrait)
end

Expand Down
8 changes: 8 additions & 0 deletions lib/hallon/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ class Image < Base
extend Observable::Image
include Loadable

# A list of available image sizes.
#
# @see Album#cover
# @see Artist#portrait
def self.sizes
Spotify.enum_type(:image_size).symbols
end

# Create a new instance of an Image.
#
# @example from a link
Expand Down
16 changes: 16 additions & 0 deletions spec/hallon/album_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@
it "should be nil if there is no image" do
empty_album.cover.should be_nil
end

it "should support specifying size" do
album.cover(:large).should eq Hallon::Image.new(mock_image_id)
end

it "should raise an error when given an invalid size" do
expect { album.cover(:lawl) }.to raise_error(ArgumentError)
end
end

describe "#cover_link" do
Expand All @@ -90,5 +98,13 @@
it "should be nil if there is no image" do
empty_album.cover_link.should be_nil
end

it "should support specifying size" do
album.cover_link(:large).should eq Hallon::Link.new("spotify:image:3ad93423add99766e02d563605c6e76ed2b0e400")
end

it "should raise an error when given an invalid size" do
expect { album.cover_link(:lawl) }.to raise_error(ArgumentError)
end
end
end
16 changes: 16 additions & 0 deletions spec/hallon/artist_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@
it "should be nil if an image is not available" do
empty_artist.portrait.should be_nil
end

it "should support specifying size" do
artist.portrait(:large).should eq Hallon::Image.new(mock_image_id)
end

it "should raise an error when given an invalid size" do
expect { artist.portrait(:lawl) }.to raise_error(ArgumentError)
end
end

describe "#portrait_link" do
Expand All @@ -64,5 +72,13 @@
it "should be nil if an image is not available" do
empty_artist.portrait_link.should be_nil
end

it "should support specifying size" do
artist.portrait_link(:large).should eq Hallon::Link.new(mock_image_uri)
end

it "should raise an error when given an invalid size" do
expect { artist.portrait_link(:lawl) }.to raise_error(ArgumentError)
end
end
end
6 changes: 6 additions & 0 deletions spec/hallon/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@

specify { image.should be_a Hallon::Loadable }

describe ".sizes" do
it "should list all sizes" do
Hallon::Image.sizes.should eq [:normal, :small, :large]
end
end

describe "#loaded?" do
it "returns true when the image is loaded" do
image.should be_loaded
Expand Down
2 changes: 1 addition & 1 deletion spec/mockspotify/libmockspotify

0 comments on commit 5f8156c

Please sign in to comment.