Skip to content

Commit

Permalink
Use preview object to get link photo
Browse files Browse the repository at this point in the history
  • Loading branch information
L-Eugene committed Apr 6, 2024
1 parent 35fffd5 commit e7b296b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
6 changes: 1 addition & 5 deletions lib/vk/vk_informer_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize(domain, node)
title = (node[:link][:title] || '').empty? ? node[:link][:url] : node[:link][:title]

@text = "[#{title}](#{node[:link][:url]})"
@preview = get_image(node) if node[:link].key? :photo
@preview = get_album_image(node[:link][:photo]) if node[:link].key? :photo
end

def to_hash
Expand All @@ -38,10 +38,6 @@ def preview?
@preview
end

def get_image(node)
node[:link][:photo]
end

def to_hash_text
{
text: text,
Expand Down
10 changes: 9 additions & 1 deletion spec/fixtures/vk_informer_attachment/link/hash.w_prev.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
"title": "sometext",
"description": "link description",
"target": "internal",
"photo": "http://example.com/image.jpg"
"photo": {
"id": 23456,
"album_id": 12456,
"owner_id": 123,
"sizes": [
{ "height": 75, "url": "http://example.com/image.small.jpg" },
{ "height": 604, "url": "http://example.com/image.jpg" }
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
"title": "sometext",
"description": "link description",
"target": "internal",
"photo": "http://example.com/image.small.jpg"
"photo": {
"id": 23456,
"album_id": 12456,
"owner_id": 123,
"sizes": [
{ "height": 75, "url": "http://example.com/image.small.jpg" }
]
}
}
}

0 comments on commit e7b296b

Please sign in to comment.