Class: FAMailer
- Inherits:
-
Object
- Object
- FAMailer
- Defined in:
- lib/famailer.rb
Constant Summary collapse
- VERSION =
"0.0.3"
- 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.
8 9 10 11 12 |
# File 'lib/famailer.rb', line 8 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
47 48 49 50 51 52 |
# File 'lib/famailer.rb', line 47 def { "a" => @fa_cookie_a, "b" => @fa_cookie_b } end |
#form ⇒ Object
35 36 37 |
# File 'lib/famailer.rb', line 35 def form @form ||= .css("#MsgForm").first end |
#key ⇒ Object
31 32 33 |
# File 'lib/famailer.rb', line 31 def key @key ||= form.css("input[name=key]").first['value'] end |
#messages_page ⇒ Object
39 40 41 |
# File 'lib/famailer.rb', line 39 def @messages_page ||= Nokogiri::HTML(site["/msg/pms"].get.body) end |
#send!(recipient, subject, message, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/famailer.rb', line 14 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
43 44 45 |
# File 'lib/famailer.rb', line 43 def site @site ||= RestClient::Resource.new(HOST, cookies: ) end |