dsander-reve 0.0.132 → 0.0.133.pre

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,13 +1,7 @@
1
- STATS_DIRECTORIES = [
2
- %w(Libraries lib/),
3
- %w(tests test/)
4
- ]
5
-
6
1
  require 'rake'
7
2
  require 'rake/testtask'
8
3
  require 'rake/rdoctask'
9
4
 
10
-
11
5
  task :default => :redoc
12
6
 
13
7
  desc "Generate Docs"
@@ -21,40 +15,7 @@ Rake::RDocTask.new("doc") { |rdoc|
21
15
  rdoc.rdoc_files.include('test/**/*')
22
16
  }
23
17
 
24
- desc "Code Statistics"
25
- task :stats do
26
- require 'code_statistics'
27
- CodeStatistics.new(*STATS_DIRECTORIES).to_s
28
- end
29
-
30
- if File.exists?('.svn')
31
- require 'rubygems'
32
- require 'rake/packagetask'
33
- require 'rake/gempackagetask'
34
-
35
- REVE_RELEASE=`svn up &>/dev/null && svn info|grep ^Revision| cut -d ' ' -f 2`
36
-
37
- spec = Gem::Specification.new do |s|
38
- s.name = "reve"
39
- s.rubyforge_project = "reve"
40
- s.version = "0.0.#{REVE_RELEASE.chomp || '1'}"
41
- s.author = "Lisa Seelye"
42
- s.email = "lisa@thedoh.com"
43
- s.homepage = "http://revetrac.crudvision.com"
44
- s.platform = Gem::Platform::RUBY
45
- s.summary = "Reve is a Ruby library to interface with the Eve Online API"
46
- s.files = FileList["Rakefile","LICENSE", "lib/**/*.rb","reve.rb","tester.rb","init.rb"].to_a
47
- s.require_path = "lib"
48
- s.test_files = FileList["test/test_reve.rb","test/xml/**/*.xml"].to_a
49
- s.has_rdoc = true
50
- s.extra_rdoc_files = ["ChangeLog"]
51
- s.add_dependency("hpricot",">= 0.6")
52
- end rescue nil
53
-
54
- Rake::GemPackageTask.new(spec) do |pkg|
55
- pkg.need_tar = true
56
- end rescue nil
57
- elsif File.exists?('.git')
18
+ if File.exists?('.git')
58
19
  begin
59
20
  require 'jeweler'
60
21
  Jeweler::Tasks.new do |s|
@@ -62,10 +23,10 @@ elsif File.exists?('.git')
62
23
  s.rubyforge_project = "reve"
63
24
  s.author = "Lisa Seelye"
64
25
  s.email = "lisa@thedoh.com"
65
- s.homepage = "http://revetrac.crudvision.com"
26
+ s.homepage = "http://github.com/lisa/reve"
66
27
  s.platform = Gem::Platform::RUBY
67
28
  s.summary = "Reve is a Ruby library to interface with the Eve Online API"
68
- s.files = FileList["Rakefile","LICENSE", "lib/**/*.rb","reve.rb","tester.rb","init.rb"].to_a
29
+ s.files = FileList["Rakefile","VERSION","LICENSE", "lib/**/*.rb","reve.rb","tester.rb","init.rb"].to_a
69
30
  s.require_path = "lib"
70
31
  s.test_files = FileList["test/test_reve.rb","test/xml/**/*.xml"].to_a
71
32
  s.has_rdoc = true
data/lib/reve/classes.rb CHANGED
@@ -453,7 +453,8 @@ module Reve #:nodoc:
453
453
  @flag = elem['flag'].to_i
454
454
  @singleton = elem['singleton'] == "1"
455
455
  @assets = []
456
- #@xml_hash = elem.to_s.gsub(/\n|\r|\s/,'')
456
+ # This ::Digest::SHA1 is a bit of custom code for Eve Metrics that will
457
+ # probably find its way to all classes since it could prove handy.
457
458
  @xml_hash = ::Digest::SHA1.hexdigest elem.to_s.gsub(/\n|\r|\s/,'')
