Class: Thornbed::Providers::Imgur
- Defined in:
- lib/thornbed/providers/imgur.rb
Constant Summary
Constants inherited from Provider
Instance Attribute Summary collapse
-
#pattern ⇒ Object
Returns the value of attribute pattern.
Instance Method Summary collapse
- #get(url) ⇒ Object
-
#initialize ⇒ Imgur
constructor
A new instance of Imgur.
Methods inherited from Provider
inherited, #provider_name, #valid?
Constructor Details
#initialize ⇒ Imgur
Returns a new instance of Imgur.
10 11 12 |
# File 'lib/thornbed/providers/imgur.rb', line 10 def initialize self.pattern = /^https?:\/\/(www\.|i\.)?imgur\.com\/(gallery\/)?(?<pid>\w{5,})(?<ptype>\.gif|\.jpg|\.jpeg|\.png)?(\?full)?$/ end |
Instance Attribute Details
#pattern ⇒ Object
Returns the value of attribute pattern.
8 9 10 |
# File 'lib/thornbed/providers/imgur.rb', line 8 def pattern @pattern end |
Instance Method Details
#get(url) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/thornbed/providers/imgur.rb', line 14 def get(url) raise Thornbed::NotValid, url if !valid?(url) # imgur pic_id is ambiguous since the chars for thumb etc... can be part of the id # so we check the embed page # first get the pseudo id md = pattern.match(url) pid = md[:pid] # from Alan Schaaf, Founder & CEO, Imgur.com # If the image ID is 6 or 8 characters then it's a thumbnail. if [6,8].include? pid.size pid = pid[0...-1] end raise Thornbed::NotValid, url if not pid ptype = md[:ptype] || ".jpg" { "url" => "http://i.imgur.com/#{pid}#{ptype}", "type" => "photo", "provider_name" => provider_name, "provider_url" => "http://imgur.com", "thumbnail_url" => "http://i.imgur.com/#{pid}s#{ptype}", "version" => "1.0", "page" => "http://imgur.com/#{pid}", "width" => nil, "height" => nil } end |