elekk 0.0.1
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/CHANGELOG +3 -0
- data/Manifest +14 -0
- data/Rakefile +23 -0
- data/elekk.gemspec +45 -0
- data/lib/elekk.rb +18 -0
- data/lib/elekk/armory.rb +40 -0
- data/lib/elekk/character.rb +78 -0
- data/lib/elekk/data.rb +139 -0
- data/lib/elekk/http.rb +42 -0
- data/lib/elekk/wowhead.rb +59 -0
- data/readme.md +8 -0
- data/spec/armory_spec.rb +44 -0
- data/spec/character_spec.rb +92 -0
- data/spec/klass_spec.rb +43 -0
- data/spec/wowhead_spec.rb +37 -0
- metadata +162 -0
data/CHANGELOG
ADDED
data/Manifest
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
CHANGELOG
|
2
|
+
Rakefile
|
3
|
+
lib/elekk.rb
|
4
|
+
lib/elekk/armory.rb
|
5
|
+
lib/elekk/character.rb
|
6
|
+
lib/elekk/data.rb
|
7
|
+
lib/elekk/http.rb
|
8
|
+
lib/elekk/wowhead.rb
|
9
|
+
readme.md
|
10
|
+
spec/armory_spec.rb
|
11
|
+
spec/character_spec.rb
|
12
|
+
spec/klass_spec.rb
|
13
|
+
spec/wowhead_spec.rb
|
14
|
+
Manifest
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'spec/rake/spectask'
|
4
|
+
require 'echoe'
|
5
|
+
|
6
|
+
Echoe.new('elekk') do |p|
|
7
|
+
p.summary = "A simple library for World of Warcraft data in Ruby."
|
8
|
+
p.description = "Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write access to the social graph via the Graph API and the older REST API, as well as support for realtime updates and OAuth and Facebook Connect authentication. Koala is fully tested and supports Net::HTTP and Typhoeus connections out of the box and can accept custom modules for other services."
|
9
|
+
p.url = "http://github.com/agnoster/elekk"
|
10
|
+
p.author = "Isaac Wasileski"
|
11
|
+
p.email = "agnoster@gmail.com"
|
12
|
+
p.ignore_pattern = ["tmp/*", "script/*", "pkg/*"]
|
13
|
+
p.development_dependencies = ['rspec']
|
14
|
+
p.runtime_dependencies = ['typhoeus', 'memcached', 'nokogiri', 'json']
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
desc "Run all tests"
|
19
|
+
Spec::Rake::SpecTask.new('spec') do |t|
|
20
|
+
t.spec_files = FileList['spec/**/*.rb']
|
21
|
+
t.spec_opts = ["--color", "--format", "specdoc"]
|
22
|
+
t.fail_on_error = false
|
23
|
+
end
|
data/elekk.gemspec
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{elekk}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Isaac Wasileski"]
|
9
|
+
s.date = %q{2010-06-04}
|
10
|
+
s.description = %q{Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write access to the social graph via the Graph API and the older REST API, as well as support for realtime updates and OAuth and Facebook Connect authentication. Koala is fully tested and supports Net::HTTP and Typhoeus connections out of the box and can accept custom modules for other services.}
|
11
|
+
s.email = %q{agnoster@gmail.com}
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "lib/elekk.rb", "lib/elekk/armory.rb", "lib/elekk/character.rb", "lib/elekk/data.rb", "lib/elekk/http.rb", "lib/elekk/wowhead.rb"]
|
13
|
+
s.files = ["CHANGELOG", "Rakefile", "lib/elekk.rb", "lib/elekk/armory.rb", "lib/elekk/character.rb", "lib/elekk/data.rb", "lib/elekk/http.rb", "lib/elekk/wowhead.rb", "readme.md", "spec/armory_spec.rb", "spec/character_spec.rb", "spec/klass_spec.rb", "spec/wowhead_spec.rb", "Manifest", "elekk.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/agnoster/elekk}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Elekk", "--main", "readme.md"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{elekk}
|
18
|
+
s.rubygems_version = %q{1.3.7}
|
19
|
+
s.summary = %q{A simple library for World of Warcraft data in Ruby.}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_runtime_dependency(%q<typhoeus>, [">= 0"])
|
27
|
+
s.add_runtime_dependency(%q<memcached>, [">= 0"])
|
28
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
29
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
30
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
31
|
+
else
|
32
|
+
s.add_dependency(%q<typhoeus>, [">= 0"])
|
33
|
+
s.add_dependency(%q<memcached>, [">= 0"])
|
34
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
35
|
+
s.add_dependency(%q<json>, [">= 0"])
|
36
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
37
|
+
end
|
38
|
+
else
|
39
|
+
s.add_dependency(%q<typhoeus>, [">= 0"])
|
40
|
+
s.add_dependency(%q<memcached>, [">= 0"])
|
41
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
42
|
+
s.add_dependency(%q<json>, [">= 0"])
|
43
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
44
|
+
end
|
45
|
+
end
|
data/lib/elekk.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
module Elekk
|
5
|
+
def self.default_region
|
6
|
+
@@default_region ||= :us
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.default_region=(r)
|
10
|
+
@@default_region = r
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
require File.dirname(__FILE__) + '/elekk/data'
|
15
|
+
require File.dirname(__FILE__) + '/elekk/http'
|
16
|
+
require File.dirname(__FILE__) + '/elekk/armory'
|
17
|
+
require File.dirname(__FILE__) + '/elekk/wowhead'
|
18
|
+
require File.dirname(__FILE__) + '/elekk/character'
|
data/lib/elekk/armory.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Elekk
|
2
|
+
class Armory
|
3
|
+
|
4
|
+
attr_accessor :realm
|
5
|
+
attr_reader :region
|
6
|
+
|
7
|
+
def initialize(*keywords)
|
8
|
+
opts = keywords.pop if keywords.last.class == {}.class
|
9
|
+
@realm = keywords.shift if keywords.length > 0
|
10
|
+
@region = keywords.shift if keywords.length > 0
|
11
|
+
|
12
|
+
if opts
|
13
|
+
@realm ||= opts[:realm]
|
14
|
+
@region ||= opts[:region]
|
15
|
+
end
|
16
|
+
|
17
|
+
@region ||= Elekk::default_region
|
18
|
+
end
|
19
|
+
|
20
|
+
def character(name)
|
21
|
+
Character.new name, @realm, :region => @region, :armory => self
|
22
|
+
end
|
23
|
+
|
24
|
+
def base
|
25
|
+
"http://#{@region}.wowarmory.com/"
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_xml(resource, params=nil)
|
29
|
+
response = HTTP.request(url(resource+'.xml'), params, {
|
30
|
+
:cache_timeout => 24*3600,
|
31
|
+
:user_agent => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.9) Gecko/20100315 Firefox/3.5.9'
|
32
|
+
})
|
33
|
+
Nokogiri::XML(response.body)
|
34
|
+
end
|
35
|
+
|
36
|
+
def url(path)
|
37
|
+
base + path
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Elekk
|
2
|
+
class Character
|
3
|
+
attr_reader :name, :realm, :region
|
4
|
+
attr_writer :armory
|
5
|
+
attr_reader :properties
|
6
|
+
|
7
|
+
def initialize(name, realm, opts={})
|
8
|
+
@name = name
|
9
|
+
@realm = realm
|
10
|
+
@region = opts[:region] || Elekk::default_region
|
11
|
+
@armory = opts[:armory]
|
12
|
+
@properties = { :name => @name, :realm => @realm, :region => @region }
|
13
|
+
end
|
14
|
+
|
15
|
+
def armory
|
16
|
+
@armory ||= Armory.new @realm, :region => @region
|
17
|
+
end
|
18
|
+
|
19
|
+
def sheet
|
20
|
+
@sheet ||= xml :sheet
|
21
|
+
end
|
22
|
+
|
23
|
+
def xml(resource)
|
24
|
+
self.armory.get_xml "character-#{resource}", :r => @realm, :cn => @name
|
25
|
+
end
|
26
|
+
|
27
|
+
def klass
|
28
|
+
@properties[:klass] ||= Klass[sheet.at_css('character')['classId'].to_i]
|
29
|
+
end
|
30
|
+
|
31
|
+
def faction
|
32
|
+
@properties[:faction] ||= Faction[sheet.at_css('character')['factionId'].to_i]
|
33
|
+
end
|
34
|
+
|
35
|
+
def race
|
36
|
+
@properties[:race] ||= Race[sheet.at_css('character')['raceId'].to_i]
|
37
|
+
end
|
38
|
+
|
39
|
+
def level
|
40
|
+
@properties[:level] ||= sheet.at_css('character')['level'].to_i
|
41
|
+
end
|
42
|
+
|
43
|
+
def gender
|
44
|
+
@properties[:gender] ||= Gender[sheet.at_css('character')['genderId'].to_i]
|
45
|
+
end
|
46
|
+
|
47
|
+
def points
|
48
|
+
@properties[:points] ||= sheet.at_css('character')['points'].to_i
|
49
|
+
end
|
50
|
+
|
51
|
+
def spec(which)
|
52
|
+
if not @properties[:specs]
|
53
|
+
specs = {}
|
54
|
+
primary = 0
|
55
|
+
sheet.css('talentSpecs talentSpec').each do |t|
|
56
|
+
n = t['group'].to_i-1
|
57
|
+
specs[n] = TalentTree.const_get(klass.to_sym)[t['prim'].to_s]
|
58
|
+
specs[:active] = specs[n] if t['active']
|
59
|
+
end
|
60
|
+
@properties[:specs] = specs
|
61
|
+
end
|
62
|
+
@properties[:specs][which]
|
63
|
+
end
|
64
|
+
|
65
|
+
def portrait
|
66
|
+
type = 'default'
|
67
|
+
[60, 70, 80].each { |m| type = m if level >= m }
|
68
|
+
|
69
|
+
@armory.url "_images/portraits/wow-#{type}/#{gender.id}-#{race.id}-#{klass.id}.gif"
|
70
|
+
end
|
71
|
+
|
72
|
+
def fullname(tag=nil)
|
73
|
+
n = name
|
74
|
+
n = "<#{tag}>#{n}</#{tag}>" if tag unless tag == ''
|
75
|
+
sheet.at_css('character')['prefix'] + n + sheet.at_css('character')['suffix']
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/elekk/data.rb
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
module Elekk
|
2
|
+
class Enum
|
3
|
+
attr_accessor :name, :id
|
4
|
+
|
5
|
+
def initialize(name, id)
|
6
|
+
@name = name
|
7
|
+
@id = id
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_sym
|
11
|
+
@symbol ||= @name.gsub(/\W/,'').to_sym
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.const_missing(name)
|
15
|
+
@hash[name]
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.[](idx)
|
19
|
+
if idx.is_a? Integer
|
20
|
+
@array[idx]
|
21
|
+
elsif idx.is_a? String
|
22
|
+
@hash[idx.gsub(/\W/,'').to_sym]
|
23
|
+
elsif idx.is_a? Symbol
|
24
|
+
@hash[idx]
|
25
|
+
else
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.add_item(name, id=nil?)
|
31
|
+
@hash ||= {}
|
32
|
+
@array ||= []
|
33
|
+
id ||= @array.length
|
34
|
+
if name.nil?
|
35
|
+
@array[id] = nil
|
36
|
+
else
|
37
|
+
k = self.new(name,id)
|
38
|
+
@array[id] = k
|
39
|
+
@hash[k.to_sym] = k
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.add_items(*arr)
|
44
|
+
start = arr.pop if arr.last.is_a? Integer
|
45
|
+
arr.each do |a|
|
46
|
+
self.add_item a, start
|
47
|
+
start = nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.each
|
52
|
+
@array.each do |v|
|
53
|
+
yield v unless v.nil?
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.find(cond=nil, &block)
|
58
|
+
each do |v|
|
59
|
+
if cond and not cond === v.to_s
|
60
|
+
next
|
61
|
+
end
|
62
|
+
if block and not yield v
|
63
|
+
next
|
64
|
+
end
|
65
|
+
return v
|
66
|
+
end
|
67
|
+
return nil
|
68
|
+
end
|
69
|
+
|
70
|
+
def to_s
|
71
|
+
@name
|
72
|
+
end
|
73
|
+
|
74
|
+
def to_i
|
75
|
+
@id
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class Klass < Enum
|
80
|
+
self.add_items nil, "Warrior", "Paladin", "Hunter", "Rogue", "Priest",
|
81
|
+
"Death Knight", "Shaman", "Mage", "Warlock", nil, "Druid"
|
82
|
+
end
|
83
|
+
|
84
|
+
class Faction < Enum
|
85
|
+
self.add_items 'Alliance', 'Horde'
|
86
|
+
end
|
87
|
+
|
88
|
+
class Race < Enum
|
89
|
+
self.add_items nil, 'Human', 'Orc', 'Dwarf', 'Night Elf', 'Undead',
|
90
|
+
'Tauren', 'Gnome', 'Troll', nil, 'Blood Elf', 'Draenei'
|
91
|
+
end
|
92
|
+
|
93
|
+
class Gender < Enum
|
94
|
+
self.add_items 'Male', 'Female'
|
95
|
+
end
|
96
|
+
|
97
|
+
class Quality < Enum
|
98
|
+
self.add_items 'Poor', 'Common', 'Uncommon', 'Rare', 'Epic', 'Legendary', 'Artifact', 'Heirloom'
|
99
|
+
end
|
100
|
+
|
101
|
+
class Kind < Enum
|
102
|
+
self.add_items nil, 'NPC', 'Object', 'Item', 'Item Set', 'Quest', 'Spell',
|
103
|
+
'Zone', 'Faction', 'Pet', 'Achievement'
|
104
|
+
self.add_items 'Class', 'Race', 'Skill', 13
|
105
|
+
end
|
106
|
+
|
107
|
+
module TalentTree
|
108
|
+
class Priest < Enum
|
109
|
+
self.add_items 'Discipline', 'Holy', 'Shadow'
|
110
|
+
end
|
111
|
+
class Warrior < Enum
|
112
|
+
self.add_items 'Arms', 'Fury', 'Protection'
|
113
|
+
end
|
114
|
+
class Shaman < Enum
|
115
|
+
self.add_items 'Elemental', 'Enhancement', 'Restoration'
|
116
|
+
end
|
117
|
+
class Druid < Enum
|
118
|
+
self.add_items 'Balance', 'Feral', 'Restoration'
|
119
|
+
end
|
120
|
+
class Paladin < Enum
|
121
|
+
self.add_items 'Holy', 'Protection', 'Retribution'
|
122
|
+
end
|
123
|
+
class Mage < Enum
|
124
|
+
self.add_items 'Arcane', 'Fire', 'Frost'
|
125
|
+
end
|
126
|
+
class Warlock < Enum
|
127
|
+
self.add_items 'Affliction', 'Demonology', 'Destruction'
|
128
|
+
end
|
129
|
+
class DeathKnight < Enum
|
130
|
+
self.add_items 'Blood', 'Frost', 'Unholy'
|
131
|
+
end
|
132
|
+
class Hunter < Enum
|
133
|
+
self.add_items 'Beast Mastery', 'Marksmanship', 'Survival'
|
134
|
+
end
|
135
|
+
class Rogue < Enum
|
136
|
+
self.add_items 'Assassination', 'Combat', 'Subtlety'
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
data/lib/elekk/http.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'typhoeus'
|
2
|
+
require 'memcached'
|
3
|
+
|
4
|
+
module Elekk
|
5
|
+
|
6
|
+
# All the web requests by Elekk go through here. It would be good
|
7
|
+
# to abstract this so it can use HTTP requesters other than Typhoeus
|
8
|
+
# someday.
|
9
|
+
class HTTP
|
10
|
+
|
11
|
+
# Do the set-up for Typhoeus and Memcache. Does not need to be called
|
12
|
+
# manually, it will set itself up when a request comes in.
|
13
|
+
def self.init
|
14
|
+
if @initialized
|
15
|
+
return
|
16
|
+
end
|
17
|
+
@initialized = true
|
18
|
+
@hydra = Typhoeus::Hydra.new
|
19
|
+
@cache = Memcached.new
|
20
|
+
@hydra.cache_setter do |request|
|
21
|
+
@cache.set request.cache_key, request.response, request.cache_timeout
|
22
|
+
end
|
23
|
+
@hydra.cache_getter do |request|
|
24
|
+
@cache.get(request.cache_key) rescue nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Do a synchronous request for the base url with params added,
|
29
|
+
# default verb is GET
|
30
|
+
def self.request(url, params=nil, opts={})
|
31
|
+
self.init
|
32
|
+
opts = {:method => :get, :params => params, :timeout => 1000}.merge opts
|
33
|
+
|
34
|
+
request = Typhoeus::Request.new(url, opts)
|
35
|
+
|
36
|
+
@hydra.queue request
|
37
|
+
@hydra.run
|
38
|
+
request.response
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Elekk
|
4
|
+
class Wowhead
|
5
|
+
def self.search(term)
|
6
|
+
response = HTTP.request('http://www.wowhead.com/search', {:q => term, :opensearch => nil}, :cache_timeout => 60)
|
7
|
+
resp = JSON.parse(response.body)
|
8
|
+
data = []
|
9
|
+
resp[1].each_with_index do |v,i|
|
10
|
+
d = resp[7][i]
|
11
|
+
kind = Kind[d[0]]
|
12
|
+
data.push Result.new d[1], v.gsub(/\s*\(#{kind}\)$/, ''), kind, d[2], d[3]
|
13
|
+
end
|
14
|
+
data
|
15
|
+
end
|
16
|
+
|
17
|
+
class Result
|
18
|
+
attr_reader :name, :id, :kind, :icon, :quality
|
19
|
+
|
20
|
+
def initialize(id, name, kind, icon=nil, quality=nil)
|
21
|
+
@id = id
|
22
|
+
@name = name
|
23
|
+
@kind = kind
|
24
|
+
@icon = icon
|
25
|
+
@quality = Quality[quality] if quality
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_s
|
29
|
+
@name
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_html
|
33
|
+
q = (@kind == Kind::Item) ? " class='q#{@quality.to_i}'" : ''
|
34
|
+
"<a href='#{url}'#{q}>#{@name}</a>"
|
35
|
+
end
|
36
|
+
|
37
|
+
def url
|
38
|
+
"http://www.wowhead.com/#{@kind.to_s.downcase}=#{@id}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def icon_url(size=:medium) # :small, :medium, or :large
|
42
|
+
"http://static.wowhead.com/images/wow/icons/#{size}/#{icon}.jpg" if icon
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.from_html(mkp)
|
46
|
+
html = Nokogiri.HTML(mkp)
|
47
|
+
link = html.at_css('a')
|
48
|
+
return unless link
|
49
|
+
if link['href'] =~ /wowhead.com\/(\w+)\=(\d+)/
|
50
|
+
id = $2
|
51
|
+
kind = Kind.find(/^#{$1}$/i)
|
52
|
+
quality = $1.to_i if kind == Kind::Item and link['class'] =~ /q(\d)/
|
53
|
+
end
|
54
|
+
name = link.content
|
55
|
+
Result.new id, name, kind, nil, quality
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/readme.md
ADDED
data/spec/armory_spec.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'elekk'
|
2
|
+
include Elekk
|
3
|
+
|
4
|
+
describe Armory do
|
5
|
+
before :each do
|
6
|
+
@armory = Armory.new 'Uldaman'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should have a default region" do
|
10
|
+
@armory.region.should == :us
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should have a region, even when freshly instantiated" do
|
14
|
+
a = Armory.new
|
15
|
+
a.region.should_not be_nil
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should have a default realm" do
|
19
|
+
@armory.realm.should == 'Uldaman'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should allow looking up of a Character" do
|
23
|
+
character = @armory.character 'Fyrbard'
|
24
|
+
character.should_not be_nil
|
25
|
+
character.name.should == 'Fyrbard'
|
26
|
+
character.armory.should == @armory
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should know the proper server to request from" do
|
30
|
+
@armory.base.should == 'http://us.wowarmory.com/'
|
31
|
+
eu_armory = Armory.new :region => :eu
|
32
|
+
eu_armory.base.should == 'http://eu.wowarmory.com/'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should build URLs relative to the server" do
|
36
|
+
@armory.url('character-sheet.xml').should == 'http://us.wowarmory.com/character-sheet.xml';
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should get xml from the armory" do
|
40
|
+
xml = @armory.get_xml 'character-sheet', :r => 'Uldaman', :cn => 'Fyrbard'
|
41
|
+
xml.should_not be_nil
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'elekk'
|
2
|
+
include Elekk
|
3
|
+
|
4
|
+
describe Character do
|
5
|
+
before :each do
|
6
|
+
@armory = Armory.new 'Uldaman', :us
|
7
|
+
@fyrbard = @armory.character 'Fyrbard'
|
8
|
+
@aldea = Character.new 'Aldea', 'Uldaman'
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have a name" do
|
12
|
+
@fyrbard.name.should == 'Fyrbard'
|
13
|
+
@aldea.name.should == 'Aldea'
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have a realm" do
|
17
|
+
@fyrbard.realm.should == 'Uldaman'
|
18
|
+
@aldea.realm.should == 'Uldaman'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should have a region" do
|
22
|
+
@fyrbard.region.should == :us
|
23
|
+
@aldea.region.should == :us
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should have a armory object" do
|
27
|
+
@fyrbard.armory.should_not be_nil
|
28
|
+
@aldea.armory.should_not be_nil
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should have an xml sheet" do
|
32
|
+
@fyrbard.sheet.should_not be_nil
|
33
|
+
@aldea.sheet.should_not be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should have the right class" do
|
37
|
+
@fyrbard.klass.should == Klass::Priest
|
38
|
+
@aldea.klass.should == Klass::Warrior
|
39
|
+
@armory.character('Ultimohombre').klass.should == Klass::DeathKnight
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should have the right level" do
|
43
|
+
@fyrbard.level.should == 80
|
44
|
+
@armory.character('Harimad').level.should == 16
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should have the right faction" do
|
48
|
+
@fyrbard.faction.should == Faction::Alliance
|
49
|
+
@armory.character('Tabularasa').faction.should == Faction::Horde
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should have the right race" do
|
53
|
+
@fyrbard.race.should == Race::Dwarf
|
54
|
+
@aldea.race.should == Race::Human
|
55
|
+
@armory.character('Alassiel').race.should == Race::NightElf
|
56
|
+
@armory.character('Wulffe').race.should == Race::Draenei
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should have the right gender" do
|
60
|
+
@fyrbard.gender.should == Gender::Male
|
61
|
+
@aldea.gender.should == Gender::Female
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should have the right specs" do
|
65
|
+
@fyrbard.spec(0).should == TalentTree::Priest::Shadow
|
66
|
+
@fyrbard.spec(1).should == TalentTree::Priest::Holy
|
67
|
+
@aldea.spec(:active).should == TalentTree::Warrior::Protection
|
68
|
+
@armory.character('Alassiel').spec(0).should == TalentTree::Hunter::BeastMastery
|
69
|
+
@armory.character('Alassiel').spec(0).name.should == 'Beast Mastery'
|
70
|
+
@armory.character('Ultimohombre').spec(0).should == TalentTree::DeathKnight::Frost
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should have the right points" do
|
74
|
+
@fyrbard.points.should >= 4000
|
75
|
+
@fyrbard.points.should <= 5000
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should have the right title" do
|
79
|
+
@fyrbard.fullname.should == 'Fyrbard Jenkins'
|
80
|
+
@aldea.fullname.should == 'Aldea of the Nightfall'
|
81
|
+
@aldea.fullname(:strong).should == '<strong>Aldea</strong> of the Nightfall'
|
82
|
+
@fyrbard.fullname('').should == 'Fyrbard Jenkins'
|
83
|
+
@armory.character('Bitterleaf').fullname('strong').should == 'Loremaster <strong>Bitterleaf</strong>'
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should generate the right image" do
|
87
|
+
@fyrbard.portrait.should == 'http://us.wowarmory.com/_images/portraits/wow-80/0-3-5.gif';
|
88
|
+
@aldea.portrait.should == 'http://us.wowarmory.com/_images/portraits/wow-80/1-1-1.gif';
|
89
|
+
@armory.character('Harimad').portrait.should == 'http://us.wowarmory.com/_images/portraits/wow-default/1-3-1.gif';
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
data/spec/klass_spec.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'elekk'
|
2
|
+
include Elekk
|
3
|
+
|
4
|
+
describe Klass do
|
5
|
+
it "should be properly indexed" do
|
6
|
+
dk = Klass.new "Death Knight", 11
|
7
|
+
dk.name.should == 'Death Knight'
|
8
|
+
dk.id.should == 11
|
9
|
+
dk.to_sym.should == :DeathKnight
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be findable as a constant" do
|
13
|
+
Klass::Priest.should_not be_nil
|
14
|
+
Klass::DeathKnight.should_not be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have a name" do
|
18
|
+
Klass::Priest.name.should == 'Priest'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should preserve spaces in name" do
|
22
|
+
Klass::DeathKnight.name.should == 'Death Knight'
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should be indexable by ints, strings and symbols" do
|
26
|
+
dk = Klass::DeathKnight
|
27
|
+
Klass[6].should == dk
|
28
|
+
Klass['Death Knight'].should == dk
|
29
|
+
Klass[:DeathKnight].should == dk
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should be convertible to an int" do
|
33
|
+
Klass::Priest.to_i.should == 5
|
34
|
+
end
|
35
|
+
it "should be convertible to a symbol" do
|
36
|
+
Klass::Priest.to_sym.should == :Priest
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should be convertible to a string" do
|
40
|
+
Klass::Priest.to_s.should == 'Priest'
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'elekk'
|
2
|
+
include Elekk
|
3
|
+
|
4
|
+
describe Wowhead do
|
5
|
+
before :each do
|
6
|
+
@q = Wowhead.search 'Varian'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should make search queries" do
|
10
|
+
@q.should_not be_nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should return good results" do
|
14
|
+
@q[0].kind.should == Kind::Item
|
15
|
+
@q[0].quality.should == Quality::Poor
|
16
|
+
@q[1].quality.should == Quality::Common
|
17
|
+
@q[2].quality.should == Quality::Epic
|
18
|
+
@q[3].kind.should == Kind['Object']
|
19
|
+
@q[4].kind.should == Kind::NPC
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should give links for results" do
|
23
|
+
@q[0].url.should == 'http://www.wowhead.com/item=43680'
|
24
|
+
@q[1].to_html.should == "<a href='http://www.wowhead.com/item=43440' class='q1'>To King Varian Wrynn of the Alliance</a>"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should give icons for results" do
|
28
|
+
@q[0].icon_url.should == 'http://static.wowhead.com/images/wow/icons/medium/INV_Misc_Coin_18.jpg'
|
29
|
+
@q[1].icon_url(:small).should == 'http://static.wowhead.com/images/wow/icons/small/INV_Scroll_15.jpg'
|
30
|
+
@q[2].icon_url(:large).should == 'http://static.wowhead.com/images/wow/icons/large/INV_Misc_Cape_16.jpg'
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should be correct when parsed from HTML" do
|
34
|
+
r = Wowhead::Result.from_html "<a href='http://www.wowhead.com/item=47547' class='q4'>Varian's Furor</a>"
|
35
|
+
r.to_html.should == "<a href='http://www.wowhead.com/item=47547' class='q4'>Varian's Furor</a>"
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: elekk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Isaac Wasileski
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-06-04 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: typhoeus
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: memcached
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: nokogiri
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :runtime
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: json
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
type: :runtime
|
76
|
+
version_requirements: *id004
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: rspec
|
79
|
+
prerelease: false
|
80
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
type: :development
|
90
|
+
version_requirements: *id005
|
91
|
+
description: Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write access to the social graph via the Graph API and the older REST API, as well as support for realtime updates and OAuth and Facebook Connect authentication. Koala is fully tested and supports Net::HTTP and Typhoeus connections out of the box and can accept custom modules for other services.
|
92
|
+
email: agnoster@gmail.com
|
93
|
+
executables: []
|
94
|
+
|
95
|
+
extensions: []
|
96
|
+
|
97
|
+
extra_rdoc_files:
|
98
|
+
- CHANGELOG
|
99
|
+
- lib/elekk.rb
|
100
|
+
- lib/elekk/armory.rb
|
101
|
+
- lib/elekk/character.rb
|
102
|
+
- lib/elekk/data.rb
|
103
|
+
- lib/elekk/http.rb
|
104
|
+
- lib/elekk/wowhead.rb
|
105
|
+
files:
|
106
|
+
- CHANGELOG
|
107
|
+
- Rakefile
|
108
|
+
- lib/elekk.rb
|
109
|
+
- lib/elekk/armory.rb
|
110
|
+
- lib/elekk/character.rb
|
111
|
+
- lib/elekk/data.rb
|
112
|
+
- lib/elekk/http.rb
|
113
|
+
- lib/elekk/wowhead.rb
|
114
|
+
- readme.md
|
115
|
+
- spec/armory_spec.rb
|
116
|
+
- spec/character_spec.rb
|
117
|
+
- spec/klass_spec.rb
|
118
|
+
- spec/wowhead_spec.rb
|
119
|
+
- Manifest
|
120
|
+
- elekk.gemspec
|
121
|
+
has_rdoc: true
|
122
|
+
homepage: http://github.com/agnoster/elekk
|
123
|
+
licenses: []
|
124
|
+
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options:
|
127
|
+
- --line-numbers
|
128
|
+
- --inline-source
|
129
|
+
- --title
|
130
|
+
- Elekk
|
131
|
+
- --main
|
132
|
+
- readme.md
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
none: false
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
hash: 3
|
141
|
+
segments:
|
142
|
+
- 0
|
143
|
+
version: "0"
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
hash: 11
|
150
|
+
segments:
|
151
|
+
- 1
|
152
|
+
- 2
|
153
|
+
version: "1.2"
|
154
|
+
requirements: []
|
155
|
+
|
156
|
+
rubyforge_project: elekk
|
157
|
+
rubygems_version: 1.3.7
|
158
|
+
signing_key:
|
159
|
+
specification_version: 3
|
160
|
+
summary: A simple library for World of Warcraft data in Ruby.
|
161
|
+
test_files: []
|
162
|
+
|