458
459
  end
459
460
  end
@@ -473,7 +474,8 @@ module Reve #:nodoc:
473
474
  @quantity = elem['quantity'].to_i
474
475
  @flag = elem['flag'].to_i
475
476
  @singleton = elem['singleton'].to_i
476
- #@xml_hash = elem.to_s.gsub(/\n|\r|\s/,'')
477
+ # This ::Digest::SHA1 is a bit of custom code for Eve Metrics that will
478
+ # probably find its way to all classes since it could prove handy.
477
479
  @xml_hash = ::Digest::SHA1.hexdigest elem.to_s.gsub(/\n|\r|\s/,'')
478
480
  end
479
481
  end
@@ -708,7 +710,6 @@ module Reve #:nodoc:
708
710
  @id = elem['stationID'].to_i
709
711
  @name = elem['stationName']
710
712
  @type_id = elem['stationTypeID'].to_i
711
- @system_id = elem['solarSystemID'].to_i
712
713
  @corporation_id = elem['corporationID'].to_i
713
714
  @corporation_name = elem['corporationName']
714
715
  @system_id = elem['solarSystemID'].to_i
@@ -1520,5 +1521,84 @@ module Reve #:nodoc:
1520
1521
  @read = elem['read'] == '1'
1521
1522
  end
1522
1523
  end
