wowr 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,10 +5,10 @@
5
5
  # http://benhumphreys.co.uk/
6
6
 
7
7
  begin
8
- require 'lib/hpricot-0.6/hpricot'
8
+ require 'hpricot' # version 0.6
9
9
  rescue LoadError
10
10
  require 'rubygems'
11
- require 'hpricot'
11
+ require 'hpricot' # version 0.6
12
12
  end
13
13
  require 'net/http'
14
14
  require 'cgi'
@@ -26,6 +26,8 @@ module Wowr
26
26
  @@armory_url = 'http://www.wowarmory.com/'
27
27
  @@eu_armory_url = 'http://eu.wowarmory.com/'
28
28
 
29
+ @@search_url = 'search.xml'
30
+
29
31
  @@character_sheet_url = 'character-sheet.xml'
30
32
  @@character_talents_url = 'character-talents.xml'
31
33
  @@character_skills_url = 'character-skills.xml'
@@ -33,18 +35,15 @@ module Wowr
33
35
 
34
36
  @@guild_info_url = 'guild-info.xml'
35
37
 
36
- @@search_url = 'search.xml'
37
-
38
38
  @@item_info_url = 'item-info.xml'
39
39
  @@item_tooltip_url = 'item-tooltip.xml'
40
-
41
- @@icon_url = 'http://wowbench.com/images/icons/32x32/'
42
-
40
+
43
41
  @@arena_team_url = 'team-info.xml'
44
42
 
45
43
  @@max_connection_tries = 10
46
44
 
47
45
  # Tiny forum-used race/class icons
46
+ # @@icon_url = 'http://wowbench.com/images/icons/32x32/'
48
47
  # http://forums.worldofwarcraft.com/images/icon/class/4.gif
49
48
  # http://forums.worldofwarcraft.com/images/icon/race/3-0.gif
50
49
  # http://forums.worldofwarcraft.com/images/icon/pvpranks/rank_default_0.gif
@@ -111,8 +110,6 @@ module Wowr
111
110
 
112
111
  @@arena_team_sizes = [2, 3, 5]
113
112
 
114
- # TODO: Refactor, rethink and remove locale from all requests by passing unused options on to get_xml
115
-
116
113
  attr_accessor :character_name, :guild_name, :realm, :locale
117
114
 
118
115
  # You can set up the API with an optional default guild and realm
@@ -128,6 +125,7 @@ module Wowr
128
125
 
129
126
 
130
127
  # General-purpose search
128
+ # All specific searches are wrappers around this method.
131
129
  def search(options = {:search => nil, :type => nil})
132
130
  if @@search_types.include? options[:type]
133
131
  raise Wowr::Exceptions::InvalidSearchType.new
@@ -141,7 +139,7 @@ module Wowr
141
139
 
142
140
  results = []
143
141
 
144
- if (xml%'armorySearch'%'searchResults')
142
+ if (xml) && (xml%'armorySearch') && (xml%'armorySearch'%'searchResults')
145
143
  case options[:type]
146
144
 
147
145
  # TODO: Filter stuff
@@ -184,18 +182,10 @@ module Wowr
184
182
  return Wowr::Classes::CharacterSheet.new(xml)
185
183
  end
186
184
 
187
- def get_character_list(min_level, klass)
188
-
189
- end
190
-
191
- # ??
192
- def get_character_skills(options = {:character_name => @character_name, :realm => @realm})
193
- compute_hash(options.merge(:url => @@character_skills_url)) ||
194
- process_query(Wowr::Classes::Skill, @character_skills_url, false)
195
- end
196
185
 
197
186
 
198
187
  # Guilds
188
+ # Note searches go across all realms by default
199
189
  def search_guilds(options = {:search => @guild_name, :locale => @locale})
200
190
  options.merge!(:type => @@search_types[:guild])
201
191
  return search(options)
@@ -209,16 +199,17 @@ module Wowr
209
199
 
210
200
 
211
201
  # Items
202
+ # Items are not realm-specific
212
203
  def search_items(options = {:search => nil})
213
204
  options.merge!(:type => @@search_types[:item])
214
205
  return search(options)
215
206
  end
216
207
 
217
208
  # TODO: Is not finding the item an exception or just return nil?
218
- def get_item(options = {:item_id => nil, :locale => @locale})
209
+ #def get_item(options = {:item_id => nil, :locale => @locale})
219
210
 
220
211
  #return Wowr::Classes::ItemTooltip.new(xml%'itemTooltip')
221
- end
212
+ #end
222
213
 
223
214
  def get_item_info(options = {:item_id => nil, :locale => @locale})
224
215
  xml = get_xml(@@item_info_url, options)
@@ -331,6 +322,10 @@ module Wowr
331
322
  errors.each do |error|
332
323
  raise Wowr::Exceptions::raise_me(error[:errCode])
333
324
  end
325
+ # elsif (doc%'page').nil?
326
+ # puts full_query
327
+ # puts response
328
+ # raise Wowr::Exceptions::EmptyPage
334
329
  else
335
330
  return (doc%'page')
336
331
  end
