Class: Thornbed::Providers::NineGag

Inherits:
Provider
  • Object
show all
Defined in:
lib/thornbed/providers/9gag.rb

Constant Summary

Constants inherited from Provider

Provider::USER_AGENT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Provider

inherited, #provider_name, #valid?

Constructor Details

#initializeNineGag

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

#patternObject

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

Raises:



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