1524
+
1525
+ # Represents a AccountStatus for
1526
+ # Reve::API#account_status
1527
+ # Attributes
1528
+ # * user_id ( Fixnum ) - The account's userID
1529
+ # * paid_until ( Time ) - DateTime until when the account is still active.
1530
+ # * created_at ( Time ) - DateTime when the account was created.
1531
+ # * logon_count ( Fixnum ) - The amount of times the User logged in.
1532
+ # * logon_minutes ( Fixnum ) - The amount of minutes the user was logged in.
1533
+ # GTC buy offers not yet inplemented
1534
+ class AccountStatus
1535
+ attr_reader :user_id, :paid_until, :created_at, :logon_count, :logon_minutes
1536
+ def initialize(elem) #:nodoc:
1537
+ @user_id = (elem/'userID').inner_html.to_i
1538
+ @paid_until = Time.parse((elem/'paidUntil').inner_html)
1539
+ @created_at = Time.parse((elem/'createDate').inner_html)
1540
+ @logon_count = (elem/'logonCount').inner_html.to_i
1541
+ @logon_minutes = (elem/'logonMinutes').inner_html.to_i
1542
+ end
1543
+ end
1544
+
1545
+ # Represents a CharacterInfo for
1546
+ # Reve::API#character_info
1547
+ # Basic Attributes
1548
+ # * id ( Fixnum ) - ID of the Character
1549
+ # * name ( String ) - Name of the Character
1550
+ # * race ( String ) - Race of the Character
1551
+ # * bloodline ( String ) - Bloodline of the Character
1552
+ # * corporation_id ( Fixnum ) - ID of the Corporation the Character is in
1553
+ # * corporation_name ( String ) - Name of the Corporation the Character is in
1554
+ # * corporation_date ( Time ) - Date the Character joined his Corporation
1555
+ # * alliance_id ( Fixnum | NilClass ) - The ID of the Alliance the Character is in, if any. Will be nil unless the victim was in an Alliance
1556
+ # * alliance_name ( String | NilClass ) - Name of the Alliance the Character is in, if any.
1557
+ # * alliance_date ( Time | NilClass ) - Date the Character's Corporations joined the Alliance.
1558
+ # * security_status ( Float ) - Security status of the Character
1559
+ # Limited Attributes
1560
+ # * skillpoints ( Fixnum ) - The amount of Skillpoints
1561
+ # * skill_training_ends ( Time )-
1562
+ # * ship_name ( String ) -
1563
+ # * ship_type_id ( Fixnum ) -
1564
+ # * ship_type_name ( String ) -
1565
+ # Full Attributes
1566
+ # * last_known_location ( String ) -
1567
+ # * acount_balance ( Float )
1568
+ class CharacterInfo
1569
+ attr_reader :id, :name, :race, :bloodline, :corporation_id, :corporation_name, :corporation_date, :alliance_id, :alliance_name, :alliance_date
1570
+ attr_reader :security_status, :skillpoints, :skill_training_ends, :ship_name, :ship_type_id, :ship_type_name, :last_known_location, :acount_balance
1571
+
1572
+ def initialize(elem) #:nodoc:
1573
+ @id = (elem/'characterID').inner_html.to_i
1574
+ @name = (elem/'characterName').inner_html
1575
+ @race = (elem/'race').inner_html
1576
+ @bloodline = (elem/'bloodline').inner_html
1577
+ @corporation_id = (elem/'corporationID').inner_html.to_i
1578
+ @corporation_name = (elem/'corporation').inner_html
1579
+ @corporation_date = Time.parse((elem/'corporationDate').inner_html)
1580
+ @alliance_id = (elem/'allianceID').inner_html.to_i
1581
+ @alliance_name = (elem/'alliance').inner_html
1582
+ @alliance_date = Time.parse((elem/'alliancenDate').inner_html)
1583
+ @security_status = (elem/'securityStatus').inner_html.to_f
1584
+ @skillpoints = (elem/'skillPoints').inner_html == "" ? nil : (elem/'skillPoints').inner_html.to_i
1585
+ @skill_training_ends = (elem/'nextTrainingEnds').inner_html == "" ? nil : Time.parse((elem/'nextTrainingEnds').inner_html)
1586
+ @ship_name = (elem/'shipName').inner_html == "" ? nil : (elem/'shipName').inner_html
1587
+ @ship_type_id = (elem/'shipTypeID').inner_html == "" ? nil : (elem/'shipTypeID').inner_html.to_i
1588
+ @ship_type_name = (elem/'shipTypeName').inner_html == "" ? nil : (elem/'shipTypeName').inner_html
1589
+ @last_known_location = (elem/'lastKnownLocation').inner_html == "" ? nil : (elem/'lastKnownLocation').inner_html
1590
+ @acount_balance = (elem/'accountBalance').inner_html == "" ? nil : (elem/'accountBalance').inner_html.to_f
1591
+ end
1592
+
1593
+ def type
1594
+ if self.acount_balance
1595
+ return :full
1596
+ elsif self.skillpoints
1597
+ return :limited
1598
+ else
1599
+ return :basic
1600
+ end
1601
+ end
1602
+ end
1523
1603
  end
1524
1604
  end
@@ -57,6 +57,8 @@ module Reve
57
57
  raise UnexpectedBeforeKillID.new(msg)
58
58
  when 121
59
59
  raise BadBeforeKillID.new(msg)
60
+ when 122
61
+ raise InvalidOrMissingListOfNames.new(msg)
60
62
  when 200
61
63
  raise SecurityLevelNotHighEnough.new(msg + ' (Should you be using the full API Key?)')
62
64
  when 201
@@ -214,6 +216,9 @@ module Reve
214
216
  # 121
215
217
  class BadBeforeKillID < ReveError #:nodoc:
216
218
  end
219
+ # 122
220
+ class InvalidOrMissingListOfNames < ReveError #:nodoc:
221
+ end
217
222
  # 200
218
223
  class SecurityLevelNotHighEnough < ReveError #:nodoc:
219
224
  end
data/lib/reve.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  #--
2
- # Code copyright Lisa Seelye, 2007-2008. www.crudvision.com
2
+ # Code copyright Lisa Seelye, 2007-2010. www.crudvision.com
3
+ # Contributors at: http://github.com/lisa/reve/contributors
3
4
  # This library is licensed under the terms of the MIT license. For full text
