Class: Mailfire::TextToRoom
- Inherits:
-
Object
- Object
- Mailfire::TextToRoom
- Defined in:
- lib/mailfire.rb
Instance Attribute Summary collapse
-
#campfire ⇒ Object
readonly
Returns the value of attribute campfire.
-
#config ⇒ Object
Returns the value of attribute config.
-
#rooms ⇒ Object
readonly
Returns the value of attribute rooms.
Instance Method Summary collapse
- #connect_to_campfire ⇒ Object
- #deliver!(mail) ⇒ Object
-
#initialize(opts = {}) ⇒ TextToRoom
constructor
A new instance of TextToRoom.
- #select_rooms ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ TextToRoom
Returns a new instance of TextToRoom.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mailfire.rb', line 12 def initialize(opts={}) @config = opts if opts[:room] @config[:rooms] = [opts[:room]] end @config[:rooms].map!(&:downcase) raise ArgumentError, 'No :account provided' if @config[:account].nil? raise ArgumentError, 'No :token provided' if @config[:token].nil? if @config[:rooms].nil? or @config[:rooms].empty? raise ArgumentError, 'No :room or :rooms provided' end connect_to_campfire select_rooms end |
Instance Attribute Details
#campfire ⇒ Object (readonly)
Returns the value of attribute campfire.
9 10 11 |
# File 'lib/mailfire.rb', line 9 def campfire @campfire end |
#config ⇒ Object
Returns the value of attribute config.
10 11 12 |
# File 'lib/mailfire.rb', line 10 def config @config end |
#rooms ⇒ Object (readonly)
Returns the value of attribute rooms.
9 10 11 |
# File 'lib/mailfire.rb', line 9 def rooms @rooms end |
Instance Method Details
#connect_to_campfire ⇒ Object
29 30 31 |
# File 'lib/mailfire.rb', line 29 def connect_to_campfire @campfire = Tinder::Campfire.new @config[:account], token: @config[:token] end |
#deliver!(mail) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/mailfire.rb', line 39 def deliver!(mail) @rooms.each do |room| room.speak "To: #{mail.to}, From: #{mail.from}" room.speak mail.subject if mail.multipart? room.paste mail.text_part.to_s else room.paste mail.body end end end |
#select_rooms ⇒ Object
33 34 35 36 37 |
# File 'lib/mailfire.rb', line 33 def select_rooms @rooms = @campfire.rooms.select do |room| @config[:rooms].include? room.name.downcase end end |