Class: Lcms::Engine::MediaEmbed
- Inherits:
-
Object
- Object
- Lcms::Engine::MediaEmbed
- Defined in:
- app/entities/lcms/engine/media_embed.rb
Constant Summary collapse
- SUBJECT_COLORS =
{ math: '00a699', ela: 'f75b28', default: 'a269bf' }.freeze
Class Method Summary collapse
Class Method Details
.soundcloud(url, subject) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/entities/lcms/engine/media_embed.rb', line 8 def self.soundcloud(url, subject) color = SUBJECT_COLORS[subject || :default] = "http://soundcloud.com/oembed?url=#{url}&iframe=true&maxheight=166&" \ "color=#{color}&auto_play=false&format=json" RestClient.get() do |response| if response.code == 200 = JSON.parse(response)['html'] return .sub!('visual=true&', '') if .present? end end nil end |
.video_id(url) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/entities/lcms/engine/media_embed.rb', line 21 def self.video_id(url) case url when /youtube/ query = URI(url).query Rack::Utils.parse_query(query)['v'] when /vimeo\.com/ url.match(%r{https?://(www\.)?vimeo.com/(\d+)}).try(:[], 2) when /youtu\.be/ url.match(%r{https?://(www\.)?youtu\.be/([^"&?/]+)}).try(:[], 2) end end |