4
5
  # see the LICENSE file distributed with this package.
5
6
  # (Also, send Raquel Smith some ISK if you would like to show appreciation ;-)
@@ -16,6 +17,7 @@ require 'uri'
16
17
  require 'cgi'
17
18
  require 'digest'
18
19
  require 'fileutils'
20
+ require 'time'
19
21
 
20
22
  $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
21
23
 
@@ -93,7 +95,11 @@ module Reve
93
95
  @@personal_mailing_lists_url = 'http://api.eve-online.com/char/mailinglists.xml.aspx'
94
96
  @@personal_mail_messages_url = 'http://api.eve-online.com/char/MailMessages.xml.aspx'
95
97
  @@personal_contacts_url = 'http://api.eve-online.com/char/ContactList.xml.aspx'
96
- @@corporate_contacts_url = 'http://api.eve-online.com/corp/ContactList.xml.aspx'
98
+ @@corporate_contacts_url = 'http://api.eve-online.com/corp/ContactList.xml.aspx'
99
+ # DO NOT USE THE FOLLOWING IN PRODUCTION
100
+ # These methods will be available with Tyrannis 1.2 (current data is from the test server)
101
+ @@account_status_url = 'http://apitest.eve-online.com/account/AccountStatus.xml.aspx'
102
+ @@character_info_url = 'http://apitest.eve-online.com/eve/CharacterInfo.xml.aspx'
97
103
 
98
104
  cattr_accessor :character_sheet_url, :training_skill_url, :characters_url, :personal_wallet_journal_url,
99
105
  :corporate_wallet_journal_url, :personal_wallet_trans_url, :corporate_wallet_trans_url,
@@ -108,12 +114,13 @@ module Reve
108
114
  :certificate_tree_url, :character_medals_url, :corporate_medals_url,
109
115
  :corp_member_medals_url, :server_status_url, :skill_queue_url, :corporation_member_security_url,
110
116
  :personal_notification_url, :personal_mailing_lists_url, :personal_mail_messages_url,
111
- :research_url, :personal_contacts_url, :corporate_contacts_url
117
+ :research_url, :personal_contacts_url, :corporate_contacts_url,
118
+ :account_status_url, :character_info_url
112
119
 
113
120
 
114
121
  attr_accessor :key, :userid, :charid
115
- attr_accessor :http_user_agent, :save_path
116
- attr_reader :current_time, :cached_until, :last_hash
122
+ attr_accessor :http_user_agent, :save_path, :timeout
123
+ attr_reader :current_time, :cached_until, :last_hash, :reve_version
117
124
 
118
125
  # Create a new API instance.
119
126
  # current_time and cached_until are meaningful only for the LAST call made.
@@ -128,13 +135,15 @@ module Reve
128
135
  @charid = (charid || "").to_s
129
136
 
130
137
  @save_path = nil
131
-
132
- @http_user_agent = "Reve"
138
+
133
139
  @max_tries = 3
140
+ @timeout = 20
134
141
 
135
142
  @current_time = nil
136
143
  @cached_until = nil
137
144
  @last_hash = nil
145
+ @reve_version = File.read(File.join(File.dirname(__FILE__),'../','VERSION')).chomp
146
+ @http_user_agent = "Reve v#{@reve_version}; http://github.com/lisa/reve"
138
147
  end
139
148
  # Save XML to this directory with the format:
140
149
  # :save_path/:userid/:method/:expires_at_in_unixtime.xml
@@ -955,6 +964,29 @@ module Reve
955
964
  process_query(Reve::Classes::MailMessage, opts[:url] || @@personal_mail_messages_url,false,args)
956
965
  end
957
966
 