@@ -342,14 +337,13 @@ module Wowr
342
337
 
343
338
  end
344
339
 
345
- # TODO: URL encoding of query strings
340
+ # :nodoc:
346
341
  def u(str)
347
342
  if str.instance_of?(String)
348
343
  return CGI.escape(str)
349
344
  else
350
345
  return str
351
346
  end
352
- #stripslashes(str)
353
347
  end
354
348
  end
355
349
  end
@@ -3,8 +3,7 @@
3
3
  # sourceType.questReward
4
4
  # sourceType.createdBySpell
5
5
 
6
- # TODO: Split up classes depending on subject?
7
- # Character, Item, Guild, ArenaTeam
6
+ # TODO: Split up classes depending on subject?  Character, Item, Guild, ArenaTeam
8
7
 
9
8
 
10
9
  # Wowr was written by Ben Humphreys!
@@ -12,6 +11,7 @@
12
11
  module Wowr
13
12
  module Classes
14
13
 
14
+ # Most basic
15
15
  # Composed of an ItemInfo and
16
16
  # Needs to be consolidated with ItemInfo and other stuff
17
17
  # to be a parent class that they extend?
@@ -28,6 +28,10 @@ module Wowr
28
28
 
29
29
 
30
30
  # Short character info, used in guild lists etc.
31
+ # Note that the way that searches and character listings within guilds works,
32
+ # there can be a variable amount of information filled in within the class.
33
+ # Guild listings and search results contain a smaller amount of information than
34
+ # single queries
31
35
  class Character
32
36
  attr_reader :name, :level, :url, :rank,
33
37
  :klass, :klass_id,
@@ -63,6 +67,8 @@ module Wowr
63
67
  @relevance = elem[:relevance].to_i
64
68
  @search_rank = elem[:searchRank].to_i
65
69
 
70
+ # Incoming string is 2007-02-24 20:33:04.0, parse to datetime
71
+ #@last_login = elem[:lastLoginDate] == "" ? nil : DateTime.parse(elem[:lastLoginDate])
66
72
  @last_login = elem[:lastLoginDate] == "" ? nil : elem[:lastLoginDate]
67
73
 
68
74
  # From ArenaTeam info, can be blank on normal requests
@@ -207,7 +213,7 @@ module Wowr
207
213
 
208
214
 
209
215
 
210
- # Note differences in values depending on class
216
+ # Second stat bar, depends on character class
211
217
  class SecondBar
212
218
  attr_reader :effective, :casting, :not_casting, :type
213
219
 
@@ -500,7 +506,7 @@ module Wowr
500
506
  end
501
507
  end
502
508
 
503
- class Resilience
509
+ class Resilience
504
510
  attr_reader :damage_percent, :hit_percent, :value
505
511
 
506
512
  def initialize(elem)
@@ -522,7 +528,7 @@ module Wowr
522
528
  end
523
529
 
524
530
 
525
- # TODO: Array starting at 1? Not sure if this is such a hot idea
531
+ # Note the list of talent trees starts at 1. This is quirky, but that's what's used in the XML
526
532
  class TalentSpec
527
533
  attr_reader :trees
528
534
 
@@ -594,25 +600,9 @@ module Wowr
594
600
  end
595
601
  end
596
602
 
597
-
598
-
599
- # class Damage
600
- # :type, :min, :max, :speed, :dps
601
- # end
602
- #
603
- # class ItemSource
604
- # :area_id
605
- # :area_name
606
- # :creature_id
607
- # :creature_name
608
- # :difficulty
609
- # :drop_rate
610
- # :value
611
- # end
612
603
 
613
604
  # A player guild containing members
614
- # note not all of these will be filled out, depending on how the data is found
615
-
605
+ # note not all of these will be filled out, depending on how the data is found
616
606
  class Guild
617
607
  attr_reader :name, :url, :realm, :realm_url, :battle_group,
618
608
  :roster_url, :stats_url, :stats_url_escape,
@@ -626,14 +616,14 @@ module Wowr
626
616
  guild = elem
627
617
  end
628
618
 
629
- @name = guild[:name]
630
- @name_url = guild[:nameUrl]
631
- @url = guild[:url]
632
- @realm = guild[:realm]
633
- @realm_url = guild[:realmUrl]
619
+ @name = guild[:name]
620
+ @name_url = guild[:nameUrl]
621
+ @url = guild[:url]
622
+ @realm = guild[:realm]
623
+ @realm_url = guild[:realmUrl]
634
624
  @battle_group = guild[:battleGroup]
635
- @faction = guild[:faction]
636
- @faction_id = guild[:factionId]
625
+ @faction = guild[:faction]
626
+ @faction_id = guild[:factionId].to_i
637
627
 
638
628
  # some shortened versions
639
629
  if (elem%'guildInfo')
@@ -648,31 +638,6 @@ module Wowr
648
638
  end
649
639
 
650
640
 
