| 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
Returns a RefType list (whatever they are) from api.eve-online.com/eve/RefTypes.xml.aspx See also: Reve::Classes::RefType
# File lib/reve.rb, line 229
229: def ref_types(opts = {})
230: compute_hash( opts.merge(:url => @@reftypes_url) ) ||
231: process_query(Reve::Classes::RefType,opts[:url] || @@reftypes_url,false)
232: end
Save XML to this directory with the format: :save_path/:userid/:method/:expires_at_in_unixtime.xml eg: ./xml/12345/characters/1200228878.xml or: ./xml/alliances/1200228878.xml If @save_path is nil then XML is not saved.
# File lib/reve.rb, line 131
131: def save_path=(p)
132: @save_path = p
133: end
Gets the SkillInTraining from api.eve-online.com/char/SkillInTraining.xml.aspx Expects:
See also: Reve::Classes::SkillInTraining
# File lib/reve.rb, line 554
554: def skill_in_training(opts = {:characterid => nil})
555: args = postfields(opts)
556: ch = compute_hash(args.merge(:url => @@training_skill_url))
557: return ch if ch
558: h = {}
559: xml = process_query(nil,opts[:url] || @@training_skill_url,true,args)
560: xml.search("//result").each do |elem|
561: for field in [ 'currentTQTime', 'trainingEndTime','trainingStartTime','trainingTypeID','trainingStartSP','trainingDestinationSP','trainingToLevel','skillInTraining' ]
562: h[field] = (elem/field.intern).inner_html
563: end
564: end
565: Reve::Classes::SkillInTraining.new(h)
566: end
Returns the SkillTree from api.eve-online.com/eve/SkillTree.xml.aspx See also: Reve::Classes::SkillTree NOTE: This doesn‘t actually return a ‘tree’ yet.
# File lib/reve.rb, line 280
280: def skill_tree(opts = {})
281: h = compute_hash(opts.merge(:url => @@skill_tree_url) )
282: return h if h
283: doc = process_query(nil,opts[:url] || @@skill_tree_url,true)
284: skills = []
285: (doc/'rowset[@name=skills]/row').each do |skill|
286: name = skill['typeName']
287: type_id = skill['typeID']
288: group_id = skill['groupID']
289: rank = (skill/:rank).inner_html
290: desc = (skill/:description).inner_html
291: required_skills = []
292: reqs = (skill/'rowset@name=[requiredskills]/row')
293: reqs.each do |required|
294: next if required.kind_of? Hpricot::Text # why is this needed? Why is this returned? How can I only get stuff with typeid and skilllevel?
295: required_skills << Reve::Classes::SkillRequirement.new(required) if required['typeID'] && required['skillLevel']
296: end
297: required_attribs = []
298: (skill/'requiredAttributes').each do |req|
299: pri = doc.at(req.xpath + "/primaryAttribute")
300: sec = doc.at(req.xpath + "/secondaryAttribute")
301: required_attribs << Reve::Classes::PrimaryAttribute.new(pri.inner_html)
302: required_attribs << Reve::Classes::SecondaryAttribute.new(sec.inner_html)
303: end
304: bonuses = []
305: res = (skill/'rowset@name=[skillBonusCollection]/row')
306: res.each do |bonus|
307: next if bonus.kind_of? Hpricot::Text
308: bonuses << Reve::Classes::SkillBonus.new(bonus) if bonus['bonusType'] && bonus['bonusValue']
309: end
310: skills << Reve::Classes::SkillTree.new(name,type_id,group_id,desc,rank,required_attribs,required_skills,bonuses)
311: end
312: skills
313: end
Returns the Sovereignty list from api.eve-online.com/map/Sovereignty.xml.aspx See also: Reve::Classes::Sovereignty
# File lib/reve.rb, line 221
221: def sovereignty(opts = {})
222: compute_hash( opts.merge(:url => @@sovereignty_url) ) ||
223: process_query(Reve::Classes::Sovereignty,opts[:url] || @@sovereignty_url,false)
224: end
Returns the fuel status for the Starbase whose item id is starbase_id api.eve-online.com/corp/StarbaseDetail.xml.aspx Expects:
See also Reve::Classes::StarbaseFuel
# File lib/reve.rb, line 586
586: def starbase_fuel(opts = { :characterid => nil, :starbaseid => nil })
587: args = postfields(opts)
588: h = compute_hash(args.merge(:url => @@starbasedetail_url))
589: return h if h
590: ret = process_query(Reve::Classes::StarbaseFuel,opts[:url] || @@starbasedetail_url, false, args)
591: ret.each { |r| r.starbase_id = opts[:starbaseid] }
592: ret
593: end
Returns a list of Reve::Classes::Starbase for characterid‘s Corporation. api.eve-online.com/corp/StarbaseList.xml.aspx Expects:
See also Reve::Classes::Starbase
# File lib/reve.rb, line 573
573: def starbases(opts = { :characterid => nil})
574: args = postfields(opts)
575: h = compute_hash(args.merge(:url => @@starbases_url))
576: return h if h
577: process_query(Reve::Classes::Starbase,opts[:url] || @@starbases_url,false,args)
578: end
# File lib/reve.rb, line 888
888: def build_save_filename
889: method = caller(3).first.match(/\`(.+)'/)[1] # Get the API method that's being called. This is called from save_xml -> process_query -> :real_method
890: File.join(@save_path,@userid.to_s,method,( @cached_until || Time.now.utc).to_i.to_s + '.xml')
891: end
Raises the proper exception (if there is one), otherwise it returns the XML response.
# File lib/reve.rb, line 867
867: def check_exception(xml)
868: x = Hpricot::XML(xml)
869: begin
870: out = x.search("//error") # If this fails then there are some big problems with Hpricot#search ?
871: rescue Exception => e
872: $stderr.puts "Fatal error ((#{e.to_s})): Couldn't search the XML document ((#{xml})) for any potential error messages! Is your Hpricot broken?"
873: exit 1
874: end
875: @current_time = (x/:currentTime).inner_html.to_time rescue Time.now.utc # Shouldn't need to rescue this but one never knows
876: @cached_until = (x/:cachedUntil).inner_html.to_time rescue nil # Errors aren't always cached
877: return x if out.size < 1
878: code = out.first['code'].to_i
879: str = out.first.inner_html
880: Reve::Exceptions.raise_it(code,str)
881: end
Creates a hash for some hash of postfields. For each API method pass :just_hash => to something to return a hash that can be matched to the last_hash instance method created in process_query. This method is called in each API method before process_query and if :just_hash was passed in args then a String will be returned, otherwise nil will be returned TODO: Consider moving this whole thing into process_query before the URI parsing
# File lib/reve.rb, line 761
761: def compute_hash(args = {})
762: args.stringify_keys!
763: return nil unless args.include?('just_hash')
764: args.delete('just_hash')
765: url = args['url'].kind_of?(URI) ? args['url'].path : args['url']
766: args.delete('url')
767: spl = url.split '/'
768: ret = (spl[-2] + '/' + spl[-1]) + ':'
769: args.delete_if { |k,v| (v || "").to_s.length == 0 } # Delete keys if the value is nil
770: h = args.stringify_keys
771: ret += h.sort.flatten.collect{ |e| e.to_s }.join(':')
772: ret.gsub(/:$/,'')
773: end
Turns a hash into ?var=baz&bam=boo
# File lib/reve.rb, line 805
805: def format_url_request(opts)
806: req = "?"
807:
808: opts.stringify_keys!
809: opts.keys.sort.each do |key|
810: req += "#{CGI.escape(key.to_s)}=#{CGI.escape(opts[key].to_s)}&" if opts[key]
811: end
812: req.chop # We are lazy and append a & to each pair even if it's the last one. FIXME: Don't do this.
813: end
Gets the XML from a source. Expects:
NOTE: To override the lowercase http -> URI rule make the HTTP part uppercase.
# File lib/reve.rb, line 821
821: def get_xml(source,opts)
822: xml = ""
823:
824: # Let people still pass Strings starting with http.
825: if source =~ /^http/
826: source = URI.parse(source)
827: end
828:
829: if source.kind_of?(URI)
830: opts.merge({ :version => 2, :url => nil }) #the uri bit will now ignored in format_url_request
831: req_args = format_url_request(opts)
832: req = Net::HTTP::Get.new(source.path + req_args)
833: req['User-Agent'] = @http_referer_agent || "Reve"
834:
835: res = nil
836: response = nil
837: 1.upto(@max_tries) do |try|
838: begin
839: # ||= to prevent making a new Net::HTTP object, the res = nil above should reset this for the next request.
840: # the request needs to be here to rescue exceptions from it.
841: res ||= Net::HTTP.new(source.host, source.port).start {|http| http.request(req) }
842: case res
843: when Net::HTTPSuccess, Net::HTTPRedirection
844: response = res.body
845: end
846: rescue Exception
847: sleep 5
848: next
849: end
850: break if response
851: end
852: raise Reve::Exceptions::ReveNetworkStatusException.new( (res.body rescue "No Response Body!") ) unless response
853:
854: xml = response
855:
856: # here ends test for URI
857: elsif source.kind_of?(String)
858: xml = File.open(source).read
859: else
860: raise Reve::Exceptions::ReveNetworkStatusException.new("Don't know how to deal with a #{source.class} XML source. I expect a URI or String")
861: end
862: xml
863: end
Sets up the post fields for Net::HTTP::Get hash for process_query method. See also format_url_request TODO: Consider moving this whole thing into process_query to avoid calling this in every method!
# File lib/reve.rb, line 746
746: def postfields(opts = {})
747: ret = { "userid" => @userid, "apikey" => @key, "characterid" => @charid }.merge(opts.stringify_keys)
748: ret.inject({}) do |n, (k,v)|
749: n[k.downcase] = v.to_s if v
750: n
751: end
752: end
Processes a URL and for simple <rowset><row /><row /></rowset> results create an array of objects of type klass. Or just return the XML if just_xml is set true. args is from postfields This method will call check_exception to see if an Exception came from CCP. Expects:
# File lib/reve.rb, line 785
785: def process_query(klass, url, just_xml = false, opts = {})
786:
787: #args = postfields(opts)
788: #h = compute_hash(args.merge(:url => url))
789: #return h if h
790:
791: @last_hash = compute_hash(opts.merge({:url => url, :just_hash => true })) # compute hash
792:
793: xml = check_exception(get_xml(url,opts))
794: save_xml(xml) if @save_path
795:
796: return xml if just_xml
797: return [] if xml.nil? # No XML document returned. We should panic.
798:
799: # Create the array of klass objects to return, assume we start with an empty set from the XML search for rows
800: # and build from there.
801: xml.search("//rowset/row").inject([]) { |ret,elem| ret << klass.new(elem) }
802: end
Returns an array of klass
# File lib/reve.rb, line 894
894: def pull_out_top_10_data(xml,klass,kind,field)
895: xml.search("/eveapi/result/#{kind}/rowset[@name='#{field}']/row").inject([]) do |all,row|
896: all << klass.new(row)
897: all
898: end
899: end