Class: ArticleJSON::Utils::OEmbedResolver::Base
- Inherits:
-
Object
- Object
- ArticleJSON::Utils::OEmbedResolver::Base
- Defined in:
- lib/article_json/utils/o_embed_resolver/base.rb
Direct Known Subclasses
FacebookVideo, Slideshare, Soundcloud, Tweet, VimeoVideo, YoutubeVideo
Class Method Summary collapse
-
.build(embed_element) ⇒ ArticleJSON::Utils::OEmbedResolver::Base
Instantiate the correct sub class for a given element.
-
.resolver_by_embed_type(type) ⇒ ArticleJSON::Utils::OEmbedResolver::Base
Lookup the correct sub class for a given element type.
Instance Method Summary collapse
-
#initialize(embed_element) ⇒ Base
constructor
A new instance of Base.
- #name ⇒ Object
-
#oembed_data ⇒ Hash|nil
Requests the OEmbed endpoint of the respective service and returns its data as a Hash.
- #source_url ⇒ Object
-
#unavailable_message ⇒ Array[ArticleJSON::Elements::Text]|nil
In case that there was an error with requesting the OEmbed data from the endpoint (e.g. because the URL is unavailable), this message can be rendered to let the user know about the issue.
Constructor Details
#initialize(embed_element) ⇒ Base
Returns a new instance of Base.
6 7 8 |
# File 'lib/article_json/utils/o_embed_resolver/base.rb', line 6 def initialize() @element = end |
Class Method Details
.build(embed_element) ⇒ ArticleJSON::Utils::OEmbedResolver::Base
Instantiate the correct sub class for a given element
83 84 85 86 |
# File 'lib/article_json/utils/o_embed_resolver/base.rb', line 83 def build() resolver = (.) resolver.new() unless resolver.nil? end |
.resolver_by_embed_type(type) ⇒ ArticleJSON::Utils::OEmbedResolver::Base
Lookup the correct sub class for a given element type
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/article_json/utils/o_embed_resolver/base.rb', line 91 def (type) { facebook_video: FacebookVideo, slideshare: Slideshare, tweet: Tweet, vimeo_video: VimeoVideo, youtube_video: YoutubeVideo, soundcloud: Soundcloud, }[type.to_sym] end |
Instance Method Details
#name ⇒ Object
34 35 36 37 |
# File 'lib/article_json/utils/o_embed_resolver/base.rb', line 34 def name raise NotImplementedError, '`#name` needs to be implemented by the subclass' end |
#oembed_data ⇒ Hash|nil
Requests the OEmbed endpoint of the respective service and returns its data as a Hash. If the endpoint returns an error, nil will be returned.
14 15 16 17 |
# File 'lib/article_json/utils/o_embed_resolver/base.rb', line 14 def resolver = self.class == Base ? self.class.build(@element) : self resolver.parsed_api_response end |
#source_url ⇒ Object
39 40 41 42 |
# File 'lib/article_json/utils/o_embed_resolver/base.rb', line 39 def source_url raise NotImplementedError, '`#source_url` needs to be implemented by the subclass' end |
#unavailable_message ⇒ Array[ArticleJSON::Elements::Text]|nil
In case that there was an error with requesting the OEmbed data from the endpoint (e.g. because the URL is unavailable), this message can be rendered to let the user know about the issue
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/article_json/utils/o_embed_resolver/base.rb', line 23 def [ ArticleJSON::Elements::Text.new(content: "The #{name} "), ArticleJSON::Elements::Text.new( content: source_url, href: source_url ), ArticleJSON::Elements::Text.new(content: ' is not available.'), ] end |