| Class | Reve::API |
| In: |
lib/reve.rb
|
| Parent: | Object |
API Class. Basic Usage: api = Reve::API.new(‘my_UserID’, ‘my_apiKey’) alliances = api.alliances # Returns an array of Reve::Classes::Alliance
api.personal_wallet_blanace(:characterid => 892008733) # Returns an array of Reve::Classes::WalletBalance. Note that the CharacterID Number is required here.
api.sovereignty :just_hash => true # Returns the hash for this call with no Alliance data with it.
As of Revision 22 (28 August 2007) all API calls take a parameter, :just_hash, to just get the hash that represents that particular API call; No data related to the call is returned if :just_hash is present
All API methods have the functionality to read XML from an arbitrary location. This could be another webserver, or a XML file on disk. To use this pass the hash option :url => location where location is a String or URI class. See format_url_request documentation for more details.
| cached_until | [R] | |
| charid | [RW] | |
| current_time | [R] | |
| http_user_agent | [RW] | |
| key | [RW] | |
| last_hash | [R] | |
| save_path | [RW] | |
| userid | [RW] |
Create a new API instance. current_time and cached_until are meaningful only for the LAST call made. Expects:
NOTE: All values passed to the constructor are typecasted to a String for safety.
# File lib/reve.rb, line 112
112: def initialize(userid = "", key = "", charid = "")
113: @userid = (userid || "").to_s
114: @key = (key || "").to_s
115: @charid = (charid || "").to_s
116:
117: @save_path = nil
118:
119: @http_user_agent = "Reve"
120: @max_tries = 3
121:
122: @current_time = nil
123: @cached_until = nil
124: @last_hash = nil
125: end
Return a list of Alliances and member Corporations from api.eve-online.com/eve/AllianceList.xml.aspx Use the corporation_sheet method to get information for each member Corporation See also: Reve::Classes::Alliance, Reve::Classes::Corporation and corporation_sheet
# File lib/reve.rb, line 182
182: def alliances(opts = {})
183: args = postfields(opts)
184: h = compute_hash(args.merge(:url => @@alliances_url))
185: return h if h
186: xml = process_query(nil,opts[:url] || @@alliances_url,true,args)
187: alliances = []
188: xml.search("/eveapi/result/rowset[@name='alliances']/row").each do |alliance|
189: alliance_obj = Reve::Classes::Alliance.new(alliance)
190: alliance.search("rowset[@name='memberCorporations']/row").each do |corporation|
191: alliance_obj.member_corporations << Reve::Classes::Corporation.new(corporation)
192: end
193: alliances << alliance_obj
194: end
195: alliances
196: end
Convert Character names to Character ids. Expects a Hash as a parameter with these keys:
See Also: character_name, Reve::Classes::Character, character_sheet
# File lib/reve.rb, line 148
148: def character_id(opts = {} )
149: names = opts[:names] || []
150: return [] if names.empty? # No names were passed.
151: opts[:names] = names.join(',')
152: args = postfields(opts)
153: h = compute_hash( opts.merge(:url => @@character_id_url) )
154: return h if h
155: xml = process_query(nil,opts[:url] || @@character_id_url, true,opts)
156: xml = Hpricot::XML(xml.to_s.gsub('row:name','row')) # Namespaces are evil!!
157: ret = []
158: xml.search("//rowset/row").each do |elem|
159: ret << Reve::Classes::Character.new(elem)
160: end
161: ret
162: end
Convert Character names to Character names. Expects a Hash as a parameter with these keys:
See Also: character_name, Reve::Classes::Character, character_sheet
# File lib/reve.rb, line 168
168: def character_name(opts = {})
169: ids = opts[:ids] || []
170: return [] if ids.empty?
171: opts[:ids] = ids.join(',')
172: compute_hash( opts.merge(:url => @@character_name_url) ) ||
173: process_query(Reve::Classes::Character,opts[:url] || @@character_name_url,false,opts)
174: end
Gets the CharacterSheet from api.eve-online.com/char/CharacterSheet.xml.aspx Expects:
See also: Reve::Classes::CharacterSheet
# File lib/reve.rb, line 693
693: def character_sheet(opts = { :characterid => nil })
694: args = postfields(opts)
695: h = compute_hash(args.merge(:url => @@character_sheet_url))
696: return h if h
697:
698: xml = process_query(nil,opts[:url] || @@character_sheet_url,true,args)
699: cs = Reve::Classes::CharacterSheet.new
700:
701: xml.search("//result/attributeEnhancers").each do |enh|
702: for kind in ['intelligenceBonus', 'memoryBonus', 'charismaBonus', 'perceptionBonus','willpowerBonus']
703: thing = nil
704: case kind
705: when 'intelligenceBonus'
706: thing = Reve::Classes::IntelligenceEnhancer
707: when 'memoryBonus'
708: thing = Reve::Classes::MemoryEnhancer
709: when 'charismaBonus'
710: thing = Reve::Classes::CharismaEnhancer
711: when 'perceptionBonus'
712: thing = Reve::Classes::PerceptionEnhancer
713: when 'willpowerBonus'
714: thing = Reve::Classes::WillpowerEnhancer
715: end
716: (enh/kind).each do |b|
717: name = (b/:augmentatorname).inner_html
718: value = (b/:augmentatorvalue).inner_html
719: cs.enhancers << thing.new(name,value)
720: end
721: end
722: end
723:
724: (xml/:result).each do |elem|
725: for field in [ 'characterID', 'name', 'race', 'bloodLine', 'gender','corporationName','corporationID','balance' ]
726: cs.send("#{field.downcase}=",(elem/field.intern).first.inner_html)
727: end
728: end
729: (xml/:result/:attributes).each do |elem|
730: for attrib in [ 'intelligence','memory','charisma','perception','willpower' ]
731: cs.send("#{attrib}=",(elem/attrib.intern).first.inner_html)
732: end
733: end
734: (xml/:result/:rowset/:row).each do |elem|
735: cs.skills << Reve::Classes::Skill.new(elem)
736: end
737: cs
738: end
Returns a Character list for the associated key and userid from api.eve-online.com/account/Characters.xml.aspx See also: Reve::Classes::Character
# File lib/reve.rb, line 542
542: def characters(opts = {})
543: args = postfields(opts)
544: h = compute_hash(args.merge(:url => @@characters_url))
545: return h if h
546: process_query(Reve::Classes::Character,opts[:url] || @@characters_url,false,args)
547: end
Returns a list of ConqurableStations and outposts from api.eve-online.com/eve/ConquerableStationList.xml.aspx See also: Reve::Classes::ConqurableStation
# File lib/reve.rb, line 237
237: def conqurable_stations(opts = {})
238: compute_hash( opts.merge(:url => @@conqurable_outposts_url) ) ||
239: process_query(Reve::Classes::ConqurableStation, opts[:url] || @@conqurable_outposts_url, false)
240: end
Get a list of the Corporate Assets. Pass the characterid of the Corporate member See also assets_list method
# File lib/reve.rb, line 523
523: def corporate_assets_list(opts = { :characterid => nil})
524: args = postfields(opts)
525: h = compute_hash(args.merge(:url => @@corporate_assets_url))
526: return h if h
527: xml = process_query(nil,opts[:url] || @@corporate_assets_url,true,args)
528: assets = []
529: xml.search("/eveapi/result/rowset/row").each do |container|
530: asset_container = Reve::Classes::AssetContainer.new(container)
531: container.search("rowset[@name='contents']/row").each do |asset|
532: asset_container.assets << Reve::Classes::Asset.new(asset)
533: end
534: assets << asset_container
535: end
536: assets
537: end
Gets the CorporateFactionWarStat for the Corporation a Character belongs to. Expects:
See Also Reve::Classes::CorporateFactionWarStat and personal_faction_war_stats
# File lib/reve.rb, line 429
429: def corporate_faction_war_stats(opts = { :characterid => nil })
430: args = postfields(opts)
431: h = compute_hash(args.merge(:url => @@corporate_faction_war_stats_url))
432: return h if h
433: xml = process_query(nil,opts[:url] || @@corporate_faction_war_stats_url,true,args)
434: elems = {}
435: [ :factionID, :factionName, :enlisted, :pilots,
436: :killsYesterday, :killsLastWeek, :killsTotal, :victoryPointsYesterday,
437: :victoryPointsLastWeek, :victoryPointsTotal ].each do |elem|
438: elems[elem.to_s] = xml.search("/eveapi/result/" + elem.to_s).first.inner_html
439: end
440: Reve::Classes::CorporateFactionWarParticpant.new(elems)
441: end
Returns a list of Reve::Classes::CorporateIndustryJob objects.
# File lib/reve.rb, line 269
269: def corporate_industry_jobs(opts = {:characterid => nil})
270: args = postfields(opts)
271: h = compute_hash(args.merge(:url => @@corporate_industry_jobs_url))
272: return h if h
273: process_query(Reve::Classes::CorporateIndustryJob, opts[:url] || @@corporate_industry_jobs_url,false,args)
274: end
See the options for personal_kills
# File lib/reve.rb, line 627
627: def corporate_kills(opts = { :characterid => nil })
628: args = postfields(opts)
629: h = compute_hash(args.merge(:url => @@corporate_kills_url))
630: return h if h
631: xml = process_query(nil,opts[:url] || @@corporate_kills_url,true,args)
632: kills = []
633: xml.search("/eveapi/result/rowset/row").each do |e|
634: victim = Reve::Classes::KillVictim.new(e.search("victim").first) rescue next # cant find victim
635: attackers = []
636: losses = []
637: e.search("rowset[@name='attackers']/row").each do |attacker|
638: attackers << Reve::Classes::KillAttacker.new(attacker)
639: end
640: e.search("rowset[@name='items']/row").each do |lost_item|
641: lost = Reve::Classes::KillLoss.new(lost_item)
642: lost_item.search("rowset[@name='items']/row").each do |contained|
643: lost.contained_losses << Reve::Classes::KillLoss.new(contained)
644: end
645: losses << lost
646: end
647: kills << Reve::Classes::Kill.new(e, victim, attackers, losses)
648: end
649: kills
650: end
Returns a list of Reve::Classes::MarketOrder objects for market orders that are up on behalf of a Corporation Pass the characterid of the Character of whose corporation to check for
# File lib/reve.rb, line 253
253: def corporate_market_orders(opts = {:characterid => nil})
254: args = postfields(opts)
255: h = compute_hash(args.merge(:url => @@corporate_market_orders_url))
256: return h if h
257: process_query(Reve::Classes::CorporateMarketOrder, opts[:url] || @@corporate_market_orders_url, false, args)
258: end
Gets one‘s corporate WalletBalance from api.eve-online.com/corp/AccountBalance.xml.aspx Expects:
See also: Reve::Classes::WalletBalance and personal_wallet_balance
# File lib/reve.rb, line 344
344: def corporate_wallet_balance(opts = { :characterd => nil })
345: args = postfields(opts)
346: h = compute_hash(args.merge(:url => @@corporate_wallet_balance_url))
347: return h if h
348: process_query(Reve::Classes::WalletBalance,opts[:url] || @@corporate_wallet_balance_url,false,args)
349: end
Gets one‘s own corporate WalletJournal list from api.eve-online.com/corp/WalletJournal.xml.aspx Expects:
See also: Reve::Classes::WalletJournal and personal_wallet_journal
# File lib/reve.rb, line 387
387: def corporate_wallet_journal(opts = {:accountkey => nil, :characterid => nil, :beforerefid => nil})
388: args = postfields(opts)
389: h = compute_hash(args.merge(:url => @@corporate_wallet_journal_url))
390: return h if h
391: process_query(Reve::Classes::WalletJournal,opts[:url] || @@corporate_wallet_journal_url,false,args)
392: end
Gets one‘s corporate WalletTransaction list from api.eve-online.com/corp/WalletTransactions.xml.aspx Expects:
See also: Reve::Classes::WalletTransaction and personal_wallet_transactions
# File lib/reve.rb, line 373
373: def corporate_wallet_transactions(opts = {:accountkey => nil, :characterid => nil, :beforerefid => nil})
374: args = postfields(opts)
375: h = compute_hash(args.merge(:url => @@corporate_wallet_trans_url))
376: return h if h
377: process_query(Reve::Classes::CorporateWalletTransaction,opts[:url] || @@corporate_wallet_trans_url,false,args)
378: end
Gets the CorporationSheet from api.eve-online.com/corp/CorporationSheet.xml.aspx Expects:
(See the alliances method for a list) to get the details of a Corporation that belongs to an Alliance. See also: Reve::Classes::CorporationSheet
# File lib/reve.rb, line 659
659: def corporation_sheet(opts = { :characterid => nil })
660: args = postfields(opts)
661: h = compute_hash(args.merge(:url => @@corporation_sheet_url))
662: return h if h
663: xml = process_query(nil,opts[:url] || @@corporation_sheet_url,true,args)
664:
665: h = { 'graphicid' => 0, 'shape1' => 0, 'shape2' => 0, 'shape3' => 0, 'color1' => 0, 'color2' => 0, 'color3' => 0, }
666: h.keys.each { |k| h[k] = xml.search("//result/logo/" + k + "/").to_s.to_i }
667: corporate_logo = Reve::Classes::CorporateLogo.new h
668:
669: wallet_divisions = xml.search("//result/rowset[@name='walletDivisions']/").collect { |k| k if k.kind_of? Hpricot::Elem } - [ nil ]
670: divisions = xml.search("//result/rowset[@name='divisions']/").collect { |k| k if k.kind_of? Hpricot::Elem } - [ nil ]
671: divisions.collect! { |d| Reve::Classes::CorporateDivision.new(d) }
672: wallet_divisions.collect! { |w| Reve::Classes::WalletDivision.new(w) }
673:
674: # Map the XML names to our own names and assign them to the temporary
675: # hash +res+ to pass to Reve::Classes::CorporationSheet#new
676: res = Hash.new
677: { :corporationid => :id, :corporationname => :name, :ticker => :ticker, :ceoid => :ceo_id,
678: :ceoname => :ceo_name, :stationid => :station_id, :stationname => :station_name,
679: :description => :description, :url => :url, :allianceid => :alliance_id,
680: :alliancename => :alliance_name, :taxrate => :tax_rate, :membercount => :member_count,
681: :memberlimit => :member_limit, :shares => :shares }.each do |k,v|
682: res[v] = xml.search("//result/#{k.to_s}/").first.to_s.strip
683: end
684:
685: Reve::Classes::CorporationSheet.new res, divisions, wallet_divisions, corporate_logo
686: end
Gets Faction-wide war stats. See also: Reve::Classes::EveFactionWarStat, Reve::Classes::FactionwideFactionWarParticpant, Reve::Classes::FactionWar
# File lib/reve.rb, line 446
446: def faction_war_stats(opts = {} )
447: args = postfields(opts)
448: h = compute_hash(args.merge(:url => @@general_faction_war_stats_url))
449: return h if h
450: xml = process_query(nil,opts[:url] || @@general_faction_war_stats_url,true,args)
451: participants = xml.search("/eveapi/result/rowset[@name='factions']/row").collect do |faction|
452: Reve::Classes::FactionwideFactionWarParticpant.new(faction)
453: end
454: wars = xml.search("/eveapi/result/rowset[@name='factionWars']/row").collect do |faction_war|
455: Reve::Classes::FactionWar.new(faction_war)
456: end
457: totals = {}
458: [ :killsYesterday, :killsLastWeek, :killsTotal, :victoryPointsYesterday,
459: :victoryPointsLastWeek, :victoryPointsTotal ].each do |elem|
460: totals[elem.to_s] = xml.search("/eveapi/result/totals/" + elem.to_s).first.inner_html
461: end
462: Reve::Classes::EveFactionWarStat.new(totals, wars, participants)
463: end
Returns the occupancy data for each System. See also: Reve::Classes::FactionWarSystemStatus
# File lib/reve.rb, line 467
467: def faction_war_system_stats(opts = {})
468: args = postfields(opts)
469: h = compute_hash(args.merge(:url => @@faction_war_occupancy_url))
470: return h if h
471: process_query(Reve::Classes::FactionWarSystemStatus,opts[:url] || @@faction_war_occupancy_url,false,args)
472: end
Gets a list of the top 10 statistics for Characters, Corporations and Factions in factional warfare. Read the notes on Reve::Classes::FactionWarTopStats.
# File lib/reve.rb, line 477
477: def faction_war_top_stats(opts = {})
478: args = postfields(opts)
479: h = compute_hash(args.merge(:url => @@top_faction_war_stats_url))
480: return h if h
481: xml = process_query(nil,opts[:url] || @@top_faction_war_stats_url,true,args)
482: template = { :yesterday_kills => "KillsYesterday", :last_week_kills => "KillsLastWeek", :total_kills => "KillsTotal",
483: :yesterday_victory_points => 'VictoryPointsYesterday', :last_week_victory_points => 'VictoryPointsLastWeek', :total_victory_points => 'VictoryPointsTotal' }
484: # Inject here to save 60 lines.
485: characters = template.inject({}) do |h,(key,val)|
486: klass = key.to_s =~ /kills/ ? Reve::Classes::CharacterFactionKills : Reve::Classes::CharacterFactionVictoryPoints
487: h[key] = pull_out_top_10_data(xml,klass,'characters',val)
488: h
489: end
490: corporations = template.inject({}) do |h,(key,val)|
491: klass = key.to_s =~ /kills/ ? Reve::Classes::CorporationFactionKills : Reve::Classes::CorporationFactionVictoryPoints
492: h[key] = pull_out_top_10_data(xml,klass,'corporations',val)
493: h
494: end
495: factions = template.inject({}) do |h,(key,val)|
496: klass = key.to_s =~ /kills/ ? Reve::Classes::FactionKills : Reve::Classes::FactionVictoryPoints
497: h[key] = pull_out_top_10_data(xml,klass,'factions',val)
498: h
499: end
500: Reve::Classes::FactionWarTopStats.new(characters,corporations,factions)
501: end
Returns a list of the number of jumps for each system. If there are no jumps for a system it will not be included. See also Reve::Classes::MapJump
# File lib/reve.rb, line 200
200: def map_jumps(opts = {})
201: compute_hash( opts.merge(:url => @@map_jumps_url) ) ||
202: process_query(Reve::Classes::MapJump,opts[:url] || @@map_jumps_url,false)
203: end
Returns a list of the number of kills for each system. If there are no kills for a system it will not be included. See also Reve::Classes::MapKill
# File lib/reve.rb, line 207
207: def map_kills(opts = {})
208: compute_hash( opts.merge(:url => @@map_kills_url) ) ||
209: process_query(Reve::Classes::MapKill,opts[:url] || @@map_kills_url,false)
210: end
Does big brother tracking from api.eve-online.com/corp/MemberTracking.xml.aspx Expects:
See also: Reve::Classes::MemberTracking
# File lib/reve.rb, line 320
320: def member_tracking(opts = {:characterid => nil})
321: args = postfields(opts)
322: h = compute_hash(args.merge(:url => @@member_tracking_url))
323: return h if h
324: process_query(Reve::Classes::MemberTracking,opts[:url] || @@member_tracking_url,false,args)
325: end
Get a list of personal assets for the characterid. See the Reve::Classes::Asset and Reve::Classes::AssetContainer classes for attributes available.
# File lib/reve.rb, line 506
506: def personal_assets_list(opts = { :characterid => nil })
507: args = postfields(opts)
508: h = compute_hash(args.merge(:url => @@personal_assets_url))
509: return h if h
510: xml = process_query(nil,opts[:url] || @@personal_assets_url,true,args)
511: assets = []
512: xml.search("/eveapi/result/rowset[@name='assets']/row").each do |container|
513: asset_container = Reve::Classes::AssetContainer.new(container)
514: container.search("rowset[@name='contents']/row").each do |asset|
515: asset_container.assets << Reve::Classes::Asset.new(asset)
516: end
517: assets << asset_container
518: end
519: assets
520: end
Gets the PersonalFactionWarStat for a character. Expects:
See Also Reve::Classes::PersonalFactionWarStat and corporate_faction_war_stats
# File lib/reve.rb, line 411
411: def personal_faction_war_stats(opts = { :characterid => nil })
412: args = postfields(opts)
413: h = compute_hash(args.merge(:url => @@personal_faction_war_stats_url))
414: return h if h
415: xml = process_query(nil,opts[:url] || @@personal_faction_war_stats_url,true,args)
416: elems = {}
417: [ :factionID, :factionName, :enlisted, :currentRank, :highestRank,
418: :killsYesterday, :killsLastWeek, :killsTotal, :victoryPointsYesterday,
419: :victoryPointsLastWeek, :victoryPointsTotal ].each do |elem|
420: elems[elem.to_s] = xml.search("/eveapi/result/" + elem.to_s).first.inner_html
421: end
422: Reve::Classes::PersonalFactionWarParticpant.new(elems)
423: end
Returns a list of Reve::Classes::PersonalIndustryJob objects.
# File lib/reve.rb, line 261
261: def personal_industry_jobs(opts = {:characterid => nil})
262: args = postfields(opts)
263: h = compute_hash(args.merge(:url => @@personal_industry_jobs_url))
264: return h if h
265: process_query(Reve::Classes::PersonalIndustryJob, opts[:url] || @@personal_industry_jobs_url,false,args)
266: end
Get the last kills for the characterid passed. Expects:
# File lib/reve.rb, line 601
601: def personal_kills(opts = { :characterid => nil })
602: args = postfields(opts)
603: h = compute_hash(args.merge(:url => @@personal_kills_url))
604: return h if h
605: xml = process_query(nil,opts[:url] || @@personal_kills_url,true,args)
606: kills = []
607: xml.search("/eveapi/result/rowset/row").each do |e|
608: victim = Reve::Classes::KillVictim.new(e.search("victim").first) rescue next # cant find victim
609: attackers = []
610: losses = []
611: e.search("rowset[@name='attackers']/row").each do |attacker|
612: attackers << Reve::Classes::KillAttacker.new(attacker)
613: end
614: e.search("rowset[@name='items']/row").each do |lost_item|
615: lost = Reve::Classes::KillLoss.new(lost_item)
616: lost_item.search("rowset[@name='items']/row").each do |contained|
617: lost.contained_losses << Reve::Classes::KillLoss.new(contained)
618: end
619: losses << lost
620: end
621: kills << Reve::Classes::Kill.new(e, victim, attackers, losses)
622: end
623: kills
624: end
Returns a list of Reve::Classes::MarketOrder objects for market orders that are up Pass the characterid of the Character to check for
# File lib/reve.rb, line 244
244: def personal_market_orders(opts = {:characterid => nil})
245: args = postfields(opts)
246: h = compute_hash(args.merge(:url => @@personal_market_orders_url))
247: return h if h
248: process_query(Reve::Classes::PersonalMarketOrder, opts[:url] || @@personal_market_orders_url, false, args)
249: end
Gets one‘s own personal WalletBalance from api.eve-online.com/char/AccountBalance.xml.aspx Expects:
See also: Reve::Classes::WalletBalance and corporate_wallet_balance
# File lib/reve.rb, line 332
332: def personal_wallet_balance(opts = { :characterid => nil })
333: args = postfields(opts)
334: h = compute_hash(args.merge(:url => @@personal_wallet_balance_url))
335: return h if h
336: process_query(Reve::Classes::WalletBalance,opts[:url] || @@personal_wallet_balance_url,false,args)
337: end
Gets one‘s own personal WalletJournal list from api.eve-online.com/char/WalletJournal.xml.aspx Expects:
See also: Reve::Classes::WalletJournal and corporate_wallet_journal
# File lib/reve.rb, line 400
400: def personal_wallet_journal(opts = { :characterid => nil, :beforerefid => nil} )
401: args = postfields(opts)
402: h = compute_hash(args.merge(:url => @@personal_wallet_journal_url))
403: return h if h
404: process_query(Reve::Classes::WalletJournal,opts[:url] || @@personal_wallet_journal_url,false,args)
405: end
Gets one‘s own personal WalletTransaction list from api.eve-online.com/char/WalletTransactions.xml.aspx Expects:
See also: Reve::Classes::WalletTransaction and corporate_wallet_transactions
# File lib/reve.rb, line 358
358: def personal_wallet_transactions(opts = { :characterid => nil, :before_trans_id => nil })
359: args = postfields(opts)
360: h = compute_hash(args.merge(:url => @@personal_wallet_trans_url) )
361: return h if h
362: process_query(Reve::Classes::PersonalWalletTransaction,opts[:url] || @@personal_wallet_trans_url,false,args)
363: end