diff --git a/lib/vk/vk_informer_attachment.rb b/lib/vk/vk_informer_attachment.rb index 6de7b17..565c488 100644 --- a/lib/vk/vk_informer_attachment.rb +++ b/lib/vk/vk_informer_attachment.rb @@ -45,8 +45,7 @@ def domain_prefix(domain, type = :markdown) end def get_album_image(obj) - k = %w[1280 807 604 130 75].find { |x| obj.key? "photo_#{x}".to_sym } - k.nil? ? nil : obj["photo_#{k}".to_sym] + obj[:sizes].max { |a, b| a[:height] <=> b[:height] }[:url] end end end diff --git a/spec/fixtures/vk_informer_attachment/album/hash.json b/spec/fixtures/vk_informer_attachment/album/hash.json index b7ece2e..80b91ab 100644 --- a/spec/fixtures/vk_informer_attachment/album/hash.json +++ b/spec/fixtures/vk_informer_attachment/album/hash.json @@ -7,13 +7,15 @@ "id": 23456, "album_id": 12456, "owner_id": 123, - "photo_75": "http://example.com/photo75.jpg", - "photo_130": "http://example.com/photo75.jpg", - "photo_604": "http://example.com/photo75.jpg", - "photo_807": "http://example.com/photo75.jpg", - "photo_1280": "http://example.com/photo75.jpg" + "sizes": [ + { "height": 75, "url": "http://example.com/photo75.jpg" }, + { "height": 130, "url": "http://example.com/photo130.jpg" }, + { "height": 604, "url": "http://example.com/photo604.jpg" }, + { "height": 807, "url": "http://example.com/photo807.jpg" }, + { "height": 1280, "url": "http://example.com/photo1280.jpg" } + ] }, "title": "Album title", "description": "Album description" } -} \ No newline at end of file +}