eve_gate 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+ test.rb
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Dominik Sander
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,44 @@
1
+ # eve_gate: A Ruby interface to EVE Gate
2
+
3
+ ## Disclaimer
4
+
5
+ I wrote the library for educational purposes only!
6
+ CCP Karuck stated that "Crawling EVE Gate is forbidden as part of our soon to be updated Terms of Service, and can be a basis for an account ban.", even though eve_gate does not support crawling - it just *uses* the site as a normal user would do - do not use it unless you are willing to risk your account.
7
+
8
+ Furthermore it would be nice to get statement from CCP if viewing and writing evemails is considered "crawling".
9
+
10
+ I hope that CCP will actually release a complete eve mail api with write support, so there is no need for this library anymore.
11
+
12
+ ## Installation
13
+
14
+ sudo gem install eve_gate
15
+
16
+ ## Usage
17
+
18
+ require 'eve_gate'
19
+ g = EveGate.new('username', 'password', 'character')
20
+
21
+ g.send_mail('Makurid', 'eve_gate', 'rocksalot!')
22
+
23
+ puts g.eve_mails.first.body
24
+ puts g.alliance_mails.first.body
25
+ puts g.corporation_mails.first.body
26
+
27
+ ## Note on Patches/Pull Requests
28
+
29
+ * Fork the project.
30
+ * Make your feature addition or bug fix.
31
+ * Add tests for it. This is important so I don't break it in a
32
+ future version unintentionally.
33
+ * Commit, do not mess with rakefile, version, or history.
34
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
35
+ * Send me a pull request. Bonus points for topic branches.
36
+
37
+ ## Copyright
38
+
39
+ Copyright (c) 2010 Dominik Sander.
40
+
41
+ eve_gate is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
42
+ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
43
+ See the GNU General Public License for more details.
44
+
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "eve_gate"
8
+ gem.summary = %Q{A Ruby interface to EVE Gate}
9
+ gem.description = %Q{A Ruby interface to EVE Gate}
10
+ gem.email = "git@dsander.de"
11
+ gem.homepage = "http://github.com/dsander/eve_gate"
12
+ gem.authors = ["Dominik Sander"]
13
+ gem.add_dependency "mechanize", ">= 1.0.0"
14
+ gem.add_dependency "activesupport"
15
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ require 'rake/testtask'
24
+ Rake::TestTask.new(:test) do |test|
25
+ test.libs << 'lib' << 'test'
26
+ test.pattern = 'test/**/test_*.rb'
27
+ test.verbose = true
28
+ end
29
+
30
+ begin
31
+ require 'rcov/rcovtask'
32
+ Rcov::RcovTask.new do |test|
33
+ test.libs << 'test'
34
+ test.pattern = 'test/**/test_*.rb'
35
+ test.verbose = true
36
+ end
37
+ rescue LoadError
38
+ task :rcov do
39
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
40
+ end
41
+ end
42
+
43
+ task :test => :check_dependencies
44
+
45
+ task :default => :test
46
+
47
+ require 'rake/rdoctask'
48
+ Rake::RDocTask.new do |rdoc|
49
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "eve_gate #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,134 @@
1
+ require "active_support"
2
+ require "mechanize"
3
+ require 'openssl'
4
+
5
+ class EveGate
6
+ class Mail
7
+ attr_accessor :receipient, :subject, :read
8
+ #attr_writer :body, :sender, :to
9
+ def initialize(mail, agent)
10
+ @read = mail.children[2].children[1].attributes['alt'].text == 'Read'
11
+ @sender = mail.children[4].children[1].text.strip
12
+ @subject = mail.children[6].children[1].children[1].text
13
+ @url = mail.children[6].children[1].children[1].attributes['href'].value
14
+ @date = DateTime.parse(mail.children[8].text).to_time
15
+ @agent = agent
16
+ end
17
+
18
+ def body
19
+ update_details unless @body
20
+ @body
21
+ end
22
+
23
+ def sender
24
+ update_details unless @sender
25
+ @sender
26
+ end
27
+
28
+ def to
29
+ update_details unless @to
30
+ @to
31
+ end
32
+
33
+ def update_details
34
+ @agent.get(@url)
35
+ @body = @agent.page.search(".//div[@id='hideBottomButtons']/p")[1].inner_html
36
+ @to = @agent.page.search(".//div[@id='hideBottomButtons']/p[1]/a")[1].text
37
+ @sender = @agent.page.search(".//div[@id='hideBottomButtons']/p[1]/a")[0].text
38
+ end
39
+ end
40
+
41
+ def initialize(user, pass, character)
42
+ @user = user
43
+ @pass = pass
44
+ @character = character
45
+ @agent = Mechanize.new
46
+ @page = nil
47
+ @characters = {}
48
+ login
49
+ end
50
+
51
+ def login
52
+ begin
53
+ @page = @agent.get('https://www.evegate.com/')
54
+ rescue Mechanize::ResponseCodeError
55
+ puts "EveGate is currently not available."
56
+ exit -1
57
+ end
58
+
59
+ login_form = @page.form_with(:action => "/LogOn/Logon")
60
+ login_form['username'] = @user
61
+ login_form['password'] = @pass
62
+ @agent.submit(login_form, login_form.button_with(:value => 'Log On'))
63
+
64
+ if error = @agent.page.search(".//ul[@class='logOnErrorMessages']/li")
65
+ if error.text.include? 'EVE Gate is currently not accepting new logins'
66
+ puts "EVE Gate is currently not accepting new logins"
67
+ exit -1
68
+ end
69
+ end
70
+
71
+ if @agent.page.links_with(:href => /\/Account\/SwitchCharacter\?characterName=#{@character.gsub(' ', '%20')}/).length != 0
72
+ puts "switch char"
73
+ @agent.page.links_with(:href => /\/Account\/SwitchCharacter\?characterName=#{@character.gsub(' ', '%20')}/)[0].click
74
+ end
75
+ if @agent.page.links_with(:href => /\/Account\/LogOnCharacter\?characterName=#{@character.gsub(' ', '%20')}/).length != 0
76
+ puts "logong char"
77
+ @agent.page.links_with(:href => /\/Account\/LogOnCharacter\?characterName=#{@character.gsub(' ', '%20')}/)[0].click
78
+ end
79
+ if @character != current_character
80
+ raise "Could not select #{@character}."
81
+ end
82
+ end
83
+
84
+ def eve_mails
85
+ @agent.get('/Mail/Inbox')
86
+ parse_mails
87
+ end
88
+
89
+ def corporation_mails
90
+ @agent.get('/Mail/Corp')
91
+ parse_mails
92
+ end
93
+
94
+ def alliance_mails
95
+ @agent.get('/Mail/Alliance')
96
+ parse_mails
97
+ end
98
+
99
+ def send_mail(to, subject, text)
100
+ @agent.get('/Mail/Compose')
101
+ mail_form = @agent.page.forms_with(:action => "/Mail/SendMessage").first
102
+ mail_form['recipientLine'] = to
103
+ mail_form['subject'] = subject
104
+ mail_form['message'] = text
105
+ mail_form['mailContents'] = text
106
+ @agent.submit(mail_form, mail_form.button_with(:value => 'Send'))
107
+
108
+ @agent.page.code == "200"
109
+ end
110
+
111
+ def current_character
112
+ begin
113
+ c1 = @agent.page.search(".//div[@id='activeCharacterContent']/div/div/h1").text
114
+ return c1 if c1 != ""
115
+ c2 = @agent.page.search(".//div[@id='sectionHeaderContainer']/div/span").text.gsub(' Contacts Chatter','')
116
+ return c2 if c2 != ""
117
+ rescue
118
+ raise "Error getting current character."
119
+ end
120
+ end
121
+
122
+ private
123
+ def dump_page
124
+ File.open('page', 'w') { |f| f.write @agent.page.parser }
125
+ end
126
+
127
+ def parse_mails
128
+ mails = []
129
+ @agent.page.search(".//table[@id='mailTable']/tbody/tr").each do |mail|
130
+ mails << Mail.new(mail, @agent)
131
+ end
132
+ mails
133
+ end
134
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'eve_gate'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestEveGate < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eve_gate
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Dominik Sander
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-27 00:00:00 +00:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: mechanize
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 0
30
+ - 0
31
+ version: 1.0.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: activesupport
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: thoughtbot-shoulda
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ type: :development
57
+ version_requirements: *id003
58
+ description: A Ruby interface to EVE Gate
59
+ email: git@dsander.de
60
+ executables: []
61
+
62
+ extensions: []
63
+
64
+ extra_rdoc_files:
65
+ - LICENSE
66
+ - README.markdown
67
+ files:
68
+ - .document
69
+ - .gitignore
70
+ - LICENSE
71
+ - README.markdown
72
+ - Rakefile
73
+ - VERSION
74
+ - lib/eve_gate.rb
75
+ - test/helper.rb
76
+ - test/test_eve_gate.rb
77
+ has_rdoc: true
78
+ homepage: http://github.com/dsander/eve_gate
79
+ licenses: []
80
+
81
+ post_install_message:
82
+ rdoc_options:
83
+ - --charset=UTF-8
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ requirements: []
101
+
102
+ rubyforge_project:
103
+ rubygems_version: 1.3.6
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: A Ruby interface to EVE Gate
107
+ test_files:
108
+ - test/helper.rb
109
+ - test/test_eve_gate.rb