eve-api 0.0.1 → 0.0.5

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.
data/History.txt ADDED
@@ -0,0 +1,36 @@
1
+ == 0.0.5 2007-06-26
2
+
3
+ * Enhancements
4
+ * None
5
+ * Fixes
6
+ * Fixed Transport debugging support
7
+
8
+ == 0.0.4 2007-06-26
9
+
10
+ * Enhancements
11
+ * Added debug option to Transport layer
12
+ * Fixes
13
+ * None
14
+
15
+ == 0.0.3 2007-06-26
16
+
17
+ * Enhancements
18
+ * None
19
+ * Fixes
20
+ * Renamed Character::attributes to Character:: skills to be friendlier (though slightly less accurate)
21
+
22
+ == 0.0.2 2007-06-26
23
+
24
+ * Enhancements
25
+ * Reworked gem infrastructure
26
+ * Completed objectiness(tm)
27
+ * Added unit tests
28
+ * Fixes
29
+ * None
30
+
31
+ == 0.0.1 2007-06-22
32
+
33
+ * Enhancements
34
+ * Initial release
35
+ * Fixes
36
+ * None
data/License.txt ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2007 David Dollar
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,21 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ lib/eve-api.rb
7
+ lib/eve-api/common.rb
8
+ lib/eve-api/eve-api.rb
9
+ lib/eve-api/exceptions.rb
10
+ lib/eve-api/transport.rb
11
+ lib/eve-api/version.rb
12
+ scripts/txt2html
13
+ setup.rb
14
+ test/config.yml.dist
15
+ test/test_eve-api.rb
16
+ test/test_helper.rb
17
+ website/index.html
18
+ website/index.txt
19
+ website/javascripts/rounded_corners_lite.inc.js
20
+ website/stylesheets/screen.css
21
+ website/template.rhtml
data/README.txt ADDED
@@ -0,0 +1,33 @@
1
+ Eve API Support
2
+ ===============
3
+
4
+ Some docs will go here. See tests/general.rb for usage examples
5
+
6
+ Run general.rb using the following command:
7
+ cd lib && ruby ../tests/general.rb
8
+
9
+ Basic example:
10
+
11
+ require 'eve-api'
12
+
13
+ api = EveAPI::API.new(:id => 'user id', :api_key => 'api key')
14
+ api.users.each do |user|
15
+ user.characters.each do |character|
16
+ character.accounts.each do |account|
17
+ account.transactions.each do |transaction|
18
+ puts "transaction: #{transaction.id} [date=#{transaction.date.strftime("%Y-%m-%d %H:%m")}]"
19
+ end
20
+ account.journal.each do |entry|
21
+ puts "journal entry: #{entry.id} [balance=#{entry.balance}]"
22
+ end
23
+ end
24
+ character.corporation.members.each do |member|
25
+ puts "corp member: #{member.id} [name=#{member.name}]"
26
+ end
27
+ character.corporation.accounts.each do |account|
28
+ account.transactions.each do |transaction|
29
+ puts "corp transaction: #{transaction.id} [date=#{transaction.date.strftime("%Y-%m-%d %H:%m")}]"
30
+ end
31
+ end
32
+ end
33
+ end
data/Rakefile ADDED
@@ -0,0 +1,123 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/rdoctask'
8
+ require 'rake/contrib/rubyforgepublisher'
9
+ require 'fileutils'
10
+ require 'hoe'
11
+
12
+ include FileUtils
13
+ require File.join(File.dirname(__FILE__), 'lib', 'eve-api', 'version')
14
+
15
+ AUTHOR = 'David Dollar' # can also be an array of Authors
16
+ EMAIL = "ddollar@gmail.com"
17
+ DESCRIPTION = "EVE API Support"
18
+ GEM_NAME = 'eve-api' # what ppl will type to install your gem
19
+
20
+ @config_file = "~/.rubyforge/user-config.yml"
21
+ @config = nil
22
+ def rubyforge_username
23
+ unless @config
24
+ begin
25
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
26
+ rescue
27
+ puts <<-EOS
28
+ ERROR: No rubyforge config file found: #{@config_file}"
29
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
30
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
31
+ EOS
32
+ exit
33
+ end
34
+ end
35
+ @rubyforge_username ||= @config["username"]
36
+ end
37
+
38
+ RUBYFORGE_PROJECT = 'eve-api' # The unix name for your project
39
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
40
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
41
+
42
+ NAME = "eve-api"
43
+ REV = nil
44
+ # UNCOMMENT IF REQUIRED:
45
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
46
+ VERS = EveAPI::VERSION::STRING + (REV ? ".#{REV}" : "")
47
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store']
48
+ RDOC_OPTS = ['--quiet', '--title', 'eve-api documentation',
49
+ "--opname", "index.html",
50
+ "--line-numbers",
51
+ "--main", "README",
52
+ "--inline-source"]
53
+
54
+ class Hoe
55
+ def extra_deps
56
+ @extra_deps.reject { |x| Array(x).first == 'hoe' }
57
+ end
58
+ end
59
+
60
+ # Generate all the Rake tasks
61
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
62
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
63
+ p.author = AUTHOR
64
+ p.description = DESCRIPTION
65
+ p.email = EMAIL
66
+ p.summary = DESCRIPTION
67
+ p.url = HOMEPATH
68
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
69
+ p.test_globs = ["test/**/test_*.rb"]
70
+ p.clean_globs |= CLEAN #An array of file patterns to delete on clean.
71
+
72
+ # == Optional
73
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
74
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
75
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
76
+ end
77
+
78
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\n\n")
79
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
80
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
81
+
82
+ desc 'Generate website files'
83
+ task :website_generate do
84
+ Dir['website/**/*.txt'].each do |txt|
85
+ sh %{ ruby scripts/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
86
+ end
87
+ end
88
+
89
+ desc 'Upload website files to rubyforge'
90
+ task :website_upload do
91
+ host = "#{rubyforge_username}@rubyforge.org"
92
+ remote_dir = "/var/www/gforge-projects/#{PATH}/"
93
+ local_dir = 'website'
94
+ sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
95
+ end
96
+
97
+ desc 'Generate and upload website files'
98
+ task :website => [:website_generate, :website_upload, :publish_docs]
99
+
100
+ desc 'Release the website and new gem version'
101
+ task :deploy => [:check_version, :website, :release] do
102
+ puts "Remember to create SVN tag:"
103
+ puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
104
+ "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
105
+ puts "Suggested comment:"
106
+ puts "Tagging release #{CHANGES}"
107
+ end
108
+
109
+ desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
110
+ task :local_deploy => [:website_generate, :install_gem]
111
+
112
+ task :check_version do
113
+ unless ENV['VERSION']
114
+ puts 'Must pass a VERSION=x.y.z release version'
115
+ exit
116
+ end
117
+ unless ENV['VERSION'] == VERS
118
+ puts "Please update your version.rb to match the release version, currently #{VERS}"
119
+ exit
120
+ end
121
+ end
122
+
123
+
data/lib/eve-api.rb CHANGED
@@ -1,5 +1,7 @@
1
- require 'pp'
1
+ module EveAPI
2
+ end
2
3
 
4
+ require 'eve-api/version'
3
5
  require 'eve-api/common'
4
6
  require 'eve-api/exceptions'
5
7
  require 'eve-api/transport'
@@ -67,6 +67,33 @@ module EveAPI
67
67
  end
68
68
  return characters
69
69
  end
70
+ def skill_tree
71
+ groups = []
72
+ skills = {}
73
+ skilltree = @api.skilltree
74
+ skilltree[:groups].each do |raw_group_id, raw_group|
75
+ group_skills = {}
76
+ skilltree[:skills].each do |raw_skill_id, raw_skill|
77
+ group_skills[raw_skill_id] = Skill.new(raw_skill, @api) if raw_skill[:group_id] == raw_group_id
78
+ end
79
+ groups << SkillGroup.new(raw_group.merge({:skills => group_skills}), @api)
80
+ end
81
+ return groups
82
+ end
83
+ def sovereignty
84
+ systems = {}
85
+ @api.sovereignty.each do |raw_system_id, raw_system|
86
+ systems[raw_system_id] = System.new(raw_system, @api)
87
+ end
88
+ return systems
89
+ end
90
+ def ref_types
91
+ ref_types = {}
92
+ @api.reftypes.each do |raw_reftype_id, raw_reftype|
93
+ ref_types[raw_reftype_id] = ReferenceType.new(raw_reftype, @api)
94
+ end
95
+ return ref_types
96
+ end
70
97
  end
71
98
 
72
99
  class Character < Base
@@ -80,6 +107,12 @@ module EveAPI
80
107
  end
81
108
  return accounts
82
109
  end
110
+ def skill_in_training
111
+ return SkillInTraining.new(@api.skill_in_training(id), @api)
112
+ end
113
+ def skills
114
+ return CharacterSkills.new(@api.skills(id), @api)
115
+ end
83
116
  end
84
117
 
85
118
  class Corporation < Base
@@ -135,4 +168,22 @@ module EveAPI
135
168
  class Member < Base
136
169
  end
137
170
 
171
+ class SkillGroup < Base
172
+ end
173
+
174
+ class Skill < Base
175
+ end
176
+
177
+ class SkillInTraining < Base
178
+ end
179
+
180
+ class CharacterSkills < Base
181
+ end
182
+
183
+ class System < Base
184
+ end
185
+
186
+ class ReferenceType < Base
187
+ end
188
+
138
189
  end
@@ -93,7 +93,7 @@ module EveAPI
93
93
 
94
94
  def skilltree
95
95
  result = {
96
- :skillgroups => {},
96
+ :groups => {},
97
97
  :skills => {}
98
98
  }
99
99
  doc = @transport.call('eve/SkillTree.xml.aspx')
@@ -106,6 +106,7 @@ module EveAPI
106
106
  row.each_element('rowset[@name="skills"]/row') do |skill_row|
107
107
  skill = {
108
108
  :id => skill_row.attributes['typeID'].to_i,
109
+ :group_id => skill_row.attributes['groupID'].to_i,
109
110
  :name => skill_row.attributes['typeName'],
110
111
  :rank => skill_row.elements['rank'].text.to_i,
111
112
  :description => skill_row.elements['description'].text
@@ -119,8 +120,7 @@ module EveAPI
119
120
  result[:skills][skill[:id]] = skill
120
121
  end
121
122
  skillgroup[:skills] = skills
122
- result[:skillgroups][skillgroup[:id]] = skillgroup
123
- break
123
+ result[:groups][skillgroup[:id]] = skillgroup
124
124
  end
125
125
  return result
126
126
  end
@@ -257,20 +257,20 @@ module EveAPI
257
257
  EVE_API_URI_BASE = "http://api.eve-online.com/"
258
258
 
259
259
  def initialize(*args)
260
- options = extract_options_from_args!(args)
260
+ @options = extract_options_from_args!(args)
261
261
  @base_params = {}
262
- @base_params[:userID] = options[:id] or raise Exceptions::OptionsException, "id is missing"
263
- @base_params[:apiKey] = options[:api_key] or raise Exceptions::OptionsException, "api_key is missing"
264
- @base_params[:betaAccess] = options[:beta_key] if options[:beta_key]
262
+ @base_params[:userID] = @options[:id] or raise Exceptions::OptionsException, "id is missing"
263
+ @base_params[:apiKey] = @options[:api_key] or raise Exceptions::OptionsException, "api_key is missing"
264
+ @base_params[:betaAccess] = @options[:beta_key] if @options[:beta_key]
265
265
  end
266
266
 
267
267
  def call(uri, *args)
268
268
  params = extract_options_from_args!(args).merge(@base_params)
269
- #pp params
269
+ pp params if @options[:debug]
270
270
  res = Net::HTTP.post_form(URI.parse("#{EVE_API_URI_BASE}#{uri}"), params)
271
271
  xml = '<?xml version="1.0"?>' + res.body
272
272
  doc = REXML::Document.new(xml)
273
- #puts doc
273
+ puts doc if @options[:debug]
274
274
  if error = doc.elements['//error']
275
275
  case error.attributes['code'][0,1]
276
276
  when '1': raise Exceptions::InputException, error.text
@@ -0,0 +1,9 @@
1
+ module EveAPI #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 5
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
data/scripts/txt2html ADDED
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'redcloth'
5
+ require 'syntax/convertors/html'
6
+ require 'erb'
7
+ require File.dirname(__FILE__) + '/../lib/eve-api/version.rb'
8
+
9
+ version = EveAPI::VERSION::STRING
10
+ download = 'http://rubyforge.org/projects/eve-api'
11
+
12
+ class Fixnum
13
+ def ordinal
14
+ # teens
15
+ return 'th' if (10..19).include?(self % 100)
16
+ # others
17
+ case self % 10
18
+ when 1: return 'st'
19
+ when 2: return 'nd'
20
+ when 3: return 'rd'
21
+ else return 'th'
22
+ end
23
+ end
24
+ end
25
+
26
+ class Time
27
+ def pretty
28
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
29
+ end
30
+ end
31
+
32
+ def convert_syntax(syntax, source)
33
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
34
+ end
35
+
36
+ if ARGV.length >= 1
37
+ src, template = ARGV
38
+ template ||= File.dirname(__FILE__) + '/../website/template.rhtml'
39
+
40
+ else
41
+ puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
42
+ exit!
43
+ end
44
+
45
+ template = ERB.new(File.open(template).read)
46
+
47
+ title = nil
48
+ body = nil
49
+ File.open(src) do |fsrc|
50
+ title_text = fsrc.readline
51
+ body_text = fsrc.read
52
+ syntax_items = []
53
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</>!m){
54
+ ident = syntax_items.length
55
+ element, syntax, source = $1, $2, $3
56
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
57
+ "syntax-temp-#{ident}"
58
+ }
59
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
60
+ body = RedCloth.new(body_text).to_html
61
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
62
+ end
63
+ stat = File.stat(src)
64
+ created = stat.ctime
65
+ modified = stat.mtime
66
+
67
+ $stdout << template.result(binding)