Method: RSpotify::Base#embed

Defined in:
lib/rspotify/base.rb

#embed(options = {}) ⇒ Object

Generate an embed code for an album, artist or track. For full documentation on widgets/embeds, check out the official documentation:

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :width (Integer)

    the width of the frame

  • :height (Integer)

    the height of the frame

  • :frameborder (Integer)

    the frameborder of the frame

  • :allowtransparency (Boolean)

    toggle frame transparency

  • :view (nil|String|Symbol)

    specific view option for iframe

  • :theme (nil|String|Symbol)

    specific theme option for iframe

See Also:



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/rspotify/base.rb', line 138

def embed(options = {})
  default_options = {
    width: 300,
    height: 380,
    frameborder: 0,
    allowtransparency: true,
    view: nil,
    theme: nil
  }
  options = default_options.merge(options)

  src = "https://embed.spotify.com/?uri=#{@uri}"
  src << "&view=#{options[:view]}" unless options[:view].nil?
  src << "&theme=#{options[:theme]}" unless options[:theme].nil?

  template = <<-HTML
    <iframe
      src="#{src}"
      width="#{options[:width]}"
      height="#{options[:height]}"
      frameborder="#{options[:frameborder]}"
      allowtransparency="#{options[:allowtransparency]}">
    </iframe>
  HTML

  template.gsub(/\s+/, " ").strip
end