Sha256: 351dc23a9153a6c67979b5e8264a341aa4dabc593d7ff60172515a72d8b7596c

Contents?: true

Size: 865 Bytes

Versions: 10

Compression:

Stored size: 865 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])
        "<img src='#{oembed_data[:thumbnail_url]}' #{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/"]
            Onebox::Helpers.symbolize_keys(::MultiJson.load(Onebox::Helpers.fetch_response(oembed_url).body))
          rescue
            {}
          end
        end

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
onebox-1.7.2 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.7.1 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.7.0 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.6.9 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.6.8 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.6.7 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.6.6 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.6.5 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.6.4 lib/onebox/engine/soundcloud_onebox.rb
onebox-1.6.3 lib/onebox/engine/soundcloud_onebox.rb