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
-
.connect ⇒ Object
Public: Connects Hermaeus to reddit.
-
.help ⇒ Object
Public: Print usage information for ‘mora`.
-
.init ⇒ Object
Public: Initializes Hermaeus for use.
-
.seek(type, ids, &block) ⇒ Object
Public: Downloads Apocrypha posts.
Class Method Details
.connect ⇒ Object
Public: Connects Hermaeus to reddit.
46 47 48 |
# File 'lib/hermaeus.rb', line 46 def self.connect @client = Client.new end |
.help ⇒ Object
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 |
.init ⇒ Object
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 <<-EOS #{e.} 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.(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) ⇒ 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 |