wowapi 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +19 -0
- data/LICENSE.txt +6 -0
- data/README.md +104 -0
- data/lib/wowapi/core_extensions/object/try.rb +16 -0
- data/lib/wowapi/exceptions/api_exception.rb +7 -0
- data/lib/wowapi/exceptions/auth_exception.rb +7 -0
- data/lib/wowapi/exceptions/no_credentials_exception.rb +7 -0
- data/lib/wowapi/exceptions/region_exception.rb +7 -0
- data/lib/wowapi/exceptions.rb +4 -0
- data/lib/wowapi/modules/guild.rb +16 -0
- data/lib/wowapi/version.rb +4 -0
- data/lib/wowapi/wowapi.rb +60 -0
- data/lib/wowapi.rb +1 -0
- data/wowapi.gemspec +25 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e686e355a23bee293048d3ad3763e1b095b76fb8
|
4
|
+
data.tar.gz: 925371780e6d9bd96ce59ce4226e1da0b13324ca
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0561ca37e80e469de28109c003c92dc410a55996c01d287c9a4903002453cf1a2441aac3bcc26b0002e75d50678af4cf492f00c5847f6ba8548b949b12d615bf
|
7
|
+
data.tar.gz: 0a886207b1266b9d841d6a080133acc427d71581fb98e17e12db2844a253b7e1022065513f02e0e1f068a40e12204f61fad27760b6a86ba10b952a48ef78d827
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
coderay (1.1.1)
|
5
|
+
method_source (0.8.2)
|
6
|
+
pry (0.10.4)
|
7
|
+
coderay (~> 1.1.0)
|
8
|
+
method_source (~> 0.8.1)
|
9
|
+
slop (~> 3.4)
|
10
|
+
slop (3.6.0)
|
11
|
+
|
12
|
+
PLATFORMS
|
13
|
+
ruby
|
14
|
+
|
15
|
+
DEPENDENCIES
|
16
|
+
pry
|
17
|
+
|
18
|
+
BUNDLED WITH
|
19
|
+
1.12.5
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
2
|
+
|
3
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
4
|
+
|
5
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
6
|
+
|
data/README.md
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
# WoWAPI
|
2
|
+
**EARLY STAGE DEVELOPMENT. HERE BE DRAGONS**
|
3
|
+
However, you are welcome to contribute and/or criticise (and/or) show me the way to handle things.
|
4
|
+
|
5
|
+
# What this is
|
6
|
+
**WoWAPI** project is created by [Jasiek ~marahin Matusz](https://marahin.pl/) with it's source on [git.3lab.re](https://git.3lab.re/marahin/wowapi), licensed under MIT license.
|
7
|
+
|
8
|
+
This is a Ruby library, so called _gem_. It is targetted to be used in Ruby scripts, [Rails](http://rubyonrails.org/), [Sinatra](http://www.sinatrarb.com/) or anything that uses Ruby.
|
9
|
+
|
10
|
+
This project began during a search for an easy-to-use gem that allows to access Blizzard's World of Warcraft Community API with ease. It is based on (now deprecated) [Battlenet GEM](https://github.com/BinaryMuse/battlenet) by [BinaryMuse](https://github.com/BinaryMuse), however it focuses purely on World of Warcraft.
|
11
|
+
|
12
|
+
## What does it do?
|
13
|
+
|
14
|
+
**WoWAPI** is a library that's dependant on _open-uri_ and _json_. Both are built-in Ruby libraries. Nothing more than that, just plain Ruby.
|
15
|
+
|
16
|
+
## How do I use this?
|
17
|
+
|
18
|
+
|
19
|
+
### Guilds
|
20
|
+
|
21
|
+
Guilds can take couple of arguments to query:
|
22
|
+
|
23
|
+
* news
|
24
|
+
* achievements
|
25
|
+
* challenge
|
26
|
+
* members
|
27
|
+
|
28
|
+
Each of these will expand (temporarily*) returned Hash.
|
29
|
+
|
30
|
+
_* temporarily_ - in the end-stage of development I dream of having a `GuildClass` which would have a standardized structure. For now it just returns a `JSON.parse(obj)`, which is a simple `Hash`.
|
31
|
+
Please keep in mind that I am a working student. (:
|
32
|
+
|
33
|
+
```
|
34
|
+
require 'wowapi'
|
35
|
+
|
36
|
+
api = Wowapi.new do |config|
|
37
|
+
config.public_key = 'your-public-apikey'
|
38
|
+
# config.secret_Key = 'optional-secret-key'
|
39
|
+
# config.region = :us # (optional)
|
40
|
+
end
|
41
|
+
|
42
|
+
api.guild('Argent Dawn', 'The Aspects')
|
43
|
+
# => {"lastModified"=>1472853622000, "name"=>"The Aspects", "realm"=>"Argent Dawn", "battlegroup"=>"Reckoning / Abrechnung", "level"=>25, "side"=>1, "achievementPoints"=>1590, "emblem"=>{"icon"=>140, "iconColor"=>"ffdfa55a", "iconColorId"=>16, "border"=>1, "borderColor"=>"fff9cc30", "borderColorId"=>16, "backgroundColor"=>"ff232323", "backgroundColorId"=>45}}
|
44
|
+
|
45
|
+
```
|
46
|
+
|
47
|
+
#### Guild fields
|
48
|
+
|
49
|
+
* news ([pastebin](http://d.gimb.us/b/fe26c9f380477d3a0293072385e61cab.txt))
|
50
|
+
|
51
|
+
```
|
52
|
+
irb(main):005:0> api.guild 'Argent Dawn', 'The Aspects', :news
|
53
|
+
=> {"lastModified"=>1472853622000, "name"=>"The Aspects", "realm"=>"Argent Dawn", "battlegroup"=>"Reckoning / Abrechnung", "level"=>25, "side"=>1, "achievementPoints"=>1590, "emblem"=>{"icon"=>140, "iconColor"=>"ffdfa55a", "iconColorId"=>16, "border"=>1, "borderColor"=>"fff9cc30", "borderColorId"=>16, "backgroundColor"=>"ff232323", "backgroundColorId"=>45}, "news"=>[{"type"=>"itemLoot", "character"=>"Tormenthowl", "timestamp"=>1472858400000, "itemId"=>124325, "context"=>"raid-mythic", "bonusLists"=>[1799, 1502]}, {"type"=>"itemLoot", "character"=>"Tormenthowl", "timestamp"=>1472858400000, "itemId"=>113900, "context"=>"raid-mythic", "bonusLists"=>[567]}, {"type"=>"itemLoot", "character"=>"Humbakos", "timestamp"=>1472857980000, "itemId"=>130132, "context"=>"", "bonusLists"=>[1794, 1735]}, {"type"=>"itemLoot", "character"=>"Seszel", "timestamp"=>1472854680000, "itemId"=>131799, "context"=>"", "bonusLists"=>[1794, 1735]}, {"type"=>"itemLoot", "character"=>"Kurrash", "timestamp"=>1472854500000, "itemId"=>132970, "context"=>"quest-reward", "bonusLists"=>[767, 1734]}, {"type"=>"itemLoot", "character"=>"Greenzog", "timestamp"=>1472853960000, "itemId"=>131921, "context"=>"", "bonusLists"=>[1794, 1735]}, {"type"=>"itemLoot", "character"=>"Humbakos", "timestamp"=>1472853480000, "itemId"=>121660, "context"=>"quest-reward", "bonusLists"=>[768, 1740]}, {"type"=>"itemLoot", "character"=>"Dzidu", "timestamp"=>1472853060000, "itemId"=>138418, "context"=>"", "bonusLists"=>[1794, 1735]}, $$__***<<< A LOT OF DATA ... >>>***__$$ {"type"=>"itemLoot", "character"=>"Olvarus", "timestamp"=>1472248680000, "itemId"=>109970, "context"=>"dungeon-mythic", "bonusLists"=>[43, 642, 643]}, {"type"=>"playerAchievement", "character"=>"Guldav", "timestamp"=>1472247960000, "context"=>"", "bonusLists"=>[], "achievement"=>{"id"=>13, "title"=>"Level 80", "points"=>10, "description"=>"Reach level 80.", "rewardItems"=>[], "icon"=>"achievement_level_80", "criteria"=>[{"id"=>5212, "description"=>"Reach level 80", "orderIndex"=>1, "max"=>80}], "accountWide"=>false, "factionId"=>2}}]}
|
54
|
+
|
55
|
+
```
|
56
|
+
|
57
|
+
* achievements
|
58
|
+
|
59
|
+
(to be filled)
|
60
|
+
|
61
|
+
* challenge
|
62
|
+
|
63
|
+
(to be filled)
|
64
|
+
|
65
|
+
* members
|
66
|
+
|
67
|
+
(to be filled)
|
68
|
+
|
69
|
+
* __combined__
|
70
|
+
|
71
|
+
(to be filled)
|
72
|
+
|
73
|
+
|
74
|
+
You can easily combine fields.
|
75
|
+
# Support & requirements
|
76
|
+
|
77
|
+
## API authentication
|
78
|
+
In order to access World of Warcraft's API you need your API key. For most actions (guild info for example) you only need the public key. Nonetheless, both of these you can aquire at [Battle.net Developer Portal](https://dev.battle.net/).
|
79
|
+
|
80
|
+
If you do not provide public (and/or private key) you will most likely step upon `Wowapi::NoCredentialsException` error.
|
81
|
+
Make sure your Wowapi instance contains `public_key` (and/or, if necessary - `secret_key`).
|
82
|
+
|
83
|
+
If you fail to authenticate, you will most likely step upon `Wowapi::AuthException` error. This means either your credentials are invalid, or something is wrong with Blizzard services. Nonetheless, you have a problem.
|
84
|
+
|
85
|
+
## Ruby
|
86
|
+
Currently developed and tested only on 2.3.0, however _any_ Ruby >= 1.9.0 with _open-uri_ and _json_ support should be working properly.
|
87
|
+
## Regions
|
88
|
+
### Region defaults to :eu!
|
89
|
+
List of currently supported regions:
|
90
|
+
- Europe (**_:eu_**)
|
91
|
+
- United States (**_:us_**)
|
92
|
+
|
93
|
+
API region can be changed by passing proper symbol to the configuration, example:
|
94
|
+
|
95
|
+
```
|
96
|
+
api = Wowapi.new do |config|
|
97
|
+
config.region = :us
|
98
|
+
...
|
99
|
+
end
|
100
|
+
```
|
101
|
+
|
102
|
+
Keep in mind that this is completely optional, and default is **_:eu_**.
|
103
|
+
## Games
|
104
|
+
**There is no plan of supporting anything but World of Warcraft. Sorry.**
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# A simple .try method for Object,
|
2
|
+
# which mimics the Rails one (probably poorly)
|
3
|
+
|
4
|
+
module CoreExtensions
|
5
|
+
module Object
|
6
|
+
def try(method)
|
7
|
+
begin
|
8
|
+
self.send(method)
|
9
|
+
rescue NoMethodError
|
10
|
+
nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Object.include(CoreExtensions::Object) unless Object.methods.include?(:try)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Wowapi
|
2
|
+
module Modules
|
3
|
+
module Guild
|
4
|
+
# this should probably include
|
5
|
+
# a GuildClass definition which would properly
|
6
|
+
# handle blizzard apis' response.
|
7
|
+
# for now it returns just a simple JSON
|
8
|
+
# (also, written while drunk. sorry. )
|
9
|
+
def guild(realm, name, *args)
|
10
|
+
args = args.map{|n| n.to_s if n.is_a?(Symbol) }
|
11
|
+
res = get 'guild/', "#{realm}/#{name}?fields=#{args.join('%2C')}"
|
12
|
+
JSON.parse(res)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'json'
|
3
|
+
require 'pry'
|
4
|
+
require 'wowapi/core_extensions/object/try'
|
5
|
+
require 'wowapi/exceptions'
|
6
|
+
require 'wowapi/version'
|
7
|
+
require 'wowapi/modules/guild'
|
8
|
+
|
9
|
+
class Wowapi
|
10
|
+
attr_accessor :region, :public_key, :secret_key
|
11
|
+
|
12
|
+
# Wowapi::Modules is a namespace which we keep our
|
13
|
+
# particular methods for different parts of Blizzard's
|
14
|
+
# World of Warcraft Community API handling
|
15
|
+
module Modules; end
|
16
|
+
include Wowapi::Modules::Guild
|
17
|
+
|
18
|
+
class << self
|
19
|
+
# Raise exceptions on error responses from API endpoint?
|
20
|
+
attr_accessor :fail_silently
|
21
|
+
end
|
22
|
+
|
23
|
+
@fail_silently = false
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
self.region ||= :eu
|
27
|
+
yield self if block_given?
|
28
|
+
end
|
29
|
+
|
30
|
+
def get(path, params = {})
|
31
|
+
res = make_request(path, params)
|
32
|
+
if !(res.status.include?('200') or res.status.include?(200)) && ! Wowapi.fail_silently
|
33
|
+
raise Wowapi::ApiException.new, "Did not receive status 200, but #{res.try(:status).try(:first)} (#{res.class})."
|
34
|
+
end
|
35
|
+
res.read
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def make_request(path, params)
|
41
|
+
begin
|
42
|
+
raise Wowapi::NoCredentialsException unless public_key
|
43
|
+
req_uri = URI.encode("https://#{base_url}#{path}#{params}&apikey=#{self.public_key}")
|
44
|
+
open(req_uri)
|
45
|
+
rescue OpenURI::HTTPError => e
|
46
|
+
raise Wowapi::ApiException.new, "Could not make a request:\n#{e.inspect}" unless Wowapi.fail_silently
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def base_url
|
51
|
+
case self.region
|
52
|
+
when :eu
|
53
|
+
'eu.api.battle.net/wow/'
|
54
|
+
when :us
|
55
|
+
'us.api.battle.net/wow/'
|
56
|
+
else
|
57
|
+
raise Wowapi::RegionException
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/wowapi.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'wowapi/wowapi'
|
data/wowapi.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'wowapi/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'wowapi'
|
8
|
+
spec.version = Wowapi::VERSION
|
9
|
+
spec.authors = ['Jan Matusz']
|
10
|
+
spec.email = ['me@marahin.pl']
|
11
|
+
spec.description = %q{An easy-to-use gem providing access to World of Warcraft part of Blizzard Community API.}
|
12
|
+
spec.summary = %q{World of Warcraft API}
|
13
|
+
spec.homepage = 'https://git.3lab.re/marahin/wowapi'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 0'
|
21
|
+
spec.add_development_dependency 'rake', '~> 0'
|
22
|
+
spec.add_development_dependency 'pry', '~> 0'
|
23
|
+
|
24
|
+
end
|
25
|
+
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wowapi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jan Matusz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-02 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: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: An easy-to-use gem providing access to World of Warcraft part of Blizzard
|
56
|
+
Community API.
|
57
|
+
email:
|
58
|
+
- me@marahin.pl
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- Gemfile.lock
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- lib/wowapi.rb
|
69
|
+
- lib/wowapi/core_extensions/object/try.rb
|
70
|
+
- lib/wowapi/exceptions.rb
|
71
|
+
- lib/wowapi/exceptions/api_exception.rb
|
72
|
+
- lib/wowapi/exceptions/auth_exception.rb
|
73
|
+
- lib/wowapi/exceptions/no_credentials_exception.rb
|
74
|
+
- lib/wowapi/exceptions/region_exception.rb
|
75
|
+
- lib/wowapi/modules/guild.rb
|
76
|
+
- lib/wowapi/version.rb
|
77
|
+
- lib/wowapi/wowapi.rb
|
78
|
+
- wowapi.gemspec
|
79
|
+
homepage: https://git.3lab.re/marahin/wowapi
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.6.6
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: World of Warcraft API
|
103
|
+
test_files: []
|