Youness-e / rbattlenet

A wrapper gem for the Blizzard's Battle.net API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RBattlenet

A Ruby gem that wraps Blizzard's Battle.net Community Platform API. Currently, RBattlenet only covers the Hearthstone, World of Warcraft, Diablo 3 and StarCraft 2 APIs

Installation

Add this line to your application's Gemfile:

gem 'rbattlenet', github: 'youness-e/rbattlenet'

And then execute:

$ bundle

Usage

Step 1. Setting your Battle.net API Key

Your private Battle.net API key must be present in order to get a valid Battle.net API response. Before any requests are made, your API key must be set like so:

client_id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
client_secret = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"

RBattlenet.authenticate(client_id: client_id, client_secret: client_secret)

Step 2. Setting your region and locale (Optional)

Your region and locale defaults to US and en_US respectively. However, these can be changed like so:

RBattlenet.set_region(region: "us", locale: "en_US")

Step 3. Call the API methods to request data

character = RBattlenet::Wow::DataResources.find_character_classes

{"classes"=>
  [{"id"=>1, "mask"=>1, "powerType"=>"rage", "name"=>"Warrior"},
   {"id"=>2, "mask"=>2, "powerType"=>"mana", "name"=>"Paladin"},
   {"id"=>3, "mask"=>4, "powerType"=>"focus", "name"=>"Hunter"},
   {"id"=>4, "mask"=>8, "powerType"=>"energy", "name"=>"Rogue"},
   {"id"=>5, "mask"=>16, "powerType"=>"mana", "name"=>"Priest"},
   {"id"=>6, "mask"=>32, "powerType"=>"runic-power", "name"=>"Death Knight"},
   {"id"=>7, "mask"=>64, "powerType"=>"mana", "name"=>"Shaman"},
   {"id"=>8, "mask"=>128, "powerType"=>"mana", "name"=>"Mage"},
   {"id"=>9, "mask"=>256, "powerType"=>"mana", "name"=>"Warlock"},
   {"id"=>10, "mask"=>512, "powerType"=>"energy", "name"=>"Monk"},
   {"id"=>11, "mask"=>1024, "powerType"=>"mana", "name"=>"Druid"},
   {"id"=>12, "mask"=>2048, "powerType"=>"fury", "name"=>"Demon Hunter"}]}

Testing

CLIENT_ID=<your_id> CLIENT_SECRET=<your_secret> bundle exec rspec

TODOs

  • Refactor specs to use Mocks/Stubs instead of making real API calls
  • Add specs that make real API calls that only run when a flag if provided
  • Add a CHANGELOG

Documentation


Hearthstone

https://develop.battle.net/documentation/api-reference/hearthstone-game-data-api

Cards

args = {
  set: 'rise-of-shadows',
  class: 'mage',
  mana_cost: 10,
  attack: 4,
  health: 10,
  collectible: 1,        
  rarity: 'legendary',
  type: 'minion',
  minion_type: 'dragon',
  keyword: 'battlecry',
  text_filter: 'kalecgos',
  page: 1,
  page_size: 5,
  sort: 'name',
  order: 'desc'
}
cards = RBattlenet::Hearthstone::Card.find_cards(args)
card  = RBattlenet::Hearthstone::Card.find_card(id_or_slug: '52119-arch-villain-rafaam')

Decks

deck = RBattlenet::Hearthstone::Deck.find_deck(deckcode: 'AAECAQcG+wyd8AKS+AKggAOblAPanQMMS6IE/web8wLR9QKD+wKe+wKz/AL1gAOXlAOalAOSnwMA')

Metadata

metadata = RBattlenet::Hearthstone::Metadata.all_metadata()
# valid types:  sets, setGroups, types, rarities, classes, minionTypes, and keywords.
metadata = RBattlenet::Hearthstone::Metadata.find_metadata(type: 'sets')

World of Warcraft

Achievement

achievement = RBattlenet::Wow::Achievement.find(id: 2144)

Auction

RBattlenet::Wow::Auction.find(realm: "saurfang")

Battle Pet

Abilities

RBattlenet::Wow::Battlepet.find_abilities(id: 640)

