Class: RicherText::OEmbed

Inherits:
ApplicationRecord show all
Includes:
Embeddable
Defined in:
app/models/richer_text/o_embed.rb

Constant Summary collapse

PATTERNS =
[
  {source: "^http:\\/\\/([^\\.]+\\.)?flickr\\.com\\/(.*?)", options: ""},
  {source: "^https:\\/\\/([^\\.]+\\.)?flickr\\.com\\/(.*?)", options: ""},
  {source: "^http:\\/\\/flic\\.kr\\/(.*?)", options: ""},
  {source: "^https:\\/\\/flic\\.kr\\/(.*?)", options: ""},
  {source: "^https:\\/\\/([^\\.]+\\.)?imgur\\.com\\/gallery\\/(.*?)", options: ""},
  {source: "^http:\\/\\/([^\\.]+\\.)?imgur\\.com\\/gallery\\/(.*?)", options: ""},
  {source: "^http:\\/\\/instagr\\.am\\/p\\/(.*?)", options: ""},
  {source: "^http:\\/\\/instagram\\.com\\/p\\/(.*?)", options: ""},
  {source: "^http:\\/\\/www\\.instagram\\.com\\/p\\/(.*?)", options: ""},
  {source: "^https:\\/\\/instagr\\.am\\/p\\/(.*?)", options: ""},
  {source: "^https:\\/\\/instagram\\.com\\/p\\/(.*?)", options: ""},
  {source: "^https:\\/\\/www\\.instagram\\.com\\/p\\/(.*?)", options: ""},
  {source: "^http:\\/\\/([^\\.]+\\.)?soundcloud\\.com\\/(.*?)", options: ""},
  {source: "^https:\\/\\/([^\\.]+\\.)?soundcloud\\.com\\/(.*?)", options: ""},
  {source: "^http:\\/\\/open\\.spotify\\.com\\/(.*?)", options: ""},
  {source: "^https:\\/\\/open\\.spotify\\.com\\/(.*?)", options: ""},
  {source: "^http:\\/\\/play\\.spotify\\.com\\/(.*?)", options: ""},
  {source: "^https:\\/\\/play\\.spotify\\.com\\/(.*?)", options: ""},
  {source: "^spotify\\:(.*?)", options: ""},
  {source: "^https:\\/\\/([^\\.]+\\.)?twitter\\.com\\/(.*?)\\/status\\/(.*?)", options: ""},
  {source: "^http:\\/\\/([^\\.]+\\.)?vimeo\\.com\\/(.*?)", options: ""},
  {source: "^https:\\/\\/([^\\.]+\\.)?vimeo\\.com\\/(.*?)", options: ""},
  {source: "^http:\\/\\/([^\\.]+\\.)?youtube\\.com\\/(.*?)", options: ""},
  {source: "^https:\\/\\/([^\\.]+\\.)?youtube\\.com\\/(.*?)", options: ""},
  {source: "^http:\\/\\/([^\\.]+\\.)?youtu\\.be\\/(.*?)", options: ""},
  {source: "^https:\\/\\/([^\\.]+\\.)?youtu\\.be\\/(.*?)", options: ""}
]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.delegate_fields(*keys) ⇒ Object



43
44
45
46
47
48
49
# File 'app/models/richer_text/o_embed.rb', line 43

def self.delegate_fields(*keys)
  keys.each do |key|
    define_method(key) do
      fields[key.to_s]
    end
  end
end

.from_url(url) ⇒ Object



36
37
38
39
40
41
# File 'app/models/richer_text/o_embed.rb', line 36

def self.from_url(url)
  find_by!(url: url)
rescue ActiveRecord::RecordNotFound
  resource = ::OEmbed::Providers.get(url)
  create!(url: url, fields: resource.fields)
end

Instance Method Details

#to_embeddable_partial_pathObject



73
74
75
# File 'app/models/richer_text/o_embed.rb', line 73

def to_embeddable_partial_path
  "richer_text/o_embeds/embed"
end

#to_richer_text_editor_partial_pathObject



77
78
79
# File 'app/models/richer_text/o_embed.rb', line 77

def to_richer_text_editor_partial_path
  "richer_text/o_embeds/richer_text_editor_embed"
end