Class: EveGate
- Inherits:
-
Object
- Object
- EveGate
- Defined in:
- lib/eve_gate.rb
Defined Under Namespace
Classes: Mail
Instance Method Summary collapse
- #alliance_mails ⇒ Object
- #corporation_mails ⇒ Object
- #current_character ⇒ Object
- #eve_mails ⇒ Object
-
#initialize(user, pass, character) ⇒ EveGate
constructor
A new instance of EveGate.
- #login ⇒ Object
- #send_mail(to, subject, text) ⇒ Object
Constructor Details
#initialize(user, pass, character) ⇒ EveGate
Returns a new instance of EveGate.
41 42 43 44 45 46 47 48 49 |
# File 'lib/eve_gate.rb', line 41 def initialize(user, pass, character) @user = user @pass = pass @character = character @agent = Mechanize.new @page = nil @characters = {} login end |
Instance Method Details
#alliance_mails ⇒ Object
94 95 96 97 |
# File 'lib/eve_gate.rb', line 94 def alliance_mails @agent.get('/Mail/Alliance') parse_mails end |
#corporation_mails ⇒ Object
89 90 91 92 |
# File 'lib/eve_gate.rb', line 89 def corporation_mails @agent.get('/Mail/Corp') parse_mails end |
#current_character ⇒ Object
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/eve_gate.rb', line 111 def current_character begin c1 = @agent.page.search(".//div[@id='activeCharacterContent']/div/div/h1").text return c1 if c1 != "" c2 = @agent.page.search(".//div[@id='sectionHeaderContainer']/div/span").text.gsub(' Contacts Chatter','') return c2 if c2 != "" rescue raise "Error getting current character." end end |
#eve_mails ⇒ Object
84 85 86 87 |
# File 'lib/eve_gate.rb', line 84 def eve_mails @agent.get('/Mail/Inbox') parse_mails end |
#login ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/eve_gate.rb', line 51 def login begin @page = @agent.get('https://www.evegate.com/') rescue Mechanize::ResponseCodeError puts "EveGate is currently not available." exit -1 end login_form = @page.form_with(:action => "/LogOn/Logon") login_form['username'] = @user login_form['password'] = @pass @agent.submit(login_form, login_form.(:value => 'Log On')) if error = @agent.page.search(".//ul[@class='logOnErrorMessages']/li") if error.text.include? 'EVE Gate is currently not accepting new logins' puts "EVE Gate is currently not accepting new logins" exit -1 end end if @agent.page.links_with(:href => /\/Account\/SwitchCharacter\?characterName=#{@character.gsub(' ', '%20')}/).length != 0 puts "switch char" @agent.page.links_with(:href => /\/Account\/SwitchCharacter\?characterName=#{@character.gsub(' ', '%20')}/)[0].click end if @agent.page.links_with(:href => /\/Account\/LogOnCharacter\?characterName=#{@character.gsub(' ', '%20')}/).length != 0 puts "logong char" @agent.page.links_with(:href => /\/Account\/LogOnCharacter\?characterName=#{@character.gsub(' ', '%20')}/)[0].click end if @character != current_character raise "Could not select #{@character}." end end |
#send_mail(to, subject, text) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/eve_gate.rb', line 99 def send_mail(to, subject, text) @agent.get('/Mail/Compose') mail_form = @agent.page.forms_with(:action => "/Mail/SendMessage").first mail_form['recipientLine'] = to mail_form['subject'] = subject mail_form['message'] = text mail_form['mailContents'] = text @agent.submit(mail_form, mail_form.(:value => 'Send')) @agent.page.code == "200" end |