module Hermaeus

Public: Root module for Hermaeus.

Hermaeus’ top-level methods provide the interface used by `mora`.

Constants

VERSION

Public Class Methods

connect() click to toggle source

Public: Connects Hermaeus to reddit.

# File lib/hermaeus.rb, line 46
def self.connect
        @client = Client.new
end
help() click to toggle source

Public: Print usage information for `mora`.

`mora` may not know where Hermaeus is installed, so Hermaeus has to load the help file for it.

# File lib/hermaeus.rb, line 68
def self.help
        File.open File.join(File.dirname(__FILE__), "..", "data", "usage.txt") do |f|
                puts f.read
        end
end
init() click to toggle source

Public: Initializes Hermaeus for use.

Raises a ConfigurationError if Hermaeus’ config file does not exist, and creates a sample configuration file for modification.

# File lib/hermaeus.rb, line 18
        def self.init
                FileUtils.mkdir_p(Config::DIR)
                if File.exist? Config::FILE
                        Config.load
                        begin
                                Config.validate!
                        rescue ConfigurationError => e
                                puts <<-EOS
#{e.message}

Edit your configuration file (#{File.join Config::DIR, "config.toml"}) to \
continue.
                                EOS
                        end
                else
                        File.open Config::FILE, "w+" do |file|
                                File.open File.expand_path(Config::SOURCE), "r", 0600 do |cfg|
                                        file << cfg.read
                                end
                        end
                        raise ConfigurationError.new <<-EOS
You must put your reddit credentials in #{File.join Config::DIR,"config.toml"} \
for Hermaeus to function.
                        EOS
                end
        end
seek(type, ids, &block) click to toggle source

Public: Downloads Apocrypha posts.

type - “index” or “com” ids - A list of thread IDs to access and scrape, if type is “com”

# File lib/hermaeus.rb, line 54
def self.seek type, ids, &block
        if type == "index"
                list = @client.get_global_listing
        elsif type == "com"
                list = @client.get_weekly_listing ids
        end
        ids = @client.get_fullnames list
        posts = @client.get_posts ids, &block
end