wow 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 29c1df12f3b692c1612863da7d6044b651423923
4
+ data.tar.gz: a28ce99fa8091df0e1310e62f3809c4bcfad5767
5
+ SHA512:
6
+ metadata.gz: a3010a0a1f9411e8127696d9afc2835b45d8a56da773080224c6d930d893df981fa5e4ad8b4e11efb2e0545dde9cfd1db877a538cea74bb8d9ed11dfe7b24069
7
+ data.tar.gz: f30a85cbb7112ccfd101285aed663c1be9375b79bcfcda7e364be1b86c49af4c3e6a0d31cff4612d6c123b15fb7ccfc2ec1299d2c4a04d57e07902de4810026b
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruby_spark.gemspec
4
+ gemspec
@@ -0,0 +1,12 @@
1
+ require "wow"
2
+
3
+ # 25.times do |i|
4
+ # begin
5
+ # achive = WoW::Achievement.new(i)
6
+ # puts "#{achive[:id]} : #{achive[:title]}"
7
+ # rescue WoW::APIError
8
+ # puts "#{i} : No Achievement"
9
+ # end
10
+ # end
11
+
12
+ puts WoW::CharacterProfile.new("Stormreaver", "Epicgrim").lookup(:class)
@@ -0,0 +1,50 @@
1
+ require 'httparty'
2
+
3
+ require 'wow/version'
4
+ require 'wow/base'
5
+
6
+ module WoW
7
+ class ConfigurationError < StandardError; end
8
+ class APIError < StandardError; end
9
+
10
+ # Blizzard defined hosts, and locales.
11
+ # See http://blizzard.github.io/api-wow-docs/#features/access-and-regions
12
+
13
+ LOCALIZATIONS = {
14
+ 'us.battle.net' => ['en_US', 'es_MX', 'pt_BR'],
15
+ 'eu.battle.net' => ['en_GB', 'es_ES', 'fr_FR', 'ru_RU', 'de_DE', 'pt_PT', 'it_IT'],
16
+ 'kr.battle.net' => ['ko_KR'],
17
+ 'tw.battle.net' => ['zh_TW'],
18
+ 'www.battlenet.com.cn' => ['zh_CN'],
19
+ }
20
+
21
+ # Set defaults.
22
+ @host = 'us.battle.net'
23
+ @locale = 'en_US'
24
+
25
+ class << self
26
+ attr_reader :locale, :host
27
+
28
+ def locale=(value)
29
+ if LOCALIZATIONS[@host].include?(value)
30
+ @locale = value
31
+ else
32
+ raise ConfigurationError.new("Bad locale \"#{value}\" for host #{@host}.")
33
+ end
34
+ end
35
+
36
+ def host=(value)
37
+ if LOCALIZATIONS.has_key?(value)
38
+ @host = value
39
+ else
40
+ raise ConfigurationError.new("Bad host \"#{value}\".")
41
+ end
42
+ end
43
+
44
+ def configuration
45
+ yield self
46
+ end
47
+ end
48
+ end
49
+
50
+ require 'wow/features'
@@ -0,0 +1,21 @@
1
+ module WoW
2
+ class Base < Hash
3
+
4
+ def initialize(data)
5
+ data.each { |k,v| self[k] = v }
6
+
7
+ if self["status"] == "nok"
8
+ raise APIError.new(self["reason"])
9
+ end
10
+ end
11
+
12
+ def [](key)
13
+ super(key.to_sym)
14
+ end
15
+
16
+ def []=(key, value)
17
+ super(key.to_sym, value)
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ require 'wow/features/achievement'
2
+ require 'wow/features/auction_data'
3
+ require 'wow/features/battle_pet'
4
+ require 'wow/features/challenge_mode'
5
+ require 'wow/features/character_profile'
6
+ require 'wow/features/guild'
7
+ require 'wow/features/item'
8
+ require 'wow/features/leaderboard'
9
+ require 'wow/features/quest'
10
+ require 'wow/features/realm'
11
+ require 'wow/features/recipe'
12
+ require 'wow/features/spell'
@@ -0,0 +1,17 @@
1
+ module WoW
2
+ class Achievement < Base
3
+ include HTTParty
4
+ base_uri "#{WoW.host}/api/wow/achievement"
5
+
6
+ def initialize(id, params = {})
7
+ super(self.class.data(id, params))
8
+ end
9
+
10
+ class << self
11
+ def data(id, params = {})
12
+ params.merge!({locale: WoW.locale})
13
+ get("/#{id}", query: params).parsed_response
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ module WoW
2
+ class AuctionData
3
+ include HTTParty
4
+ base_uri "#{WoW.host}/api/wow/auction/data"
5
+
6
+ attr_reader :server, :last_modified, :url
7
+
8
+ def initialize(server, params = {})
9
+ response = self.class.data(server, params)
10
+
11
+ # Only use the first file for now...
12
+ file = response["files"][0]
13
+
14
+ @server = server
15
+ @last_modified = Time.at(file["lastModified"].to_i / 1000)
16
+ @url = file["url"]
17
+ end
18
+
19
+ def data
20
+ HTTParty.get(@url).parsed_response
21
+ end
22
+
23
+ class << self
24
+ def data(server, params = {})
25
+ params.merge!({locale: WoW.locale})
26
+ get("/#{server}", query: params).parsed_response
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,63 @@
1
+ module WoW
2
+ module BattlePet
3
+
4
+ class Ability < Base
5
+ include HTTParty
6
+ base_uri "#{WoW.host}/api/wow/battlePet/ability"
7
+
8
+ def initialize(id, params = {})
9
+ super(self.class.data(id, params))
10
+ end
11
+
12
+ class << self
13
+ def data(id, params = {})
14
+ params.merge!({locale: WoW.locale})
15
+ get("/#{id}", query: params).parsed_response
16
+ end
17
+ end
18
+ end
19
+
20
+ class Species < Base
21
+ include HTTParty
22
+ base_uri "#{WoW.host}/api/wow/battlePet/species"
23
+
24
+ def initialize(id, params = {})
25
+ super(self.class.data(id, params))
26
+ end
27
+
28
+ class << self
29
+ def data(id, params = {})
30
+ params.merge!({locale: WoW.locale})
31
+ get("/#{id}", query: params).parsed_response
32
+ end
33
+ end
34
+ end
35
+
36
+ class Stats < Base
37
+ include HTTParty
38
+ base_uri "#{WoW.host}/api/wow/battlePet/stats"
39
+
40
+ # This API accepts optional parameters.
41
+ #
42
+ # :level (default 1)
43
+ # :breedId (default 3)
44
+ # :qualityId (default 1)
45
+ #
46
+ # For example:
47
+ #
48
+ # WoW::BattlePet::Stats.new(132, level: 10)
49
+ #
50
+ def initialize(id, params = {})
51
+ super(self.class.data(id, params))
52
+ end
53
+
54
+ class << self
55
+ def data(id, params = {})
56
+ params.merge!({locale: WoW.locale})
57
+ get("/#{id}", query: params).parsed_response
58
+ end
59
+ end
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,22 @@
1
+ module WoW
2
+ module ChallengeMode
3
+
4
+ class Realm
5
+ include HTTParty
6
+ base_uri "#{WoW.host}/api/wow/challenge"
7
+
8
+ def initialize(realm, params = {})
9
+ params = params.merge({locale: WoW.locale})
10
+ #...
11
+ end
12
+
13
+ end
14
+
15
+ class Region < Realm
16
+ def initialize(params = {})
17
+ # super...
18
+ end
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,41 @@
1
+ module WoW
2
+ class CharacterProfile < Base
3
+ CLASSES = {
4
+ 1 => :warrior,
5
+ 2 => :paladin,
6
+ 3 => :hunter,
7
+ 4 => :rogue,
8
+ 5 => :priest,
9
+ 6 => :death_knight,
10
+ 7 => :shaman,
11
+ 8 => :mage,
12
+ 9 => :warlock,
13
+ 10 => :monk,
14
+ 11 => :druid,
15
+ }
16
+
17
+ include HTTParty
18
+ base_uri "#{WoW.host}/api/wow/character"
19
+
20
+ def initialize(realm, character_name, fields = [], params = {})
21
+ params = params.merge({fields: fields.join(',')})
22
+ super(self.class.data(realm, character_name, params))
23
+ end
24
+
25
+ def lookup(key)
26
+ case key
27
+ when :class
28
+ CLASSES[self[key]]
29
+ else
30
+ raise "No lookup mapping for #{key}"
31
+ end
32
+ end
33
+
34
+ class << self
35
+ def data(realm, character_name, params = {})
36
+ params.merge!({locale: WoW.locale})
37
+ get("/#{realm}/#{character_name}", query: params).parsed_response
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,18 @@
1
+ module WoW
2
+ class Guild < Base
3
+ include HTTParty
4
+ base_uri "#{WoW.host}/api/wow/guild"
5
+
6
+ def initialize(realm, guild_name, fields = [], params = {})
7
+ params = params.merge({fields: fields.join(',')})
8
+ super(self.class.data(realm, guild_name, params))
9
+ end
10
+
11
+ class << self
12
+ def data(realm, guild_name, params = {})
13
+ params.merge!({locale: WoW.locale})
14
+ get("/#{realm}/#{guild_name}", query: params).parsed_response
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,33 @@
1
+ module WoW
2
+ class Item < Base
3
+ include HTTParty
4
+ base_uri "#{WoW.host}/api/wow/item"
5
+
6
+ def initialize(id, params = {})
7
+ super(self.class.data(id, params))
8
+ end
9
+
10
+ class << self
11
+ def data(id, params = {})
12
+ params.merge!({locale: WoW.locale})
13
+ get("/#{id}", query: params).parsed_response
14
+ end
15
+ end
16
+ end
17
+
18
+ class Item::Set < Base
19
+ include HTTParty
20
+ base_uri "#{WoW.host}/api/wow/item/set"
21
+
22
+ def initialize(id, params = {})
23
+ super(self.class.data(id, params))
24
+ end
25
+
26
+ class << self
27
+ def data(id, params = {})
28
+ params.merge!({locale: WoW.locale})
29
+ get("/#{id}", query: params).parsed_response
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,17 @@
1
+ module WoW
2
+ class Leaderboard < Base
3
+ include HTTParty
4
+ base_uri "#{WoW.host}/api/wow/leaderboard"
5
+
6
+ def initialize(bracket, params = {})
7
+ super(self.class.data(bracket, params))
8
+ end
9
+
10
+ class << self
11
+ def data(bracket, params = {})
12
+ params.merge!({locale: WoW.locale})
13
+ get("/#{bracket}", query: params).parsed_response
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module WoW
2
+ class Quest < Base
3
+ include HTTParty
4
+ base_uri "#{WoW.host}/api/wow/quest"
5
+
6
+ def initialize(id, params = {})
7
+ super(self.class.data(id, params))
8
+ end
9
+
10
+ class << self
11
+ def data(id, params = {})
12
+ params.merge!({locale: WoW.locale})
13
+ get("/#{id}", query: params).parsed_response
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1 @@
1
+ # TODO: ...
@@ -0,0 +1,18 @@
1
+ module WoW
2
+ class Recipe < Base
3
+ include HTTParty
4
+ base_uri "#{WoW.host}/api/wow/recipe"
5
+
6
+ def initialize(id, params = {})
7
+ params = params.merge({fields: fields.join(',')})
8
+ super(self.class.data(id, params))
9
+ end
10
+
11
+ class << self
12
+ def data(id, params = {})
13
+ params.merge!({locale: WoW.locale})
14
+ get("/#{id}", query: params).parsed_response
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module WoW
2
+ class Spell < Base
3
+ include HTTParty
4
+ base_uri "#{WoW.host}/api/wow/spell"
5
+
6
+ def initialize(id, params = {})
7
+ params = params.merge({fields: fields.join(',')})
8
+ super(self.class.data(id, params))
9
+ end
10
+
11
+ class << self
12
+ def data(id, params = {})
13
+ params.merge!({locale: WoW.locale})
14
+ get("/#{id}", query: params).parsed_response
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module WoW
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wow/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'wow'
8
+ spec.version = WoW::VERSION
9
+ spec.authors = ['Nathan Lilienthal']
10
+ spec.email = ['nathan@nixpulvis.com']
11
+ spec.summary = 'World of Warcraft API Access.'
12
+ spec.description = 'A ruby library for accessing World of Warcraft data from Battle.net'
13
+ spec.homepage = 'https://github.com/nixpulvis/wow'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.test_files = spec.files.grep(%r{^spec/})
18
+
19
+ spec.add_development_dependency 'bundler', '~> 1.3'
20
+ spec.add_development_dependency 'rake', '~> 10.1'
21
+ spec.add_development_dependency 'rspec', '~> 2.14'
22
+
23
+ spec.add_dependency 'httparty', '~> 0'
24
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wow
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nathan Lilienthal
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A ruby library for accessing World of Warcraft data from Battle.net
70
+ email:
71
+ - nathan@nixpulvis.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - examples/example.rb
79
+ - lib/wow.rb
80
+ - lib/wow/base.rb
81
+ - lib/wow/features.rb
82
+ - lib/wow/features/achievement.rb
83
+ - lib/wow/features/auction_data.rb
84
+ - lib/wow/features/battle_pet.rb
85
+ - lib/wow/features/challenge_mode.rb
86
+ - lib/wow/features/character_profile.rb
87
+ - lib/wow/features/guild.rb
88
+ - lib/wow/features/item.rb
89
+ - lib/wow/features/leaderboard.rb
90
+ - lib/wow/features/quest.rb
91
+ - lib/wow/features/realm.rb
92
+ - lib/wow/features/recipe.rb
93
+ - lib/wow/features/spell.rb
94
+ - lib/wow/version.rb
95
+ - wow.gemspec
96
+ homepage: https://github.com/nixpulvis/wow
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.2.0
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: World of Warcraft API Access.
120
+ test_files: []