Sha256: 30a15ea7f0d576e7f47e00a3074c3bf14de3153c4dadee65e18d08a591a2e19b
Contents?: true
Size: 1.05 KB
Versions: 26
Compression:
Stored size: 1.05 KB
Contents
=begin rdoc = IMGUR.RB *Author*:: Tamara Temple <tamara@tamaratemple.com> *Since*:: 2013-05-27 *Copyright*:: (c) 2013 Tamara Temple Web Development *License*:: MIT =end module Scrapers IMGUR_TEMPLATE="http://imgur.com/path" class Imgur attr_accessor :agent, :url, :download, :page def initialize @agent = Mechanize.new @url = URI.parse(IMGUR_TEMPLATE) @download = URI.parse(IMGUR_TEMPLATE) end def download_link(code) make_url(code) retrieve_page() find_download() @download.to_s end def make_url(imgur_code) @url.path = "/#{imgur_code}" end def retrieve_page() @page = @agent.get(@url.to_s) end def find_download(link_text=/Download/) link = @page.link_with(:text => link_text) raise "#{link_text} not found on #{@page.uri.to_s}" if link.nil? @download.path = link.href end end module_function def imgur(url) code = File.basename(url).sub(/\.[^.]+$/,'') "http://imgur.com/download/#{code}/" end end
Version data entries
26 entries across 26 versions & 1 rubygems