elekk 0.0.3 → 0.1.0
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 +4 -0
- data/VERSION +1 -1
- data/elekk.gemspec +6 -3
- data/lib/elekk.rb +1 -0
- data/lib/elekk/achievement.rb +39 -0
- data/lib/elekk/armory.rb +5 -2
- data/lib/elekk/character.rb +10 -2
- data/lib/elekk/http.rb +26 -3
- data/lib/elekk/wowhead.rb +3 -4
- data/spec/achievement_spec.rb +54 -0
- metadata +7 -4
data/CHANGELOG
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/elekk.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{elekk}
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Isaac Wasileski"]
|
12
|
-
s.date = %q{2010-06-
|
12
|
+
s.date = %q{2010-06-05}
|
13
13
|
s.description = %q{A simple library for World of Warcraft data in Ruby.}
|
14
14
|
s.email = %q{agnoster@gmail.com}
|
15
15
|
s.files = [
|
@@ -19,12 +19,14 @@ Gem::Specification.new do |s|
|
|
19
19
|
"VERSION",
|
20
20
|
"elekk.gemspec",
|
21
21
|
"lib/elekk.rb",
|
22
|
+
"lib/elekk/achievement.rb",
|
22
23
|
"lib/elekk/armory.rb",
|
23
24
|
"lib/elekk/character.rb",
|
24
25
|
"lib/elekk/data.rb",
|
25
26
|
"lib/elekk/http.rb",
|
26
27
|
"lib/elekk/wowhead.rb",
|
27
28
|
"readme.md",
|
29
|
+
"spec/achievement_spec.rb",
|
28
30
|
"spec/armory_spec.rb",
|
29
31
|
"spec/character_spec.rb",
|
30
32
|
"spec/klass_spec.rb",
|
@@ -36,7 +38,8 @@ Gem::Specification.new do |s|
|
|
36
38
|
s.rubygems_version = %q{1.3.7}
|
37
39
|
s.summary = %q{A simple library for World of Warcraft data in Ruby.}
|
38
40
|
s.test_files = [
|
39
|
-
"spec/
|
41
|
+
"spec/achievement_spec.rb",
|
42
|
+
"spec/armory_spec.rb",
|
40
43
|
"spec/character_spec.rb",
|
41
44
|
"spec/klass_spec.rb",
|
42
45
|
"spec/wowhead_spec.rb"
|
data/lib/elekk.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
module Elekk
|
2
|
+
class Achievement
|
3
|
+
attr_accessor :id, :title, :points, :icon, :description, :category, :completed
|
4
|
+
|
5
|
+
def initialize(id, opts={})
|
6
|
+
@id = id
|
7
|
+
@title = opts[:title]
|
8
|
+
@points = opts[:points]
|
9
|
+
@icon = opts[:icon]
|
10
|
+
@description = opts[:description]
|
11
|
+
@category = opts[:category]
|
12
|
+
@completed = opts[:completed]
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.from_xml(node)
|
16
|
+
a = self.new(node['id'].to_i, {
|
17
|
+
:title => node['title'].to_s,
|
18
|
+
:points => node['points'].to_i,
|
19
|
+
:icon => node['icon'].to_s,
|
20
|
+
:description => node['description'].to_s,
|
21
|
+
:category => Achievements[node['categoryId'].to_i]
|
22
|
+
})
|
23
|
+
a.completed = Time.parse(node['dateCompleted'].to_s) if node['dateCompleted']
|
24
|
+
a
|
25
|
+
end
|
26
|
+
|
27
|
+
def complete?
|
28
|
+
return !!completed
|
29
|
+
end
|
30
|
+
|
31
|
+
def wowhead
|
32
|
+
Wowhead::Result.new(@id, @title, Wowhead::Kind['Achievement'], @icon)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Achievements < Enum
|
37
|
+
add_item 'Raid', 168
|
38
|
+
end
|
39
|
+
end
|
data/lib/elekk/armory.rb
CHANGED
@@ -26,11 +26,14 @@ module Elekk
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def get_xml(resource, params=nil)
|
29
|
-
response = HTTP.
|
29
|
+
response = HTTP.xml(url(resource+'.xml'), params, {
|
30
30
|
:cache_timeout => 24*3600,
|
31
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
32
|
})
|
33
|
-
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.icon_url(icon)
|
36
|
+
"http://us.wowarmory.com/wow-icons/_images/51x51/#{icon}.jpg"
|
34
37
|
end
|
35
38
|
|
36
39
|
def url(path)
|
data/lib/elekk/character.rb
CHANGED
@@ -20,8 +20,16 @@ module Elekk
|
|
20
20
|
@sheet ||= xml :sheet
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
24
|
-
|
23
|
+
def achievements(category)
|
24
|
+
@achievements ||= {}
|
25
|
+
@achievements[category.to_sym] ||=
|
26
|
+
xml(:achievements, :c => category.to_i).css('achievement').map {|x| Achievement.from_xml x}
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def xml(resource, opts={})
|
31
|
+
opts = {:r => @realm, :cn => @name}.merge opts
|
32
|
+
self.armory.get_xml "character-#{resource}", opts
|
25
33
|
end
|
26
34
|
|
27
35
|
def klass
|
data/lib/elekk/http.rb
CHANGED
@@ -29,13 +29,36 @@ module Elekk
|
|
29
29
|
# default verb is GET
|
30
30
|
def self.request(url, params=nil, opts={})
|
31
31
|
self.init
|
32
|
-
opts = {:method => :get, :params => params, :timeout =>
|
32
|
+
opts = {:method => :get, :params => params, :timeout => 10000}.merge opts
|
33
33
|
|
34
34
|
request = Typhoeus::Request.new(url, opts)
|
35
|
-
|
35
|
+
|
36
36
|
@hydra.queue request
|
37
37
|
@hydra.run
|
38
|
-
request
|
38
|
+
request
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.xml(url, params=nil, opts={})
|
42
|
+
request = self.request(url, params, opts)
|
43
|
+
xml = Nokogiri::XML(request.response.body)
|
44
|
+
if xml.errors.length > 0
|
45
|
+
$stderr.write "XML Parse errors:\n"
|
46
|
+
p xml.errors
|
47
|
+
@cache.delete request.cache_key
|
48
|
+
end
|
49
|
+
xml
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.json(url, params=nil, opts={})
|
53
|
+
request = self.request(url, params, opts)
|
54
|
+
begin
|
55
|
+
json = JSON request.response.body
|
56
|
+
raise if json.nil?
|
57
|
+
rescue
|
58
|
+
$stderr.write "JSON Parse errors:\n"
|
59
|
+
@cache.delete request.cache_key
|
60
|
+
end
|
61
|
+
json
|
39
62
|
end
|
40
63
|
|
41
64
|
end
|
data/lib/elekk/wowhead.rb
CHANGED
@@ -3,8 +3,7 @@ require 'json'
|
|
3
3
|
module Elekk
|
4
4
|
class Wowhead
|
5
5
|
def self.search(term)
|
6
|
-
|
7
|
-
resp = JSON.parse(response.body)
|
6
|
+
resp = HTTP.json('http://www.wowhead.com/search', {:q => term, :opensearch => nil}, :cache_timeout => 60)
|
8
7
|
data = []
|
9
8
|
resp[1].each_with_index do |v,i|
|
10
9
|
d = resp[7][i]
|
@@ -15,7 +14,7 @@ module Elekk
|
|
15
14
|
end
|
16
15
|
|
17
16
|
class Result
|
18
|
-
attr_reader :
|
17
|
+
attr_reader :id, :name, :kind, :icon, :quality
|
19
18
|
|
20
19
|
def initialize(id, name, kind, icon=nil, quality=nil)
|
21
20
|
@id = id
|
@@ -39,7 +38,7 @@ module Elekk
|
|
39
38
|
end
|
40
39
|
|
41
40
|
def icon_url(size=:medium) # :small, :medium, or :large
|
42
|
-
"http://static.wowhead.com/images/wow/icons/#{size}/#{icon}.jpg" if icon
|
41
|
+
"http://static.wowhead.com/images/wow/icons/#{size}/#{icon.gsub(/'/,'-')}.jpg" if icon
|
43
42
|
end
|
44
43
|
|
45
44
|
def self.from_html(mkp)
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'elekk'
|
2
|
+
include Elekk
|
3
|
+
|
4
|
+
describe Achievement do
|
5
|
+
before :each do
|
6
|
+
@achievements = Character.new('Fyrbard','Uldaman').achievements(Achievements::Raid)
|
7
|
+
@oncebitten = @achievements.find {|a| a.id == 4539 }
|
8
|
+
@bane = @achievements.find {|a| a.id == 4608 }
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should give a list of achievements" do
|
12
|
+
@oncebitten.should_not be_nil
|
13
|
+
@bane.should_not be_nil
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have the correct title" do
|
17
|
+
@oncebitten.title.should == 'Once Bitten, Twice Shy (10 player)'
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have the correct icon" do
|
21
|
+
@oncebitten.icon.should == 'achievement_boss_lanathel'
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should have the correct category" do
|
25
|
+
@oncebitten.category.should == Achievements::Raid
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should have the correct point total as an integer" do
|
29
|
+
@oncebitten.points.should == 10
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should have the correct time of completion" do
|
33
|
+
@oncebitten.completed.to_i.should == 1274250840
|
34
|
+
@bane.completed.should be_nil
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should show correct completion state" do
|
38
|
+
@oncebitten.complete?.should == true
|
39
|
+
@bane.complete?.should == false
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should get the correct information to display on wowhead" do
|
43
|
+
@oncebitten.wowhead.url.should == 'http://www.wowhead.com/achievement=4539'
|
44
|
+
@oncebitten.wowhead.icon_url(:large).should == 'http://static.wowhead.com/images/wow/icons/large/achievement_boss_lanathel.jpg'
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should look bitchin when I print them all" do
|
48
|
+
@achievements.select {|a| a.complete?}.sort_by {|a| -a.completed.to_i}.each do |a|
|
49
|
+
puts "<a href=\"#{a.wowhead.url}\"><img src=\"#{Armory.icon_url(a.icon)}\" /> <img src=\"#{a.wowhead.icon_url(:large)}\" /> #{a.title}</a><br />"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elekk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.3
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Isaac Wasileski
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-06-
|
18
|
+
date: 2010-06-05 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -89,12 +89,14 @@ files:
|
|
89
89
|
- VERSION
|
90
90
|
- elekk.gemspec
|
91
91
|
- lib/elekk.rb
|
92
|
+
- lib/elekk/achievement.rb
|
92
93
|
- lib/elekk/armory.rb
|
93
94
|
- lib/elekk/character.rb
|
94
95
|
- lib/elekk/data.rb
|
95
96
|
- lib/elekk/http.rb
|
96
97
|
- lib/elekk/wowhead.rb
|
97
98
|
- readme.md
|
99
|
+
- spec/achievement_spec.rb
|
98
100
|
- spec/armory_spec.rb
|
99
101
|
- spec/character_spec.rb
|
100
102
|
- spec/klass_spec.rb
|
@@ -134,6 +136,7 @@ signing_key:
|
|
134
136
|
specification_version: 3
|
135
137
|
summary: A simple library for World of Warcraft data in Ruby.
|
136
138
|
test_files:
|
139
|
+
- spec/achievement_spec.rb
|
137
140
|
- spec/armory_spec.rb
|
138
141
|
- spec/character_spec.rb
|
139
142
|
- spec/klass_spec.rb
|