apple_music 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env.example +4 -0
- data/.gitignore +4 -0
- data/.rubocop.yml +11 -10
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +50 -35
- data/README.md +223 -1
- data/apple_music.gemspec +2 -1
- data/bin/console +3 -9
- data/bin/setup +1 -0
- data/lib/apple_music.rb +36 -0
- data/lib/apple_music/activity.rb +52 -0
- data/lib/apple_music/activity/attributes.rb +19 -0
- data/lib/apple_music/activity/relationships.rb +16 -0
- data/lib/apple_music/album.rb +62 -0
- data/lib/apple_music/album/attributes.rb +50 -0
- data/lib/apple_music/album/relationships.rb +18 -0
- data/lib/apple_music/apple_curator.rb +10 -0
- data/lib/apple_music/apple_curator/attributes.rb +19 -0
- data/lib/apple_music/apple_curator/relationships.rb +16 -0
- data/lib/apple_music/artist.rb +67 -0
- data/lib/apple_music/artist/attributes.rb +19 -0
- data/lib/apple_music/artist/relationships.rb +20 -0
- data/lib/apple_music/artwork.rb +30 -0
- data/lib/apple_music/chart.rb +33 -0
- data/lib/apple_music/chart_response.rb +21 -0
- data/lib/apple_music/config.rb +45 -0
- data/lib/apple_music/connection.rb +45 -0
- data/lib/apple_music/curator.rb +52 -0
- data/lib/apple_music/curator/attributes.rb +19 -0
- data/lib/apple_music/curator/relationships.rb +16 -0
- data/lib/apple_music/editorial_notes.rb +13 -0
- data/lib/apple_music/error.rb +27 -0
- data/lib/apple_music/genre.rb +38 -0
- data/lib/apple_music/genre/attributes.rb +16 -0
- data/lib/apple_music/music_video.rb +76 -0
- data/lib/apple_music/music_video/attributes.rb +42 -0
- data/lib/apple_music/music_video/relationships.rb +18 -0
- data/lib/apple_music/play_parameters.rb +13 -0
- data/lib/apple_music/playlist.rb +57 -0
- data/lib/apple_music/playlist/attributes.rb +45 -0
- data/lib/apple_music/playlist/relationships.rb +17 -0
- data/lib/apple_music/preview.rb +13 -0
- data/lib/apple_music/relationship.rb +23 -0
- data/lib/apple_music/resource.rb +57 -0
- data/lib/apple_music/response.rb +29 -0
- data/lib/apple_music/search.rb +39 -0
- data/lib/apple_music/search_result.rb +20 -0
- data/lib/apple_music/song.rb +81 -0
- data/lib/apple_music/song/attributes.rb +39 -0
- data/lib/apple_music/song/relationships.rb +19 -0
- data/lib/apple_music/station.rb +38 -0
- data/lib/apple_music/station/attributes.rb +27 -0
- data/lib/apple_music/storefront.rb +32 -0
- data/lib/apple_music/storefront/attributes.rb +18 -0
- data/lib/apple_music/version.rb +1 -1
- metadata +66 -5
data/lib/apple_music.rb
CHANGED
@@ -1,6 +1,42 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
require 'apple_music/connection'
|
3
6
|
require 'apple_music/version'
|
4
7
|
|
5
8
|
module AppleMusic # :nodoc:
|
9
|
+
autoload :Activity, 'apple_music/activity'
|
10
|
+
autoload :Album, 'apple_music/album'
|
11
|
+
autoload :AppleCurator, 'apple_music/apple_curator'
|
12
|
+
autoload :Artist, 'apple_music/artist'
|
13
|
+
autoload :Artwork, 'apple_music/artwork'
|
14
|
+
autoload :Chart, 'apple_music/chart'
|
15
|
+
autoload :ChartResponse, 'apple_music/chart_response'
|
16
|
+
autoload :Curator, 'apple_music/curator'
|
17
|
+
autoload :EditorialNotes, 'apple_music/editorial_notes'
|
18
|
+
autoload :Error, 'apple_music/error'
|
19
|
+
autoload :Genre, 'apple_music/genre'
|
20
|
+
autoload :MusicVideo, 'apple_music/music_video'
|
21
|
+
autoload :PlayParameters, 'apple_music/play_parameters'
|
22
|
+
autoload :Playlist, 'apple_music/playlist'
|
23
|
+
autoload :Preview, 'apple_music/preview'
|
24
|
+
autoload :Relationship, 'apple_music/relationship'
|
25
|
+
autoload :Resource, 'apple_music/resource'
|
26
|
+
autoload :Response, 'apple_music/response'
|
27
|
+
autoload :Search, 'apple_music/search'
|
28
|
+
autoload :SearchResult, 'apple_music/search_result'
|
29
|
+
autoload :Song, 'apple_music/song'
|
30
|
+
autoload :Station, 'apple_music/station'
|
31
|
+
autoload :Storefront, 'apple_music/storefront'
|
32
|
+
|
33
|
+
class << self
|
34
|
+
def search(**options)
|
35
|
+
Search.search(**options)
|
36
|
+
end
|
37
|
+
|
38
|
+
def search_hint(**options)
|
39
|
+
Search.search_hint(**options)
|
40
|
+
end
|
41
|
+
end
|
6
42
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AppleMusic
|
4
|
+
# https://developer.apple.com/documentation/applemusicapi/activity
|
5
|
+
class Activity < Resource
|
6
|
+
class << self
|
7
|
+
# e.g. AppleMusic::Activity.find(976439514)
|
8
|
+
# https://developer.apple.com/documentation/applemusicapi/get_a_catalog_activity
|
9
|
+
def find(id, **options)
|
10
|
+
storefront = Storefront.lookup(options.delete(:storefront))
|
11
|
+
response = AppleMusic.get("catalog/#{storefront}/activities/#{id}", options)
|
12
|
+
Response.new(response.body).data.first
|
13
|
+
end
|
14
|
+
|
15
|
+
# e.g. AppleMusic::Activity.list(ids: [976439514, 976439503])
|
16
|
+
def list(**options)
|
17
|
+
raise ParameterMissing, 'required parameter :ids is missing' unless options[:ids]
|
18
|
+
|
19
|
+
get_collection_by_ids(options.delete(:ids), options)
|
20
|
+
end
|
21
|
+
|
22
|
+
# e.g. AppleMusic::Activity.get_collection_by_ids([976439514, 976439503])
|
23
|
+
# https://developer.apple.com/documentation/applemusicapi/get_multiple_catalog_activities
|
24
|
+
def get_collection_by_ids(ids, **options)
|
25
|
+
ids = ids.is_a?(Array) ? ids.join(',') : ids
|
26
|
+
storefront = Storefront.lookup(options.delete(:storefront))
|
27
|
+
response = AppleMusic.get("catalog/#{storefront}/activities", options.merge(ids: ids))
|
28
|
+
Response.new(response.body).data
|
29
|
+
end
|
30
|
+
|
31
|
+
# e.g. AppleMusic::Activity.get_relationship(976439514, :playlists)
|
32
|
+
# https://developer.apple.com/documentation/applemusicapi/get_a_catalog_activity_s_relationship_directly_by_name
|
33
|
+
def get_relationship(id, relationship_type, **options)
|
34
|
+
storefront = Storefront.lookup(options.delete(:storefront))
|
35
|
+
response = AppleMusic.get("catalog/#{storefront}/activities/#{id}/#{relationship_type}", options)
|
36
|
+
Response.new(response.body).data
|
37
|
+
end
|
38
|
+
|
39
|
+
# e.g. AppleMusic::Activity.related_playlists(976439514)
|
40
|
+
def related_playlists(id, **options)
|
41
|
+
get_relationship(id, :playlists, options)
|
42
|
+
end
|
43
|
+
|
44
|
+
def search(term, **options)
|
45
|
+
AppleMusic.search(**options.merge(term: term, types: :activities)).activities
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
require 'apple_music/activity/attributes'
|
52
|
+
require 'apple_music/activity/relationships'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AppleMusic
|
4
|
+
class Activity < Resource
|
5
|
+
# https://developer.apple.com/documentation/applemusicapi/activity/attributes
|
6
|
+
class Attributes
|
7
|
+
attr_reader :artwork, :editorial_notes, :name, :url
|
8
|
+
|
9
|
+
def initialize(props = {})
|
10
|
+
@artwork = Artwork.new(props['artwork']) # required
|
11
|
+
@editorial_notes = EditorialNotes.new(props['editorialNotes']) if props['editorialNotes']
|
12
|
+
@name = props['name'] # required
|
13
|
+
@url = props['url'] # required
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
self.attributes_model = self::Attributes
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AppleMusic
|
4
|
+
class Activity < Resource
|
5
|
+
# https://developer.apple.com/documentation/applemusicapi/activity/relationships
|
6
|
+
class Relationships
|
7
|
+
attr_reader :playlists
|
8
|
+
|
9
|
+
def initialize(props = {})
|
10
|
+
@playlists = Relationship.new(props['playlists']).data
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
self.relationships_model = self::Relationships
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AppleMusic
|
4
|
+
# https://developer.apple.com/documentation/applemusicapi/album
|
5
|
+
class Album < Resource
|
6
|
+
class << self
|
7
|
+
# e.g. AppleMusic::Album.find(310730204)
|
8
|
+
# https://developer.apple.com/documentation/applemusicapi/get_a_catalog_album
|
9
|
+
def find(id, **options)
|
10
|
+
storefront = Storefront.lookup(options.delete(:storefront))
|
11
|
+
response = AppleMusic.get("catalog/#{storefront}/albums/#{id}", options)
|
12
|
+
Response.new(response.body).data.first
|
13
|
+
end
|
14
|
+
|
15
|
+
# e.g. AppleMusic::Album.list(ids: [310730204, 19075891])
|
16
|
+
def list(**options)
|
17
|
+
raise ParameterMissing, 'required parameter :ids is missing' unless options[:ids]
|
18
|
+
|
19
|
+
get_collection_by_ids(options.delete(:ids), options)
|
20
|
+
end
|
21
|
+
|
22
|
+
# e.g. AppleMusic::Album.get_collection_by_ids([310730204, 19075891])
|
23
|
+
# https://developer.apple.com/documentation/applemusicapi/get_multiple_catalog_albums
|
24
|
+
def get_collection_by_ids(ids, **options)
|
25
|
+
ids = ids.is_a?(Array) ? ids.join(',') : ids
|
26
|
+
storefront = Storefront.lookup(options.delete(:storefront))
|
27
|
+
response = AppleMusic.get("catalog/#{storefront}/albums", options.merge(ids: ids))
|
28
|
+
Response.new(response.body).data
|
29
|
+
end
|
30
|
+
|
31
|
+
# e.g. AppleMusic::Album.get_relationship(310730204, :artists)
|
32
|
+
# https://developer.apple.com/documentation/applemusicapi/get_a_catalog_album_s_relationship_directly_by_name
|
33
|
+
def get_relationship(id, relationship_type, **options)
|
34
|
+
storefront = Storefront.lookup(options.delete(:storefront))
|
35
|
+
response = AppleMusic.get("catalog/#{storefront}/albums/#{id}/#{relationship_type}", options)
|
36
|
+
Response.new(response.body).data
|
37
|
+
end
|
38
|
+
|
39
|
+
# e.g. AppleMusic::Album.related_artists(310730204)
|
40
|
+
def related_artists(id, **options)
|
41
|
+
get_relationship(id, :artists, options)
|
42
|
+
end
|
43
|
+
|
44
|
+
# e.g. AppleMusic::Album.related_genres(310730204)
|
45
|
+
def related_genres(id, **options)
|
46
|
+
get_relationship(id, :genres, options)
|
47
|
+
end
|
48
|
+
|
49
|
+
# e.g. AppleMusic::Album.related_tracks(310730204)
|
50
|
+
def related_tracks(id, **options)
|
51
|
+
get_relationship(id, :tracks, options)
|
52
|
+
end
|
53
|
+
|
54
|
+
def search(term, **options)
|
55
|
+
AppleMusic.search(**options.merge(term: term, types: :albums)).albums
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
require 'apple_music/album/attributes'
|
62
|
+
require 'apple_music/album/relationships'
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AppleMusic
|
4
|
+
class Album < Resource
|
5
|
+
# https://developer.apple.com/documentation/applemusicapi/album/attributes
|
6
|
+
class Attributes
|
7
|
+
attr_reader :album_name, :artist_name, :artwork, :content_rating,
|
8
|
+
:copyright, :editorial_notes, :genre_names, :is_complete,
|
9
|
+
:is_single, :name, :play_params, :record_label, :release_date,
|
10
|
+
:track_count, :url, :is_mastered_for_itunes
|
11
|
+
|
12
|
+
def initialize(props = {})
|
13
|
+
@album_name = props['albumName'] # required
|
14
|
+
@artist_name = props['artistName'] # required
|
15
|
+
@artwork = Artwork.new(props['artwork']) if props['artwork']
|
16
|
+
@content_rating = props['contentRating']
|
17
|
+
@copyright = props['copyright']
|
18
|
+
@editorial_notes = EditorialNotes.new(props['editorialNotes']) if props['editorialNotes']
|
19
|
+
@genre_names = props['genreNames'] # required
|
20
|
+
@is_complete = props['isComplete'] # required
|
21
|
+
@is_single = props['isSingle'] # required
|
22
|
+
@name = props['name'] # required
|
23
|
+
@play_params = PlayParameters.new(props['playParams']) if props['playParams']
|
24
|
+
@record_label = props['recordLabel'] # required
|
25
|
+
@release_date = begin # required
|
26
|
+
Date.parse(props['releaseDate'])
|
27
|
+
rescue ArgumentError
|
28
|
+
Date.parse("#{props['releaseDate']}/01/01")
|
29
|
+
end
|
30
|
+
@track_count = props['trackCount'] # required
|
31
|
+
@url = props['url'] # required
|
32
|
+
@is_mastered_for_itunes = props['isMasteredForItunes'] # required
|
33
|
+
end
|
34
|
+
|
35
|
+
def complete?
|
36
|
+
is_complete
|
37
|
+
end
|
38
|
+
|
39
|
+
def single?
|
40
|
+
is_single
|
41
|
+
end
|
42
|
+
|
43
|
+
def mastered_for_itunes?
|
44
|
+
is_mastered_for_itunes
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
self.attributes_model = self::Attributes
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AppleMusic
|
4
|
+
class Album < Resource
|
5
|
+
# https://developer.apple.com/documentation/applemusicapi/album/relationships
|
6
|
+
class Relationships
|
7
|
+
attr_reader :artists, :genres, :tracks
|
8
|
+
|
9
|
+
def initialize(props = {})
|
10
|
+
@artists = Relationship.new(props['artists']).data
|
11
|
+
@genres = Relationship.new(props['genres']).data
|
12
|
+
@tracks = Relationship.new(props['tracks']).data
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
self.relationships_model = self::Relationships
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AppleMusic
|
4
|
+
# https://developer.apple.com/documentation/applemusicapi/applecurator
|
5
|
+
class AppleCurator < Resource
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'apple_music/apple_curator/attributes'
|
10
|
+
require 'apple_music/apple_curator/relationships'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AppleMusic
|
4
|
+
class AppleCurator < Resource
|
5
|
+
# https://developer.apple.com/documentation/applemusicapi/applecurator/attributes
|
6
|
+
class Attributes
|
7
|
+
attr_reader :artwork, :editorial_notes, :name, :url
|
8
|
+
|
9
|
+
def initialize(props = {})
|
10
|
+
@artwork = Artwork.new(props['artwork']) # required
|
11
|
+
@editorial_notes = EditorialNotes.new(props['editorialNotes']) if props['editorialNotes']
|
12
|
+
@name = props['name'] # required
|
13
|
+
@url = props['url'] # required
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
self.attributes_model = self::Attributes
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AppleMusic
|
4
|
+
class AppleCurator < Resource
|
5
|
+
# https://developer.apple.com/documentation/applemusicapi/applecurator/relationships
|
6
|
+
class Relationships
|
7
|
+
attr_reader :playlists
|
8
|
+
|
9
|
+
def initialize(props = {})
|
10
|
+
@playlists = Relationship.new(props['playlists']).data
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
self.relationships_model = self::Relationships
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AppleMusic
|
4
|
+
# https://developer.apple.com/documentation/applemusicapi/artist
|
5
|
+
class Artist < Resource
|
6
|
+
class << self
|
7
|
+
# e.g. AppleMusic::Artist.find(178834)
|
8
|
+
# https://developer.apple.com/documentation/applemusicapi/get_a_catalog_artist
|
9
|
+
def find(id, **options)
|
10
|
+
storefront = Storefront.lookup(options.delete(:storefront))
|
11
|
+
response = AppleMusic.get("catalog/#{storefront}/artists/#{id}", options)
|
12
|
+
Response.new(response.body).data.first
|
13
|
+
end
|
14
|
+
|
15
|
+
# e.g. AppleMusic::Artist.list(ids: [178834, 462006])
|
16
|
+
def list(**options)
|
17
|
+
raise ParameterMissing, 'required parameter :ids is missing' unless options[:ids]
|
18
|
+
|
19
|
+
get_collection_by_ids(options.delete(:ids), options)
|
20
|
+
end
|
21
|
+
|
22
|
+
# e.g. AppleMusic::Artist.get_collection_by_ids([178834, 462006])
|
23
|
+
# https://developer.apple.com/documentation/applemusicapi/get_multiple_catalog_artists
|
24
|
+
def get_collection_by_ids(ids, **options)
|
25
|
+
ids = ids.is_a?(Array) ? ids.join(',') : ids
|
26
|
+
storefront = Storefront.lookup(options.delete(:storefront))
|
27
|
+
response = AppleMusic.get("catalog/#{storefront}/artists", options.merge(ids: ids))
|
28
|
+
Response.new(response.body).data
|
29
|
+
end
|
30
|
+
|
31
|
+
# e.g. AppleMusic::Artist.get_relationship(178834, :albums)
|
32
|
+
# https://developer.apple.com/documentation/applemusicapi/get_a_catalog_artist_s_relationship_directly_by_name
|
33
|
+
def get_relationship(id, relationship_type, **options)
|
34
|
+
storefront = Storefront.lookup(options.delete(:storefront))
|
35
|
+
response = AppleMusic.get("catalog/#{storefront}/artists/#{id}/#{relationship_type}", options)
|
36
|
+
Response.new(response.body).data
|
37
|
+
end
|
38
|
+
|
39
|
+
# e.g. AppleMusic::Artist.related_albums(178834)
|
40
|
+
def related_albums(id, **options)
|
41
|
+
get_relationship(id, :albums, options)
|
42
|
+
end
|
43
|
+
|
44
|
+
# e.g. AppleMusic::Artist.related_genres(178834)
|
45
|
+
def related_genres(id, **options)
|
46
|
+
get_relationship(id, :genres, options)
|
47
|
+
end
|
48
|
+
|
49
|
+
# e.g. AppleMusic::Artist.related_playlists(178834)
|
50
|
+
def related_playlists(id, **options)
|
51
|
+
get_relationship(id, :playlists, options)
|
52
|
+
end
|
53
|
+
|
54
|
+
# e.g. AppleMusic::Artist.related_station(178834)
|
55
|
+
def related_station(id, **options)
|
56
|
+
get_relationship(id, :station, options).first
|
57
|
+
end
|
58
|
+
|
59
|
+
def search(term, **options)
|
60
|
+
AppleMusic.search(**options.merge(term: term, types: :artists)).artists
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
require 'apple_music/artist/attributes'
|
67
|
+
require 'apple_music/artist/relationships'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AppleMusic
|
4
|
+
class Artist < Resource
|
5
|
+
# https://developer.apple.com/documentation/applemusicapi/artist/attributes
|
6
|
+
class Attributes
|
7
|
+
attr_reader :editorial_notes, :genre_names, :name, :url
|
8
|
+
|
9
|
+
def initialize(props = {})
|
10
|
+
@editorial_notes = EditorialNotes.new(props['editorialNotes']) if props['editorialNotes']
|
11
|
+
@genre_names = props['genreNames'] # required
|
12
|
+
@name = props['name'] # required
|
13
|
+
@url = props['url'] # required
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
self.attributes_model = self::Attributes
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AppleMusic
|
4
|
+
class Artist < Resource
|
5
|
+
# https://developer.apple.com/documentation/applemusicapi/artist/relationships
|
6
|
+
class Relationships
|
7
|
+
attr_reader :albums, :genres, :music_videos, :playlists, :station
|
8
|
+
|
9
|
+
def initialize(props = {})
|
10
|
+
@albums = Relationship.new(props['albums']).data
|
11
|
+
@genres = Relationship.new(props['genres']).data
|
12
|
+
@music_videos = Relationship.new(props['musicVideos']).data
|
13
|
+
@playlists = Relationship.new(props['playlists']).data
|
14
|
+
@station = Relationship.new(props['station']).data.first
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
self.relationships_model = self::Relationships
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AppleMusic
|
4
|
+
# https://developer.apple.com/documentation/applemusicapi/artwork
|
5
|
+
class Artwork
|
6
|
+
attr_reader :bg_color, :height, :width,
|
7
|
+
:text_color1, :text_color2, :text_color3,
|
8
|
+
:text_color4, :url
|
9
|
+
|
10
|
+
def initialize(props = {})
|
11
|
+
@bg_color = props['bgColor']
|
12
|
+
@height = props['height'] # required
|
13
|
+
@width = props['width'] # required
|
14
|
+
@text_color1 = props['textColor1']
|
15
|
+
@text_color2 = props['textColor2']
|
16
|
+
@text_color3 = props['textColor3']
|
17
|
+
@text_color4 = props['textColor4']
|
18
|
+
@url = props['url'] # required
|
19
|
+
end
|
20
|
+
|
21
|
+
def image_url(options = {})
|
22
|
+
@image_url ||= begin
|
23
|
+
width = options[:width] || self.width
|
24
|
+
height = options[:height] || self.height
|
25
|
+
size = options[:size] || "#{width}x#{height}"
|
26
|
+
url.gsub('{w}x{h}', size)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|