Class: OembedProxy::Npr

Inherits:
Object
  • Object
show all
Defined in:
lib/oembed_proxy/npr.rb

Overview

NPR Fauxembed

Constant Summary collapse

NPR_REGEX =
%r{\Ahttps:\/\/(?:[a-z0-9-]+\.)+npr\.org\/.+}.freeze

Instance Method Summary collapse

Instance Method Details

#get_data(url, _other_params = {}) ⇒ Object

rubocop:disable Metrics/MethodLength



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/oembed_proxy/npr.rb', line 15

def get_data(url, _other_params = {}) # rubocop:disable Metrics/MethodLength
  return nil unless handles_url? url

  escaped_url = url.gsub('"', '"')
  {
    'type' => 'rich',
    'version' => '1.0',
    'provider_name' => 'NPR',
    'provider_url' => 'https://www.npr.org/',
    'html' => <<~HTML,
      <div class='sidechain-wrapper'>
        <side-chain src="#{escaped_url}"></side-chain>
      </div>
    HTML
  }
end

#handles_url?(url) ⇒ Boolean



11
12
13
# File 'lib/oembed_proxy/npr.rb', line 11

def handles_url?(url)
  !NPR_REGEX.match(url).nil?
end