diff --git a/lib/hallon/album.rb b/lib/hallon/album.rb index 12a6f84..f20b6e5 100644 --- a/lib/hallon/album.rb +++ b/lib/hallon/album.rb @@ -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 diff --git a/lib/hallon/artist.rb b/lib/hallon/artist.rb index d255bcf..85102d4 100644 --- a/lib/hallon/artist.rb +++ b/lib/hallon/artist.rb @@ -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 diff --git a/lib/hallon/image.rb b/lib/hallon/image.rb index 05ff6f0..ab5d2dd 100644 --- a/lib/hallon/image.rb +++ b/lib/hallon/image.rb @@ -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 diff --git a/spec/hallon/album_spec.rb b/spec/hallon/album_spec.rb index 47413ac..d5edb0b 100644 --- a/spec/hallon/album_spec.rb +++ b/spec/hallon/album_spec.rb @@ -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 @@ -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 diff --git a/spec/hallon/artist_spec.rb b/spec/hallon/artist_spec.rb index f57dc3c..e85059f 100644 --- a/spec/hallon/artist_spec.rb +++ b/spec/hallon/artist_spec.rb @@ -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 @@ -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 diff --git a/spec/hallon/image_spec.rb b/spec/hallon/image_spec.rb index b2c8976..a795def 100644 --- a/spec/hallon/image_spec.rb +++ b/spec/hallon/image_spec.rb @@ -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 diff --git a/spec/mockspotify/libmockspotify b/spec/mockspotify/libmockspotify index 578fa2d..11756ba 160000 --- a/spec/mockspotify/libmockspotify +++ b/spec/mockspotify/libmockspotify @@ -1 +1 @@ -Subproject commit 578fa2dcb58155ea3e29077ac16871d4a064b915 +Subproject commit 11756ba7020e3c2318f3db8d300dd80c3c919e8a