651
- # class Guild
652
- # attr_reader :name, :realm, :battle_group,
653
- # :roster_url, :stats_url, :stats_url_escape,
654
- # :members, :member_count
655
- #
656
- # def initialize(elem)
657
- # @name = elem[:name]
658
- # @realm = elem[:realm]
659
- # @battle_group = elem[:battleGroup]
660
- # @roster_url = elem[:rosterUrl]
661
- # @stats_url = elem[:statsUrl]
662
- # @stats_url_escape = elem[:statsUrlEscape]
663
- # @member_count = (elem%'members')[:memberCount].to_i
664
- #
665
- # @members = []
666
- # (elem%'members'/:character).each do |char|
667
- # members << Character.new(char)
668
- # end
669
- # end
670
- # end
671
-
672
-
673
-
674
-
675
-
676
641
  # General skill category
677
642
  # eg Weapon Skills, Languages
678
643
  class SkillCategory
@@ -738,7 +703,8 @@ module Wowr
738
703
 
739
704
 
740
705
  # Provides detailed item information
741
- # Reflects information found within item-tooltip.xml
706
+ # Note that the itemtooltip just returns an empty document when the item
707
+ # can't be found.
742
708
  class ItemTooltip < Item
743
709
  attr_reader :desc, :overall_quality_id, :bonding, :max_count, #:id, :name, :icon,
744
710
  :class_id, :bonuses, :item_source,
@@ -905,7 +871,6 @@ module Wowr
905
871
  end
906
872
  end
907
873
 
908
-
909
874
  class ItemDamageData
910
875
  attr_reader :type, :min, :max, :speed, :dps
911
876
 
@@ -1079,7 +1044,8 @@ module Wowr
1079
1044
  end
1080
1045
  end
1081
1046
 
1082
-
1047
+ # Cost can be gold or a set of required tokens
1048
+ # See ItemCostToken
1083
1049
  # <cost sellPrice="280" buyPrice="5600"></cost>
1084
1050
  # <cost>
1085
1051
  # <token icon="spell_holy_championsbond" id="29434" count="60"></token>
@@ -1293,7 +1259,6 @@ module Wowr
1293
1259
  @icon_style = elem[:iconStyle].to_i
1294
1260
  end
1295
1261
  end
1296
-
1297
1262
 
1298
1263
  end
1299
1264
  end
@@ -11,6 +11,9 @@ module Wowr
11
11
  class InvalidXML < StandardError
12
12
  end
13
13
 
14
+ class EmptyPage < StandardError
15
+ end
16
+
14
17
  # errCode="noCharacter"
15
18
  class CharacterNotFound < StandardError
16
19
  end
@@ -21,6 +24,9 @@ module Wowr
21
24
  class GuildNotFound < StandardError
22
25
  end
23
26
 
27
+ class SearchError < StandardError
28
+ end
29
+
24
30
  class InvalidSearchType < StandardError
25
31
  end
26
32
 
@@ -1,15 +1,5 @@
1
1
  module Wowr
2
- # All of these are shamelessly nicked from Ruby on Rails.
3
- # The String Extensions have a bit more fault tolerance.
4
2
  module Extensions
5
- module String
6
- def to_time(form = :utc)
7
- begin
8
- ::Time.send(form, *ParseDate.parsedate(self))
9
- rescue TypeError
10
- self
11
- end
12
- end
13
- end
3
+
14
4
  end
15
5
  end
metadata CHANGED
@@ -1,49 +1,58 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
3
- specification_version: 1
4
2
  name: wowr
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.1.1
7
- date: 2008-01-23 00:00:00 +00:00
8
- summary: An API wrapper for the World of Warcraft Armory.
9
- require_paths:
10
- - lib
11
- email: benhumphreys @nospam@ gmail.com
12
- homepage: http://wowr.rubyforge.org/
13
- rubyforge_project:
14
- description: Provides Ruby interface for retrieving item, character, guild and arena team info from the armory.
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.1.2
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Ben Humphreys
8
+ autorequire:
9
+ - wowr
10
+ - hpricot
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2008-02-07 00:00:00 +00:00
15
+ default_executable:
16
+ dependencies: []
17
+
18
+ description: Provides Ruby interface for retrieving item, character, guild and arena team info from the armory.
19
+ email: benhumphreys @nospam@ gmail.com
20
+ executables: []
21
+
22
+ extensions: []
23
+
24
+ extra_rdoc_files: []
25
+
31
26
  files:
32
27
  - lib/wowr.rb
33
28
  - lib/wowr/classes.rb
34
29
  - lib/wowr/exceptions.rb
35
30
  - lib/wowr/extensions.rb
36
- test_files: []
37
-
31
+ has_rdoc: true
32
+ homepage: http://wowr.rubyforge.org/
33
+ post_install_message:
38
34
  rdoc_options: []
39
35
 
40
- extra_rdoc_files: []
41
-
42
- executables: []
43
-
44
- extensions: []
45
-
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: "0"
43
+ version:
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
46
50
  requirements: []
47
51
 
48
- dependencies: []
52
+ rubyforge_project:
53
+ rubygems_version: 1.0.1
54
+ signing_key:
55
+ specification_version: 2
56
+ summary: An API wrapper for the World of Warcraft Armory.
57
+ test_files: []
49
58