Sha256: eb121df8dd39bc929413a11155156a84ec8cec706a9a5a06e7b8c53c41aabb00

Contents?: true

Size: 960 Bytes

Versions: 11

Compression:

Stored size: 960 Bytes

Contents

module Onebox
  module Engine
    class SoundCloudOnebox
      include Engine
      include StandardEmbed

      matches_regexp(/^https?:\/\/soundcloud\.com/)
      always_https

      def to_html
        oembed_data[:html].gsub('visual=true', 'visual=false')
      end

      def placeholder_html
        return if Onebox::Helpers.blank?(oembed_data[:thumbnail_url])
        escaped_src = ::Onebox::Helpers.normalize_url_for_output(oembed_data[:thumbnail_url])
        "<img src='#{escaped_src}' #{Helpers.title_attr(oembed_data)}>"
      end

      private

      def oembed_data
        @oembed_data ||= begin
          oembed_url = "https://soundcloud.com/oembed.json?url=#{url}"
          oembed_url << "&maxheight=166" unless url["/sets/"]
          response = Onebox::Helpers.fetch_response(oembed_url) rescue "{}"
          Onebox::Helpers.symbolize_keys(::MultiJson.load(response))
        rescue
          {}
        end
      end

    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
onebox-1.8.79 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.78 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.77 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.76 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.75 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.74 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.73 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.72 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.71 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.70 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.69 lib/onebox/engine/soundcloud_onebox.rb