Sha256: 55d6b8bd89c68fe3f3f5319963393daa5cc1027cd67376c6eaf0cec6629320b4

Contents?: true

Size: 980 Bytes

Versions: 71

Compression:

Stored size: 980 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

71 entries across 71 versions & 1 rubygems

Version Path
onebox-1.8.47 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.46 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.45 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.44 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.43 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.42 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.41 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.40 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.39 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.38 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.36 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.35 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.34 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.33 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.32 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.31 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.30 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.29 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.28 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.8.27 lib/onebox/engine/soundcloud_onebox.rb