Module: Caboodle

Defined in:
lib/caboodle/app.rb,
lib/caboodle/kit.rb,
lib/caboodle/config.rb,
lib/caboodle/scrape.rb,
lib/caboodle/command.rb,
lib/caboodle/kits/feed/feed.rb,
lib/caboodle/kits/page/page.rb,
lib/caboodle/kits/susy/susy.rb,
lib/caboodle/kits/flickr/flickr.rb,
lib/caboodle/kits/github/github.rb,
lib/caboodle/kits/tumblr/tumblr.rb,
lib/caboodle/kits/onepage/onepage.rb,
lib/caboodle/kits/skimmed/skimmed.rb,
lib/caboodle/kits/twitter/twitter.rb,
lib/caboodle/kits/typekit/typekit.rb,
lib/caboodle/kits/youtube/youtube.rb,
lib/caboodle/kits/debugger/debugger.rb,
lib/caboodle/kits/gravatar/gravatar.rb,
lib/caboodle/kits/identity/identity.rb,
lib/caboodle/kits/linkedin/linkedin.rb,
lib/caboodle/kits/posterous/posterous.rb,
lib/caboodle/kits/webmaster/webmaster.rb,
lib/caboodle/kits/carbonmade/carbonmade.rb,
lib/caboodle/kits/soundcloud/soundcloud.rb,
lib/caboodle/kits/googlelocal/googlelocal.rb

Defined Under Namespace

Modules: Command, Config Classes: About, Analytics, App, Beta, Carbonmade, Credits, Debugger, Disqus, Feed, FeedDetector, Flickr, FlickrAPI, Geo, Github, GithubAPI, Googlelocal, Gravatar, History, Identity, Jquery, Kit, Lastfm, LazyLoad, Linkedin, LinkedinAPI, Onepage, Page, Posterous, PosterousAPI, PosterousPost, PosterousPostNotFound, PosterousProblem, SEO, Skimmed, Soundcloud, SoundcloudAPI, Standard, Susy, Tumblr, Twitter, Typekit, Vimeo, Webmaster, Youtube

Constant Summary collapse

Kits =
[]
[]
Javascripts =
[]
Stylesheets =
[]
RSS =
[]
SASS =
[]
Errors =
[]
Debug =
[]
Defaults =
Hashie::Mash.new(Hashie::Mash.new(YAML.load_file(File.join(File.dirname(__FILE__), 'config','defaults.yml'))))
RequiredSettings =
Hashie::Mash.new()
OptionalSettings =
Hashie::Mash.new()
Layout =
Hashie::Mash.new()
Site =
Defaults.clone

Class Method Summary collapse

Class Method Details

.extract_feed(url) ⇒ Object



54
55
56
# File 'lib/caboodle/scrape.rb', line 54

def self.extract_feed url
  Caboodle::FeedDetector.fetch_feed_url url
end

.mash(req) ⇒ Object



50
51
52
# File 'lib/caboodle/scrape.rb', line 50

def self.mash req
  ::Hashie::Mash.new(req.perform_sleepily.parse)
end

.round_time(integer, factor) ⇒ Object



16
17
18
19
# File 'lib/caboodle/scrape.rb', line 16

def self.round_time(integer, factor)
  return integer if(integer % factor == 0)
  return integer - (integer % factor)
end

.scrape(url) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/caboodle/scrape.rb', line 21

def self.scrape url
  begin
    if defined?(CACHE)
      begin
        puts "Scraping with cache optimisation"
        timeout = 60*60*1000
        response = CACHE.get("#{round_time(Time.new.to_i, timeout)}:#{url}") rescue nil
        response ||= open(url).read
        CACHE.set("#{round_time(Time.new.to_i, timeout)}:#{url}", response)
        CACHE.set("0:#{url}", response)
      rescue
        # Probably a dead memcached server
        response = open(url).read
      end
    else
      puts "Scraping without cache optimisation"
      response = open(url).read
    end
    ::Nokogiri::HTML(response)
  rescue Exception => e
    puts e.inspect
    if defined?(CACHE)
      response = CACHE.get("0:#{url}")
    end
    response ||= ""
    ::Nokogiri::HTML(response)
  end
end