Class: Flickrcaptionr::Fetchers::OEmbed
- Defined in:
- lib/flickrcaptionr/fetchers/oembed.rb
Instance Method Summary collapse
- #can_handle_url?(url) ⇒ Boolean
- #fetch(url) ⇒ Object
-
#initialize ⇒ OEmbed
constructor
A new instance of OEmbed.
Methods inherited from Base
Constructor Details
Instance Method Details
#can_handle_url?(url) ⇒ Boolean
18 19 20 21 22 23 24 25 |
# File 'lib/flickrcaptionr/fetchers/oembed.rb', line 18 def can_handle_url?(url) OEmbed::Providers.urls.each_pair do |k,v| if k.match(url) return true end end return false end |
#fetch(url) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/flickrcaptionr/fetchers/oembed.rb', line 6 def fetch(url) # OEmbed::Providers.get("https://www.youtube.com/watch?v=mNrXMOSkBas") # Try and fetch this URL resp = OEmbed::Providers.get(url) # Now figure out what the heck in our oembed response is actually the image we're seeking if resp return resp.url if (resp.url rescue nil) return resp.thumbnail_url if (resp.thumbnail_url rescue nil) end # If we're here, we either didn't retrieve any suitable image URL, or our provider broke raise Flickrcaptionr::RequestNotFetchableException, "Could not retrieve #{url}" end |