wowheadr 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ doc/*
5
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in wowhead.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ wowheadr: a Powered by Wowhead Library for Ruby
2
+ ===============================================
3
+
4
+ `wowheadr` (pronounced "wow header") is a Ruby gem designed to help leverage the power the [Powered by Wowhead JavaScript API][powered]. It can help generate links to items, achievements, spells, and other entities in the Wowhead database.
5
+
6
+ [powered]: http://www.wowhead.com/tooltips
7
+
8
+ Generating URLs
9
+ ---------------
10
+
11
+ You can generate URLs for (currently) items, achievements, and spells, providing you know the ID for the entity you want a URL for. Use the methods in `Wowheadr::URI` to generate the URLs. For example, to generate a URL for the item "Bloodied Prison Shank" (http://www.wowhead.com/item=43659), you would use:
12
+
13
+ Wowheadr::URI.item(43659)
14
+
15
+ And, to generate a URL for the ability "Path of Frost" (http://www.wowhead.com/spell=3714), you would use:
16
+
17
+ Wowheadr::URI.spell(3714)
18
+
19
+ Advanced Usage
20
+ --------------
21
+
22
+ Wowhead provides the ability to customize links to various entities on their site using the `rel` property of the HTML link tag. Wowheadr supports this via the `Wowheadr::Entity` classes. (Currently, only `Item` is available.)
23
+
24
+ For example, to get the `rel` attribute for a link to a "Bloodied Arcanite Reaper" (http://www.wowhead.com/item=42943) tuned for a level 25 character, you can use:
25
+
26
+ Wowheadr::Entity::Item.new(42943).level(25).to_s
27
+
28
+ (Calling `to_s` on any `Entity` class returns the text that should be placed in the `rel` attribute of your link, as shown:)
29
+
30
+ <a hef="http://non-wowhead-site.com" rel="item=42943&amp;lvl=25">Got an awesome new item for my character</a>
31
+
32
+ You can add enchants, gems, sockets, other set pieces, and more to an `Entity`:
33
+
34
+ Wowheadr::Entity::Item.new(25697).gems(23121).enchant(2647).pieces(25695, 25696, 25697)
35
+
36
+ More Awesomeness
37
+ ----------------
38
+
39
+ More is planned in the immediate future, including a Ruby on Rails gem that provides various helper methods to make integrating Powered by Wowhead even easier. Stay tuned!
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler'
2
+ require 'rake/testtask'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "libs"
7
+ t.test_files = FileList["test/**/*.rb"]
8
+ t.verbose = false
9
+ end
@@ -0,0 +1,76 @@
1
+ require 'wowheadr/uri/rel'
2
+
3
+ module Wowheadr
4
+ module Entity
5
+ # Wowheadr::Entity::Item represents a +rel+ entry in an HTML link tag to
6
+ # specify details about the item being linked to. A list of key/value
7
+ # combinations can be found at
8
+ # http://www.wowhead.com/tooltips#related-advanced-usage
9
+ class Item
10
+ include Wowheadr::URI::Rel
11
+
12
+ # Create a new Item and optionally pass in the ID,
13
+ # which automatically calls #item on the new object.
14
+ def initialize(id = nil)
15
+ super()
16
+ unless id.nil?
17
+ self.item(id)
18
+ end
19
+ self
20
+ end
21
+
22
+ # Set the item ID for the item. Useful if the +href+ attribute of the
23
+ # link does not lead to the item's URL on wowhead.com (custom URLs).
24
+ def item(id)
25
+ self.set(:item, id)
26
+ end
27
+
28
+ # Set the character's level, useful for heirloom items.
29
+ def level(level)
30
+ self.set(:lvl, level)
31
+ end
32
+ alias :lvl :level
33
+
34
+ # Set the item's enchant using the enchant's ID.
35
+ def enchantment(enchant_id)
36
+ self.set(:ench, enchant_id)
37
+ end
38
+ alias :ench :enchantment
39
+ alias :enchant :enchantment
40
+
41
+ # Add the specified gems to the items gem slots using the gems' IDs.
42
+ # gems can be a single gem ID, multiple gem IDs, an array of gem IDs,
43
+ # or a colon-delimited string of gem IDs.
44
+ def gems(*gems)
45
+ if gems.is_a? String
46
+ self.add(:gems, gems.split(':'))
47
+ else
48
+ self.add(:gems, gems)
49
+ end
50
+ end
51
+
52
+ # Whether or not to add an extra gem socket to the item.
53
+ def socket(socket)
54
+ self.set(:sock, socket)
55
+ end
56
+ alias :extra_socket :socket
57
+ alias :sock :socket
58
+
59
+ def pieces(*pieces)
60
+ if pieces.is_a? String
61
+ self.add(:pcs, pieces.split(':'))
62
+ else
63
+ self.add(:pcs, pieces)
64
+ end
65
+ end
66
+ alias :set_pieces :pieces
67
+ alias :pcs :pieces
68
+
69
+ def random_enchantment(enchant_id)
70
+ self.set(:rand, enchant_id)
71
+ end
72
+ alias :rand :random_enchantment
73
+ alias :rand_enchant :random_enchantment
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,65 @@
1
+ module Wowheadr
2
+ module URI
3
+ # Wowheadr::URI::Rel defines methods for creating the +rel+ portion of a
4
+ # link using the Powered by Wowhead API. For a list of supported
5
+ # attributes, see http://www.wowhead.com/tooltips#related-advanced-usage
6
+ #
7
+ # Once the key/value combinations for the wowhead.com entity have been
8
+ # set, you can retrieve the text for the +rel+ portion of an HTML link
9
+ # tag by calling +to_s+ on the object.
10
+ #
11
+ # The methods to modify the data inside a Rel is protected, and a Rel
12
+ # object can not be instantiated--instead, subclasses of Rel which
13
+ # represent specific Wowhead entries with known rel attributes) should
14
+ # be created and used instead.
15
+ module Rel
16
+ # Set the wowhead domain (www, ptr, de, es, fr, ru)
17
+ # to display a different version or localization.
18
+ def domain(domain)
19
+ self.set(:domain, domain)
20
+ end
21
+
22
+ # Return the complete "rel" portion of the URL.
23
+ def to_s
24
+ return nil if @data.empty?
25
+
26
+ @data.collect do |key, value|
27
+ # Array values are concatenated by colons
28
+ if value.is_a? Array
29
+ "#{key}=#{value.join(':')}"
30
+ # Boolean values don't have a right-side assignment
31
+ elsif value.class == TrueClass || value.class == FalseClass
32
+ key
33
+ # All other values get the standard behavior
34
+ else
35
+ "#{key}=#{value.to_s}"
36
+ end
37
+ end.join "&amp;"
38
+ end
39
+
40
+ protected
41
+
42
+ # Protected self.new to keep from being instantiated
43
+ def self.new
44
+ end
45
+
46
+ def initialize
47
+ @instance = nil
48
+ @data = {}
49
+ end
50
+
51
+ # Set the given key to a single value.
52
+ def set(key, value)
53
+ @data[key.to_s] = value
54
+ self
55
+ end
56
+
57
+ # Add a value or an array of values to the given key.
58
+ def add(key, value)
59
+ @data[key.to_s] ||= []
60
+ @data[key.to_s] << value
61
+ self
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,18 @@
1
+ module Wowheadr
2
+ module URI
3
+ BASE_URL = "http://www.wowhead.com/"
4
+ JAVASCRIPT = "http://static.wowhead.com/widgets/power.js"
5
+
6
+ def self.item(id)
7
+ "#{BASE_URL}item=#{id}"
8
+ end
9
+
10
+ def self.achievement(id)
11
+ "#{BASE_URL}achievement=#{id}"
12
+ end
13
+
14
+ def self.spell(id)
15
+ "#{BASE_URL}spell=#{id}"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module Wowheadr
2
+ VERSION = "0.0.1"
3
+ end
data/lib/wowheadr.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'wowheadr/version'
2
+ require 'wowheadr/entity/item'
3
+ require 'wowheadr/uri'
4
+ require 'wowheadr/uri/rel'
@@ -0,0 +1,93 @@
1
+ require 'test/unit'
2
+ require 'wowheadr/entity/item'
3
+
4
+ class ItemTest < Test::Unit::TestCase
5
+ def setup
6
+ @item = Wowheadr::Entity::Item.new
7
+ end
8
+
9
+ def test_item
10
+ @item.item(12345)
11
+ assert_equal "item=12345", @item.to_s
12
+ end
13
+
14
+ def test_new_item
15
+ item = Wowheadr::Entity::Item.new(12345).level(10)
16
+ assert_equal "item=12345&amp;lvl=10", item.to_s
17
+ end
18
+
19
+ def test_level
20
+ @item.level(10)
21
+ assert_equal "lvl=10", @item.to_s
22
+ end
23
+
24
+ def test_lvl
25
+ @item.lvl(10)
26
+ assert_equal "lvl=10", @item.to_s
27
+ end
28
+
29
+ def test_enchant
30
+ @item.enchantment(501)
31
+ assert_equal "ench=501", @item.to_s
32
+ end
33
+
34
+ def test_ench
35
+ @item.ench(501)
36
+ assert_equal "ench=501", @item.to_s
37
+ end
38
+
39
+ def test_gems
40
+ @item.gems(101)
41
+ assert_equal "gems=101", @item.to_s
42
+ end
43
+
44
+ def test_multiple_gems
45
+ @item.gems(101, 201, 301)
46
+ assert_equal "gems=101:201:301", @item.to_s
47
+ end
48
+
49
+ def test_multiple_gems_array
50
+ @item.gems([101, 201, 301])
51
+ assert_equal "gems=101:201:301", @item.to_s
52
+ end
53
+
54
+ def test_gems_string
55
+ @item.gems('101:201:301')
56
+ assert_equal "gems=101:201:301", @item.to_s
57
+ end
58
+
59
+ def test_pieces
60
+ @item.pieces(101)
61
+ assert_equal "pcs=101", @item.to_s
62
+ end
63
+
64
+ def test_multiple_pieces
65
+ @item.pieces(101, 201, 301)
66
+ assert_equal "pcs=101:201:301", @item.to_s
67
+ end
68
+
69
+ def test_multiple_pieces_array
70
+ @item.pieces([101, 201, 301])
71
+ assert_equal "pcs=101:201:301", @item.to_s
72
+ end
73
+
74
+ def test_pieces_string
75
+ @item.pieces('101:201:301')
76
+ assert_equal "pcs=101:201:301", @item.to_s
77
+ end
78
+
79
+ def test_random_enchantment
80
+ @item.random_enchantment('103')
81
+ assert_equal "rand=103", @item.to_s
82
+ end
83
+
84
+ def test_socket
85
+ @item.socket(true)
86
+ assert_equal "sock", @item.to_s
87
+ end
88
+
89
+ def test_chaining
90
+ @item.level(10).enchant(501).gems(101, 201).socket(true)
91
+ assert_equal "lvl=10&amp;ench=501&amp;gems=101:201&amp;sock", @item.to_s
92
+ end
93
+ end
@@ -0,0 +1,63 @@
1
+ require 'test/unit'
2
+ require 'wowheadr/uri/rel'
3
+
4
+ # Set up a fake entity to include our Wowhead::Rel module in.
5
+ class FakeEntity
6
+ include Wowheadr::URI::Rel
7
+ end
8
+
9
+ class RelTest < Test::Unit::TestCase
10
+ def setup
11
+ @rel = FakeEntity.new
12
+ end
13
+
14
+ def test_no_entries
15
+ assert_nil @rel.to_s
16
+ end
17
+
18
+ def test_set
19
+ @rel.send(:set, :lvl, 10)
20
+ assert_equal "lvl=10", @rel.to_s
21
+ end
22
+
23
+ def test_multiple_set
24
+ @rel.send(:set, :lvl, 10)
25
+ @rel.send(:set, :color, "red")
26
+ assert_equal "lvl=10&amp;color=red", @rel.to_s
27
+ end
28
+
29
+ def test_overwrite_set
30
+ @rel.send(:set, :lvl, 10)
31
+ @rel.send(:set, :lvl, 20)
32
+ assert_equal "lvl=20", @rel.to_s
33
+ end
34
+
35
+ def test_add
36
+ @rel.send(:add, :socket, "a")
37
+ @rel.send(:add, :socket, "b")
38
+ assert_equal "socket=a:b", @rel.to_s
39
+ end
40
+
41
+ def test_multiple_add
42
+ @rel.send(:add, :socket, ["a", "b", "c"])
43
+ assert_equal "socket=a:b:c", @rel.to_s
44
+ end
45
+
46
+ def test_set_add
47
+ @rel.send(:set, :lvl, 20)
48
+ @rel.send(:add, :gem, "first")
49
+ @rel.send(:set, :color, "blue")
50
+ @rel.send(:add, :gem, "second")
51
+ assert_equal "lvl=20&amp;gem=first:second&amp;color=blue", @rel.to_s
52
+ end
53
+
54
+ def test_set_bool
55
+ @rel.send(:set, :socket, true)
56
+ assert_equal "socket", @rel.to_s
57
+ end
58
+
59
+ def test_domain
60
+ @rel.domain('ptr')
61
+ assert_equal "domain=ptr", @rel.to_s
62
+ end
63
+ end
@@ -0,0 +1,20 @@
1
+ require 'test/unit'
2
+ require 'wowheadr/uri'
3
+
4
+ class URITest < Test::Unit::TestCase
5
+ def test_js_url
6
+ assert_equal Wowheadr::URI::JAVASCRIPT, "http://static.wowhead.com/widgets/power.js"
7
+ end
8
+
9
+ def test_item_url
10
+ assert_equal Wowheadr::URI.item(12345), "http://www.wowhead.com/item=12345"
11
+ end
12
+
13
+ def test_achievement_url
14
+ assert_equal Wowheadr::URI.achievement(12345), "http://www.wowhead.com/achievement=12345"
15
+ end
16
+
17
+ def test_spell_url
18
+ assert_equal Wowheadr::URI.spell(12345), "http://www.wowhead.com/spell=12345"
19
+ end
20
+ end
data/wowheadr.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "wowheadr/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "wowheadr"
7
+ s.version = Wowheadr::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Brandon Tilley"]
10
+ s.email = ["binarymuse@binarymuse.net"]
11
+ s.homepage = "https://github.com/BinaryMuse/wowhead"
12
+ s.summary = "wowheadr #{Wowheadr::VERSION}"
13
+ s.description = "Leverage the power of Wowhead for your Ruby projects."
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wowheadr
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Brandon Tilley
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-11-28 00:00:00 -08:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Leverage the power of Wowhead for your Ruby projects.
22
+ email:
23
+ - binarymuse@binarymuse.net
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - README.md
34
+ - Rakefile
35
+ - lib/wowheadr.rb
36
+ - lib/wowheadr/entity/item.rb
37
+ - lib/wowheadr/uri.rb
38
+ - lib/wowheadr/uri/rel.rb
39
+ - lib/wowheadr/version.rb
40
+ - test/wowheadr/entity/item_test.rb
41
+ - test/wowheadr/uri.rb
42
+ - test/wowheadr/uri/rel_test.rb
43
+ - wowheadr.gemspec
44
+ has_rdoc: true
45
+ homepage: https://github.com/BinaryMuse/wowhead
46
+ licenses: []
47
+
48
+ post_install_message:
49
+ rdoc_options: []
50
+
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ requirements: []
70
+
71
+ rubyforge_project:
72
+ rubygems_version: 1.3.7
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: wowheadr 0.0.1
76
+ test_files:
77
+ - test/wowheadr/entity/item_test.rb
78
+ - test/wowheadr/uri.rb
79
+ - test/wowheadr/uri/rel_test.rb