Commit 66f6d25f authored by Francis's avatar Francis
Browse files

Initial release

parents
Pipeline #43487576 passed with stages
in 3 minutes and 45 seconds
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
.env
.idea
*.gem
.directory
\ No newline at end of file
cache:
paths:
- .env
stages:
- prepare
- codecheck
- test
environment-setup:
stage: prepare
script:
- rvm use 2.5.3 --install
- bundle install
- cat /dev/null > .env
- echo "BNET_APPLICATION_ID=$BNET_APP_ID" >> .env
- echo "BNET_APPLICATION_SECRET=$BNET_APP_SECRET" >> .env
- echo "USE_CACHE=$USE_CACHE" >> .env
rubocop:
stage: codecheck
script:
- rubocop
minitest:
stage: test
script:
- rake
\ No newline at end of file
inherit_from: .rubocop_todo.yml
Metrics/LineLength:
Max: 120
Metrics/AbcSize:
Max: 20
AllCops:
TargetRubyVersion: 2.5
Exclude:
- 'vendor/**/*'
- 'bin/**/*'
\ No newline at end of file
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-12-16 19:08:57 -0200 using RuboCop version 0.61.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
---
sudo: false
language: ruby
cache: bundler
rvm:
- 2.5.3
before_install: gem install bundler -v 1.16.6
Please view this file on the master branch, otherwise it may be outdated
**Version 0.1.0**
* Initial release
\ No newline at end of file
# frozen_string_literal: true
source 'https://rubygems.org'
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
# Specify your gem's dependencies in blizzard-api.gemspec
gemspec
PATH
remote: .
specs:
blizzard_api (0.1.0)
redis (~> 4.1, >= 4.1.0)
GEM
remote: https://rubygems.org/
specs:
ast (2.4.0)
dotenv (2.5.0)
jaro_winkler (1.5.1)
minitest (5.11.3)
parallel (1.12.1)
parser (2.5.3.0)
ast (~> 2.4.0)
powerpack (0.1.2)
rainbow (3.0.0)
rake (10.5.0)
redis (4.1.0)
rubocop (0.61.1)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.4.0)
ruby-progressbar (1.10.0)
unicode-display_width (1.4.0)
PLATFORMS
ruby
DEPENDENCIES
blizzard_api!
bundler (~> 1.16)
dotenv (~> 2.5)
minitest (~> 5.0)
rake (~> 10.0)
rubocop (~> 0.61)
BUNDLED WITH
1.17.3
The MIT License (MIT)
Copyright (c) 2018 Francis Schiavo
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:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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.
# Blizzard Api
[![pipeline status](https://gitlab.com/francisschiavo/blizzard_api/badges/master/pipeline.svg)](https://gitlab.com/francisschiavo/blizzard_api/commits/master)
[![Gem Version](https://badge.fury.io/rb/blizzard_api.svg)](https://badge.fury.io/rb/blizzard_api)
This gem allow you to interface with the new blizzard api (2018) using the OAuth2 protocol for every request.
**Important**: This gem does not support, nor will support China endpoints.
## Table of contents
1. [Installation](#1-installation)
2. [Configuration](#2-configuration)
3. [Basic usage](#1-basic-usage)
4. [Available endpoints](#4-available-endpoints)
- 4.1. [World of Warcraft endpoints](#41-world-of-warcraft-endpoints)
- 4.2. [Diablo III endpoints](#42-diablo-iii-endpoints)
- 4.3. [Starcraft II endpoints](#43-starcraft-ii-endpoints)
## 1. Installation
Add this line to your application's Gemfile:
```ruby
gem 'blizzard_api'
```
And then execute:
$ bundle
## 2. Configuration
Before you use the api you must create a developer account at https://develop.battle.net and create the client authorization keys.
Once you have a pair of client ID and SECRET you must set up an initialization code.
```ruby
Blizzard.configure do |config|
config.app_id = ENV['BNET_APPLICATION_ID']
config.app_secret = ENV['BNET_APPLICATION_SECRET']
config.region = 'us'
config.use_cache = true
config.redis_host = ENV['REDIS_HOST']
config.redis_port = ENV['REDIS_PORT']
end
```
It is highly recommended to use [redis](https://redis.io/) to cache all requests as it avoids unnecessary calls and speeds up your application.
## 3. Basic usage
You can now consume the api by instantiating a specific endpoint:
```ruby
race = BlizzardApi::Wow::Race.new :us
race_data = race.complete
```
or you can just use the game namespace wrapper as follows:
```ruby
race = BlizzardApi::Wow.race
race_data = race.complete
```
:bulb: If you use the wrapper it will always use the default region specified in the configuration file.
Most **data** endpoints will have always 3 methods available `index`, `get` and `complete`.
* `index` is used to get a list of all resources od that endpoint.
* `get` is used to get all information about a entry of the index returned data. It receives an id or slug as the first parameter, that depends on the endpoint.
* `complete` is a complete information of all items listed in index. **This may perform various calls to the blizzard api** only use if you really need all information.
## 4. Available endpoints
**Hint**: All methods support an additional optional hash parameter that allows you to override the following configurations for a single call:
* **ttl**: < int > - Cache duration (seconds) (Only works if you have redis enabled)
* **ignore_cache**: true - Ignores the cache and forces an api request (Only works if you have redis enabled)
* **locale**: < locale id > - Changes the default locale (if any)
### 4.1. World of Warcraft endpoints
* Blizzard::Wow::Achievement
- get :id
- character_achievement_index
- guild_achievement_index
* Blizzard::Wow::Auction
- get :realm
* Blizzard::Wow::Boss
- index
- get :id
* Blizzard::Wow::Challenge
- realm_index
- region_index
* Blizzard::Wow::Character
- get :realm, :character, :fields
- get_keystone_profile :realm, :character, :user_token, :season
- get_user_characters :user_token
* Blizzard::Wow::Guild
- get :relam, :name, :fields
- rewards
- perks
* Blizzard::Wow::Item
- get :id
- item_set :setId
* Blizzard::Wow::Mount
- index
* Blizzard::Wow::Pet
- index
- ability :id
- species :id
- stats :level, :breed_id, :quality_id
- types
* Blizzard::Wow::PvP
- get :bracket
* Blizzard::Wow::Quest
- get :id
* Blizzard::Wow::Recipe
- get :id
* Blizzard::Wow::Spell
- get :id
* Blizzard::Wow::Zone
- index
- get :id
* Blizzard::Wow::ConnectedRealm
- index
- get :id
- complete
* Blizzard::Wow::MythicKeystonesAffix
- index
- get :id
- complete
* Blizzard::Wow::PlayableClass
- index
- get :id
- complete
* Blizzard::Wow::PlayableSpecialization
- index
- get :id
- complete
* Blizzard::Wow::PowerType
- index
- get :id
- complete
* Blizzard::Wow::Race
- index
- get :id
- complete
* Blizzard::Wow::Realm
- index
- get :id
- complete
* Blizzard::Wow::Region
- index
- get :id
- complete
### 4.2. Diablo III endpoints
* BlizzardApi::Diablo::Act
- index
- get :id
* BlizzardApi::Diablo::Artisan
- get :artisan_slug
- recipe :artisan_slug, :recipe_slug
* BlizzardApi::Diablo::Follower
- get :slug
* BlizzardApi::Diablo::Character
- get :class_slug
- skill :class_slug, :skill_slug
* BlizzardApi::Diablo::ItemType
- index
- get :item_type_slug
* BlizzardApi::Diablo::Item
- get :item_slug, :item_id
* BlizzardApi::Diablo::Profile
- index :battletag, :oauth_token
- hero :battletag, :oauth_token, :hero_id
- hero_items :battletag, :oauth_token, :hero_id
- hero_follower_items :battletag, :oauth_token, :hero_id
### 4.3. Starcraft II endpoints
Every endpoint requiring a *region_id* parameter will accepts either the integer representation of the region described in the api docs or a symbol: `:US`, `:EU`, `:KO` or `:TW`
* BlizzardApi::Starcraft::League
- get :season_id, :queue_id, :team_type, :league_id
* BlizzardApi::Starcraft::Profile
- static :region_id
- metadata :region_id, :realm_id, :profile_id
- profile :region_id, :realm_id, :profile_id
- ladder_summary :region_id, :realm_id, :profile_id
- ladder :region_id, :realm_id, :profile_id, :ladder_id
* BlizzardApi::Starcraft::Ladder
- grandmaster :region_id, :options
- season :region_id
* BlizzardApi::Starcraft::Account
- player :account_id
## Contributing
Bug reports and pull requests are welcome on Gitlab at https://gitlab.com/francisschiavo/blizzard_api/issues
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
# frozen_string_literal: true
require 'bundler/gem_tasks'
require 'rake/testtask'
Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/**/*_test.rb']
end
task default: :test
#!/usr/bin/env ruby
require 'bundler/setup'
require 'blizzard/api'
# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start
require 'irb'
IRB.start(__FILE__)
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx
bundle install
# Do any other automated setup that you need to do here
# frozen_string_literal: true
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'blizzard_api/version'
Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.5'
spec.name = 'blizzard_api'
spec.version = BlizzardApi::VERSION
spec.authors = ['Francis Schiavo']
spec.email = ['francis.schiavo@francisschiavo.com']
spec.summary = 'Unofficial Ruby client for Blizzard Entertainment API'
spec.description = 'This is a simple interface to obtain data from Blizzard API'
spec.homepage = 'https://gitlab.com/francisschiavo/blizzard_api'
spec.license = 'MIT'
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow pushing to any host.
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless spec.respond_to?(:metadata)
spec.metadata['homepage_uri'] = spec.homepage
spec.metadata['source_code_uri'] = 'https://gitlab.com/francisschiavo/blizzard_api'
spec.metadata['changelog_uri'] = 'https://gitlab.com/francisschiavo/blizzard_api/blob/master/CHANGELOG.md'
# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']
spec.add_runtime_dependency 'redis', '~> 4.1', '>= 4.1.0'
spec.add_development_dependency 'bundler', '~> 1.16'
spec.add_development_dependency 'dotenv', '~> 2.5'
spec.add_development_dependency 'minitest', '~> 5.0'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rubocop', '~> 0.61'
end
# frozen_string_literal: true
require_relative 'blizzard_api/configuration'
require_relative 'blizzard_api/request'
require_relative 'blizzard_api/exception'
require_relative 'blizzard_api/version'
require_relative 'blizzard_api/wow'
require_relative 'blizzard_api/diablo'
require_relative 'blizzard_api/starcraft'
# Blizzard namespace
module BlizzardApi
extend Configuration
end
# frozen_string_literal: true
module BlizzardApi
# Global configurations
module Configuration
##
# @!attribute app_id
# Application ID.
# @see https://develop.battle.net/access/clients
# @return [String] Application ID
attr_accessor :app_id
##
# @!attribute app_secret
# Application secret.
# @see https://develop.battle.net/access/clients
# @return [String] Application secret
attr_accessor :app_secret
##
# @!attribute region
# Default region.
# @return [String] Default region
attr_accessor :region
##
# @!attribute use_cache
# If true requests will be cached using a Redis server.
# @see https://redis.io/
# @return [Boolean] Application ID
attr_accessor :use_cache
##
# @!attribute redis_host
# Redis host.
# @see https://redis.io/
# @return [String] Redis host
attr_accessor :redis_host
##
# @!attribute redis_port
# Redis port.
# @see https://redis.io/
# @return [Integer] Redis port
attr_accessor :redis_port
##
# @!attribute format
# Response format:
# * *:raw* plain text (String)
# * *:json* for native ruby json (Array).
# * Any other value *OpenStruct* will be used.
# @return [Symbol] Response format.
attr_accessor :format
##
# @!attribute access_token
# Access token. Optional. If you don't provide one it will be generate using your client credentials.
# @return [String] Access token.
attr_accessor :access_token
##
# This method return the singleton instance of the configuration module. Use this to initialize the default values
# and options.
#
# @yield self
#
# @example
# Blizzard.configure do |config|
# config.app_id = ENV['BNET_APPLICATION_ID']
# config.app_secret = ENV['BNET_APPLICATION_SECRET']
# config.region = 'us'
# config.use_cache = true
# config.redis_host = ENV['REDIS_HOST']
# config.redis_port = ENV['REDIS_PORT']
# config.format = :json
# end
def configure
yield self
end
end
end
# frozen_string_literal: true
module BlizzardApi
# Diablo III related classes
module Diablo
require_relative 'diablo/request'
require_relative 'diablo/game_data/generic_data_endpoint'
# Diablo data api
require_relative 'diablo/game_data/season'
require_relative 'diablo/game_data/era'
##
# @return {Season}
def season
BlizzardApi::Diablo::Season.new
end
##
# @return {Era}
def era
BlizzardApi::Diablo::Era.new
end
# Diablo community api
require_relative 'diablo/community/act'
require_relative 'diablo/community/artisan'
require_relative 'diablo/community/follower'
require_relative 'diablo/community/character'
require_relative 'diablo/community/item_type'
require_relative 'diablo/community/item'
require_relative 'diablo/community/profile'
##
# @return {Act}
def act
BlizzardApi::Diablo::Act.new
end
##
# @return {Artisan}
def artisan
BlizzardApi::Diablo::Artisan.new
end
##
# @return {Follower}
def follower
BlizzardApi::Diablo::Follower.new
end
##
# @return {Character}
def character
BlizzardApi::Diablo::Character.new
end
##
# @return {ItemType}
def item_type
BlizzardApi::Diablo::ItemType.new
end
##
# @return {Type}
def item
BlizzardApi::Diablo::Item.new
end