public
Description: Read an RSS feed (even HTTPS with authentication) and rebroadcast it to a Twitter account.
Clone URL: git://github.com/trak3r/rss2twitter.git
trak3r (author)
Wed Apr 30 07:07:04 -0700 2008
commit  149c7f9389a7c6d10d589d81409532f7f1212a10
tree    ff8d54d85e0b077ff068d6c2da8915d18ec43a78
parent  48eef21d8beec7ff101790ea83422f6a612b688b
rss2twitter / config.rb
100644 47 lines (34 sloc) 0.961 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
44
45
46
47
require 'yaml'
 
class Settings
  
  attr_reader :rss_url, :twitter_email, :twitter_password
  
  def initialize
    begin
      prefs = YAML::load_file("#{@@yaml_file_name}")
    rescue
      missing_or_empty_yaml
    end
 
    missing_or_empty_yaml unless prefs
 
    @twitter_email = yamlized(prefs,'twitter_email')
    @twitter_password = yamlized(prefs,'twitter_password')
    @rss_url = yamlized(prefs,'rss_url')
  end
 
  private
  
  @@yaml_file_name = 'rss2twitter.yml'
 
  def missing_or_empty_yaml
    print <<"EOF"
 
Please define a YAML file named #{@@yaml_file_name}
containing the following values:
 
twitter_email: 'yourtwitteremail@bla.com'
twitter_password: 'secret'
rss_url: 'https://username:password@yoursite.com/index.xml'
 
EOF
    exit
  end
 
  def yamlized(prefs,token)
    if prefs["#{token}"]
      return prefs["#{token}"]
    else
      raise "Please define \"#{token}\" in your YAML file."
    end
  end
end