Sha256: 785000c61917e5ff17b2fa6bbf1ea274418f1224ca30d827fcfcbbabdd1dede2
Contents?: true
Size: 785 Bytes
Versions: 12
Compression:
Stored size: 785 Bytes
Contents
require 'net/http' module Spina::Embeds class Vimeo < Base attributes :url heroicon "video-camera" REGEX = /(https?:\/\/)?(www.)?(player.)?vimeo.com\/([a-z]*\/)*([0-9]{6,11})[?]?.*/ validates :url, presence: true, format: {with: REGEX} def id REGEX.match(url).try(:[], 5) end # Get title from Vimeo API (remote call) def remote_title get_vimeo_json&.dig(0, "title") end def to_trix_partial_path "spina/embeds/vimeos/thumbnail" end private def get_vimeo_json uri = URI("https://vimeo.com/api/v2/video/#{id}.json") response = Net::HTTP.get(uri) begin JSON.parse(response) rescue nil end end end end
Version data entries
12 entries across 12 versions & 1 rubygems