Class: Integral::Video::Provider
- Inherits:
-
Object
- Object
- Integral::Video::Provider
- Defined in:
- lib/integral/video/provider.rb
Constant Summary collapse
- DB =
[ { color: "#e60000", embed_url: "https://www.youtube.com/embed/${uid}?rel=0", fa_icon: "youtube", name: "YouTube", page_url: "https://youtube.com/watch/?v=${uid}", poster_url: "https://i.ytimg.com/vi/${uid}/maxresdefault.jpg", uid: "youtube" }, { color: "#e50054", embed_url: "https://odysee.com/$/embed/${uid}", fa_icon: nil, name: "Odysee", page_url: "https://odysee.com/@LIFTINGTHEVEIL:5/How-to-save-the-world,-in-three-easy-steps.:9", poster_url: nil, uid: "odysee" }, { color: "#00ADEF", embed_url: "https://player.vimeo.com/video/${uid}", fa_icon: "vimeo-square", name: "Vimeo", page_url: "https://vimeo.com/${uid}", poster_url: nil, uid: "vimeo" }, { color: "#45668e", embed_url: "https://vk.com/video_ext.php?oid=${oid}&id=${id}&hash=${hash}&hd=2", fa_icon: "vk", name: "Вконтакте", page_url: "https://vk.com/video${uid}", poster_url: nil, uid: "vkontakte" } ].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #fa_icon ⇒ Object
- #fa_icon_id ⇒ Object
- #iframe_src(uid, hash = nil) ⇒ Object
-
#initialize(name) ⇒ Provider
constructor
Methods.
- #page_url(uid) ⇒ Object
- #poster_url(uid) ⇒ Object
Constructor Details
#initialize(name) ⇒ Provider
Methods
46 47 48 49 50 |
# File 'lib/integral/video/provider.rb', line 46 def initialize(name) fail ArgumentError, "`Provider name` must be provided" if name.nil? || name == "" self.class.find_by(name: name) || fail(ArgumentError, "Provider `name` not supported. Currently supported: #{self.class.names.join(", ")}") @name = name end |
Class Method Details
.all ⇒ Object
108 109 110 |
# File 'lib/integral/video/provider.rb', line 108 def all DB end |
.find_by(name: nil, uid: nil) ⇒ Object
116 117 118 119 120 |
# File 'lib/integral/video/provider.rb', line 116 def find_by(name: nil, uid: nil) fail ArgumentError, "Either `name` or `uid` must be provided" if [name, uid].all?(&:nil?) return DB.select { |hash| hash[:name] == name }.first unless uid return DB.select { |hash| hash[:uid] == uid }.first unless name end |
.for_select ⇒ Object
112 113 114 |
# File 'lib/integral/video/provider.rb', line 112 def for_select DB.map { |hash| [ hash[:name], hash[:name] ] } end |
.names ⇒ Object
122 123 124 |
# File 'lib/integral/video/provider.rb', line 122 def names DB.map { |hash| hash[:name] } end |
Instance Method Details
#fa_icon ⇒ Object
72 73 74 |
# File 'lib/integral/video/provider.rb', line 72 def fa_icon "<span class=\"fa fa-#{fa_icon_id}\" style=\"color: #{provider_hash[:color]}\"></span>".html_safe end |
#fa_icon_id ⇒ Object
67 68 69 |
# File 'lib/integral/video/provider.rb', line 67 def fa_icon_id provider_hash[:fa_icon] end |
#iframe_src(uid, hash = nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/integral/video/provider.rb', line 53 def iframe_src(uid, hash=nil) validate_uid! uid if @name == "Вконтакте" fail ArgumentError, "`uid` you provided (#{uid.inspect}) is not a valid VK UID" unless uid.include? "_" fail ArgumentError, "`hash` must be provided for videos from VK, you passed #{hash.inspect}" if hash.nil? || hash == "" oid, id = uid.split("_") provider_hash[:embed_url].sub("${id}", id).sub("${oid}", oid).sub("${hash}", hash) else provider_hash[:embed_url].sub("${uid}", uid) end end |
#page_url(uid) ⇒ Object
77 78 79 80 81 |
# File 'lib/integral/video/provider.rb', line 77 def page_url(uid) validate_uid! uid return unless provider_hash[:page_url] provider_hash[:page_url].sub("${uid}", uid) end |
#poster_url(uid) ⇒ Object
84 85 86 87 88 |
# File 'lib/integral/video/provider.rb', line 84 def poster_url(uid) validate_uid! uid return unless provider_hash[:poster_url] provider_hash[:poster_url].sub("${uid}", uid) end |