967
+ # DO NOT USE THE FOLLOWING IN PRODUCTION
968
+ # These methods will be available with Tyrannis 1.2 (current data is from the test server)
969
+
970
+ # Gets the status of the selected account. Returns
971
+ # Reve::Classes::AccountStatus
972
+ def account_status(opts = {})
973
+ args = postfields(opts)
974
+ h = compute_hash(args.merge(:url => @@account_status_url))
975
+ return h if h
976
+ xml = process_query(nil,opts[:url] || @@account_status_url,true,args)
977
+ Reve::Classes::AccountStatus.new(xml.search('//result').first)
978
+ end
979
+
980
+ # Gets the character info sheet for the selected Character
981
+ # Reve::Classes::CharacterInfo
982
+ def character_info(opts = { :characterid => nil })
983
+ args = postfields(opts)
984
+ h = compute_hash(args.merge(:url => @@character_info_url))
985
+ return h if h
986
+ xml = process_query(nil,opts[:url] || @@character_info_url,true,args)
987
+ Reve::Classes::CharacterInfo.new(xml.search('//result').first)
988
+ end
989
+
958
990
  protected
959
991
  # Sets up the post fields for Net::HTTP::Get hash for process_query method.
960
992
  # See also format_url_request
@@ -1047,7 +1079,7 @@ module Reve
1047
1079
  opts.merge({ :version => 2, :url => nil }) #the uri bit will now ignored in format_url_request
1048
1080
  req_args = format_url_request(opts)
1049
1081
  req = Net::HTTP::Get.new(source.path + req_args)
1050
- req['User-Agent'] = @http_referer_agent || "Reve"
1082
+ req['User-Agent'] = @http_referer_agent || "Reve v#{@reve_version}; http://github.com/lisa/reve"
1051
1083
 
1052
1084
  res = nil
1053
1085
  response = nil
@@ -1055,7 +1087,10 @@ module Reve
1055
1087
  begin
1056
1088
  # ||= to prevent making a new Net::HTTP object, the res = nil above should reset this for the next request.
1057
1089
  # the request needs to be here to rescue exceptions from it.
1058
- res ||= Net::HTTP.new(source.host, source.port).start {|http| http.request(req) }
1090
+ http ||= Net::HTTP.new(source.host, source.port)
1091
+ http.open_timeout = 3
1092
+ http.read_timeout = @timeout
1093
+ res = http.start {|http| http.request(req) }
1059
1094
  case res
1060
1095
  when Net::HTTPSuccess, Net::HTTPRedirection
1061
1096
  response = res.body
data/test/test_reve.rb CHANGED
@@ -1209,6 +1209,74 @@ class TestReve < Test::Unit::TestCase
1209
1209
  assert_equal [128250439,141157801], mails[4].to_list_ids
1210
1210
  end
1211
1211
 
