Class: EveGate

Inherits:
Object
  • Object
show all
Defined in:
lib/eve_gate.rb

Defined Under Namespace

Classes: Mail

Instance Method Summary collapse

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 = {}
  
end

Instance Method Details

#alliance_mailsObject



94
95
96
97
# File 'lib/eve_gate.rb', line 94

def alliance_mails
  @agent.get('/Mail/Alliance')
  parse_mails
end

#corporation_mailsObject



89
90
91
92
# File 'lib/eve_gate.rb', line 89

def corporation_mails
  @agent.get('/Mail/Corp')
  parse_mails
end

#current_characterObject



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_mailsObject



84
85
86
87
# File 'lib/eve_gate.rb', line 84

def eve_mails
  @agent.get('/Mail/Inbox')
  parse_mails
end

#loginObject



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 
  begin
    @page = @agent.get('https://www.evegate.com/')
  rescue Mechanize::ResponseCodeError
    puts "EveGate is currently not available."
    exit -1
  end
  
   = @page.form_with(:action => "/LogOn/Logon")
  ['username'] = @user
  ['password'] = @pass
  @agent.submit(, .button_with(: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.button_with(:value => 'Send'))
  
  @agent.page.code == "200"
end