Species

RBattlenet::Wow::Battlepet.find_species(species_id: 258)

Stats

RBattlenet::Wow::Battlepet.find_stats(species_id: 258,
  level: 25,
  breed_id: 5,
  quality_id: 4)

Challenge

Realm Leaderboard

RBattlenet::Wow::Challenge.find_realm(realm: "saurfang")

Region Leaderboard

RBattlenet::Wow::Challenge.find_region

Character

Profile

RBattlenet::Wow::Character.find(name: "milhause", realm: "saurfang")

Additional Fields

To see all possible fields visit: https://dev.battle.net/

RBattlenet::Wow::Character.find(name: "milhause",
  realm: "saurfang",
  fields: ["pet slots", "guild"])

Data Resources

Battlegroups

RBattlenet::Wow::DataResources.find_battlegroups

Character Achievements

RBattlenet::Wow::DataResources.find_character_achievements

Character Classes

RBattlenet::Wow::DataResources.find_character_classes

Character Races

RBattlenet::Wow::DataResources.find_character_races

Guild Achievements

RBattlenet::Wow::DataResources.find_guild_achievements

Guild Perks

RBattlenet::Wow::DataResources.find_guild_perks

Guild Rewards

RBattlenet::Wow::DataResources.find_guild_rewards

Item Classes

RBattlenet::Wow::DataResources.find_item_classes

Pet Types

RBattlenet::Wow::DataResources.find_pet_types

Talents

RBattlenet::Wow::DataResources.find_talents

Item

Item

RBattlenet::Wow::Item.find(id: 18803);

Item Set

RBattlenet::Wow::Item.find_set(id: 1060)

Guild

Profile

RBattlenet::Wow::Guild.find(name: "razors edge", realm:"saurfang")

Additional data

RBattlenet::Wow::Guild.find(name: "razors edge",
  realm: "saurfang",
  fields: ["members", "news"])

PVP

Leaderboards

RBattlenet::Wow::Pvp.find_bracket(bracket: "2v2")

Quest

RBattlenet::Wow::Quest.find(id: 13146)

Realm Status

RBattlenet::Wow::Realm.find

Recipe

RBattlenet::Wow::Recipe.find(id: 33994)

Spell

RBattlenet::Wow::Spell.find(id: 8056)

Starcraft 2

Profile

Not working: RBattlenet::Sc2::Profile.find(id: 1234567, region: 1, name: 'name')

Ladders

RBattlenet::Sc2::Profile.find_ladders(id: 1234567, region: 1, name: 'name')

Match history

RBattlenet::Sc2::Profile.find_match_history(id: 2137104, region: 1, realm: 1)

Ladder

RBattlenet::Sc2::Ladder.find(id: 2200)

Data Resources

Achievements

RBattlenet::Sc2::DataResources.find_achievements

Rewards

RBattlenet::Sc2::DataResources.find_rewards

Diablo 3

Data Resources

Artisan

RBattlenet::D3::DataResources.find_artisan(artisan: 'blacksmith')

Follower

RBattlenet::D3::DataResources.find_follower(follower: 'templar')

Item

data = "CrABCL-oudQGEgcIBBWZWjYNHWU61OAdyg3pEx07J28kHevi5AUd8dNq1TCLAjj_AkAAUBJYBGD_AmorCgwIABDX3bKmiICA4DESGwi5u5abChIHCAQVIpaumDCPAjgAQAFYBJABAGorCgwIABCl3rKmiICA4DESGwiR9M-gAhIHCAQVIpaumDCLAjgAQAFYBJABAIABRqUBOydvJK0Bj5DKULUBAXBvArgB9aCdsg7AAQEYsuqy0wFQAFgC"

RBattlenet::D3::DataResources.find_item(data: data)

Profile

Career

RBattlenet::D3::Profile.find_career(battletag: "username")

Hero

RBattlenet::D3::.find_hero(battletag: "username", id: 1234567)

Contributing

  1. Fork it ( https://github.com/[my-github-username]/rbattlenet/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

About

A wrapper gem for the Blizzard's Battle.net API

License:MIT License


Languages

Language:Ruby 100.0%