Sha256: a01daf6ba1fbbefbf39d479eb30f916486010f3aea35fdaad2053b63503b6e68

Contents?: true

Size: 1.03 KB

Versions: 9

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module Lcms
  module Engine
    class MediaEmbed
      SUBJECT_COLORS = { math: '00a699', ela: 'f75b28', default: 'a269bf' }.freeze

      def self.soundcloud(url, subject)
        color = SUBJECT_COLORS[subject || :default]
        oembed_url = "http://soundcloud.com/oembed?url=#{url}&iframe=true&maxheight=166&" \
                     "color=#{color}&auto_play=false&format=json"
        RestClient.get(oembed_url) do |response|
          if response.code == 200
            oembed = JSON.parse(response)['html']
            return oembed.sub!('visual=true&', '') if oembed.present?
          end
        end
        nil
      end

      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
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
lcms-engine-0.5.5 app/entities/lcms/engine/media_embed.rb
lcms-engine-0.5.4 app/entities/lcms/engine/media_embed.rb
lcms-engine-0.5.3 app/entities/lcms/engine/media_embed.rb
lcms-engine-0.5.2 app/entities/lcms/engine/media_embed.rb
lcms-engine-0.5.1 app/entities/lcms/engine/media_embed.rb
lcms-engine-0.5.0 app/entities/lcms/engine/media_embed.rb
lcms-engine-0.4.2 app/entities/lcms/engine/media_embed.rb
lcms-engine-0.4.1 app/entities/lcms/engine/media_embed.rb
lcms-engine-0.4.0 app/entities/lcms/engine/media_embed.rb