Module: Hermaeus

Defined in:
lib/hermaeus.rb,
lib/hermaeus/error.rb,
lib/hermaeus/client.rb,
lib/hermaeus/config.rb,
lib/hermaeus/version.rb,
lib/hermaeus/archivist.rb,
lib/hermaeus/apocryphon.rb

Overview

Public: Root module for Hermaeus.

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

Defined Under Namespace

Modules: Config Classes: Apocryphon, Archivist, Client, ConfigurationError

Constant Summary collapse

VERSION =
"1.1.0"

Class Method Summary collapse

Class Method Details

.connectObject

Public: Connects Hermaeus to reddit.



46
47
48
# File 'lib/hermaeus.rb', line 46

def self.connect
  @client = Client.new
end

.helpObject

Public: Print usage information for ‘mora`.

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



68
69
70
71
72
# 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

.initObject

Public: Initializes Hermaeus for use.

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



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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 "\#{e.message}\n\nEdit your configuration file (\#{File.join Config::DIR, \"config.toml\"}) to \\\ncontinue.\n      EOS\n    end\n  else\n    File.open Config::FILE, \"w+\" do |file|\n      File.open File.expand_path(Config::SOURCE), \"r\", 0600 do |cfg|\n        file << cfg.read\n      end\n    end\n    raise ConfigurationError.new <<-EOS\nYou must put your reddit credentials in \#{File.join Config::DIR,\"config.toml\"} \\\nfor Hermaeus to function.\n    EOS\n  end\nend\n"

.seek(type, ids, &block) ⇒ Object

Public: Downloads Apocrypha posts.

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



54
55
56
57
58
59
60
61
62
# 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