1212
+ def test_account_status_cleanly
1213
+ Reve::API.account_status_url = XML_BASE + 'account_status.xml'
1214
+ status = nil
1215
+ assert_nothing_raised do
1216
+ status = @api.account_status
1217
+ end
1218
+ assert_equal 3000000, status.user_id
1219
+ assert_equal Time.parse("2004-01-01 00:00:00"), status.created_at
1220
+ assert_equal Time.parse("2011-01-01 00:00:00"), status.paid_until
1221
+ assert_equal 9998, status.logon_count
1222
+ assert_equal 9999, status.logon_minutes
1223
+
1224
+ end
1225
+
1226
+ def test_character_info_cleanly
1227
+ Reve::API.character_info_url = XML_BASE + 'char_info.xml'
1228
+ info = nil
1229
+ assert_nothing_raised do
1230
+ info = @api.character_info
1231
+ end
1232
+ assert_equal :basic, info.type
1233
+ assert_equal 1643072492, info.id
1234
+ assert_equal 'Catari Taga', info.name
1235
+ assert_equal 'Caldari', info.race
1236
+ assert_equal 'Achura', info.bloodline
1237
+ assert_equal 553239300, info.corporation_id
1238
+ assert_equal 'Centre Of Attention', info.corporation_name
1239
+ assert_equal Time.parse('2009-02-03 13:06:00'), info.corporation_date
1240
+ assert_equal 1923227030, info.alliance_id
1241
+ assert_equal 'Middle of Nowhere', info.alliance_name
1242
+ assert_equal Time.parse('2009-02-03 13:06:00'), info.alliance_date
1243
+ assert_equal 0.0, info.security_status
1244
+ # limited
1245
+ assert_equal nil, info.skillpoints
1246
+ assert_equal nil, info.skill_training_ends
1247
+ assert_equal nil, info.ship_name
1248
+ assert_equal nil, info.ship_type_id
1249
+ assert_equal nil, info.ship_type_name
1250
+
1251
+ end
1252
+
1253
+ def test_character_info_limited_cleanly
1254
+ Reve::API.character_info_url = XML_BASE + 'char_info_limited.xml'
1255
+ info = nil
1256
+ assert_nothing_raised do
1257
+ info = @api.character_info
1258
+ end
1259
+ assert_equal :limited, info.type
1260
+ assert_equal 9999, info.skillpoints
1261
+ assert_equal Time.parse('2010-10-10 08:10:48'), info.skill_training_ends
1262
+ assert_equal '.', info.ship_name
1263
+ assert_equal 24694, info.ship_type_id
1264
+ assert_equal 'Maelstrom', info.ship_type_name
1265
+ # full
1266
+ assert_equal nil, info.last_known_location
1267
+ assert_equal nil, info.acount_balance
1268
+ end
1269
+
1270
+ def test_character_info_full_cleanly
1271
+ Reve::API.character_info_url = XML_BASE + 'char_info_full.xml'
1272
+ info = nil
1273
+ assert_nothing_raised do
1274
+ info = @api.character_info
1275
+ end
1276
+ assert_equal :full, info.type
1277
+ assert_equal 'FD-MLJ VII - Moon 2 - Intaki Bank Investment Bank', info.last_known_location
1278
+ assert_equal 9999.29, info.acount_balance
1279
+ end
1212
1280
  # Can we reassign a URL?
1213
1281
  def test_assignment
1214
1282
  assert_nothing_raised do
@@ -1285,11 +1353,14 @@ class TestReve < Test::Unit::TestCase
1285
1353
  assert_equal real,time
1286
1354
  end
1287
1355
 
1288
- protected
1289
- def get_api(userid = nil, apikey = nil, charid = nil)
1290
- api = Reve::API.new(userid, apikey, charid)
1291
- api.save_path = nil
1292
- api
1356
+ # It's useful to know the version and we'll stick it in the user agent
1357
+ # now as well.
1358
+ def test_reve_version
1359
+ # Path to Reve version is ../VERSION. We rely on File.read here and in the
1360
+ # class so it's kind of crummy.
1361
+ version = File.read(File.join(File.dirname(__FILE__),'../','VERSION')).chomp
1362
+ assert_equal(@api.reve_version, version)
1363
+ assert_equal("Reve v#{version}; http://github.com/lisa/reve", @api.http_user_agent)
1293
1364
  end
1294
1365
 
1295
1366
  # no need to test corporate cos they're the same.
@@ -1341,4 +1412,11 @@ class TestReve < Test::Unit::TestCase
1341
1412
  end
1342
1413
  end
1343
1414
 
1415
+ #### All tests above this method.
1416
+ protected
1417
+ def get_api(userid = nil, apikey = nil, charid = nil)
1418
+ api = Reve::API.new(userid, apikey, charid)
1419
+ api.save_path = nil
1420
+ api
1421
+ end
1344
1422
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dsander-reve
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ prerelease: true
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 132
9
- version: 0.0.132
8
+ - 133
9
+ - pre
10
+ version: 0.0.133.pre
10
11
  platform: ruby
11
12
  authors:
12
13
  - Lisa Seelye