Class: FAMailer
- Inherits:
-
Object
- Object
- FAMailer
- Defined in:
- lib/famailer.rb
Constant Summary collapse
- VERSION =
"0.0.2"
- HOST =
"http://furaffinity.net"
Instance Method Summary collapse
- #cookies ⇒ Object
- #form ⇒ Object
-
#initialize(options = {}) ⇒ FAMailer
constructor
A new instance of FAMailer.
- #key ⇒ Object
- #messages_page ⇒ Object
- #send!(recipient, subject, message, options = {}) ⇒ Object
- #site ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ FAMailer
Returns a new instance of FAMailer.
9 10 11 12 13 |
# File 'lib/famailer.rb', line 9 def initialize( = {}) @fa_cookie_a = .delete(:fa_cookie_a) || ENV["FA_COOKIE_A"] @fa_cookie_b = .delete(:fa_cookie_b) || ENV["FA_COOKIE_B"] @debug = .delete(:debug) end |
Instance Method Details
#cookies ⇒ Object
48 49 50 51 52 53 |
# File 'lib/famailer.rb', line 48 def { "a" => @fa_cookie_a, "b" => @fa_cookie_b } end |
#form ⇒ Object
36 37 38 |
# File 'lib/famailer.rb', line 36 def form @form ||= .css("#MsgForm").first end |
#key ⇒ Object
32 33 34 |
# File 'lib/famailer.rb', line 32 def key @key ||= form.css("input[name=key]").first['value'] end |
#messages_page ⇒ Object
40 41 42 |
# File 'lib/famailer.rb', line 40 def @messages_page ||= Nokogiri::HTML(site["/msg/pms"].get.body) end |
#send!(recipient, subject, message, options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/famailer.rb', line 15 def send!(recipient, subject, , = {}) puts "#{subject} -> #{recipient}\n---\n#{}" if @debug site[form['action']].post({ key: key, to: recipient, subject: subject, message: }) do |response| if response.code == 301 response.follow_redirection do |response| puts "Message sent" if @debug && response.code == 302 end end end end |
#site ⇒ Object
44 45 46 |
# File 'lib/famailer.rb', line 44 def site @site ||= RestClient::Resource.new(HOST, cookies: ) end |