Class: Thornbed::Providers::NineGag
- Defined in:
- lib/thornbed/providers/9gag.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 ⇒ NineGag
constructor
A new instance of NineGag.
Methods inherited from Provider
inherited, #provider_name, #valid?
Constructor Details
#initialize ⇒ NineGag
Returns a new instance of NineGag.
8 9 10 |
# File 'lib/thornbed/providers/9gag.rb', line 8 def initialize self.pattern = /^http(s)?:\/\/(\w+\.)?(9gag\.com\/|d24w6bsrhbeh9d\.cloudfront\.net\/photo\/)(gag\/|fast#)?(\d+)(\?[\w=]+)?(_\d+b\.jpg)?$/ end |
Instance Attribute Details
#pattern ⇒ Object
Returns the value of attribute pattern.
6 7 8 |
# File 'lib/thornbed/providers/9gag.rb', line 6 def pattern @pattern end |
Instance Method Details
#get(url) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/thornbed/providers/9gag.rb', line 12 def get(url) raise Thornbed::NotValid, url if !valid?(url) url = URI.parse(url) ptype = "jpg" pic_id = url.path == '/fast' ? url.fragment : /(\d+)/.match(url.path)[0] { url: "http://d24w6bsrhbeh9d.cloudfront.net/photo/#{pic_id}_700b.#{ptype}", type: "photo", provider_name: provider_name, provider_url: "http://9gag.com", thumbnail_url: "http://d24w6bsrhbeh9d.cloudfront.net/photo/#{pic_id}_fbthumbnail.#{ptype}", version: "1.0", page: "http://9gag.com/gag/#{pic_id}", width: nil, height: nil } end |