GithubHelp home page GithubHelp logo

binarymuse / battlenet Goto Github PK

View Code? Open in Web Editor NEW
57.0 7.0 15.0 506 KB

Easily consume Blizzard's Community Platform API.

Home Page: http://us.battle.net/wow/en/forum/topic/2369881371#1

License: MIT License

Ruby 100.00%

battlenet's Introduction

    __ )          |    |    |                     |
    __ \    _` |  __|  __|  |   _ \  __ \    _ \  __|
    |   |  (   |  |    |    |   __/  |   |   __/  |
   ____/  \__,_| \__| \__| _| \___| _|  _| \___| \__|

A Ruby library for the Battle.net Community Platform API

Build Status

Battlenet is a Ruby library that exposes Blizzard's Community Platform API.

Installing

Battlenet is available as a Ruby gem. Install it via

[sudo] gem install battlenet

Use

Simply create an instance of Battlenet, passing in an optional region as a symbol (defaulting to US), and then optionally a public and private key (for app authorization).

Default options:

api = Battlenet.new

Specifying a region:

api = Battlenet.new :eu

Specifying a public and private key:

api = Battlenet.new :us, 'public', 'private'

Battlenet is backed by the excellent HTTParty gem, which means you can make get requests very simply.

api.get '/item/12784'

Battlenet also provides modules for each section of the API, providing easy access to the resources.

api.item '12784'
api.character 'Nazjatar', 'Cyaga', :fields => "stats,talents,quests"

Configuring

Failing Silently

By default, if Battlenet receives a 4xx or 5xx response from the Battle.net API, it will throw a Battlent::ApiException. You can turn this behavior off via the fail_silently attribute:

Battlenet.fail_silently = true

The exception will have its code attribute set to the HTTP status code returned from the API; if the response included a JSON response with the reason field set, the exception will have a reason attribute set to this string. You can also access the raw response via the response attribute.

Localization

The Battle.net API supports localization via a query string parameter. Battlenet can transparently handle setting this parameter for you on every request. Just set the locale attribute:

Battlenet.locale = "en_GB"

Please note that each region only supports certain locales.

Battle.net API Documentation

The documentation for the Battle.net API can be found at http://blizzard.github.com/api-wow-docs/.

What's Missing

The following features are planned but not yet supported:

  • Caching support via Memcached, Redis, etc.
  • If-Last-Modified header support

Contributing

If you would like to contribute to the project, please feel free to do so. Just fork the project, commit your changes (preferably to a new branch), and then send me a pull request via GitHub. Be sure to add tests for your feature or fix.

Please do not change the contents of the VERSION file, or if you do, do so in a separate commit so that I can cherry-pick around it.

Setting Up the Development Environment

The development environment is managed with Bundler.

To install just the gems you need to hack on Battlenet and run the specs, run

bundle install --without documentation

To install all development gems, including the ones used to generate documentation, run

bundle install

To run the specs, run

bundle exec rake

Writing an Integration Test

High-level integration testing against the Community Platform API is handled via VCR. After the first time running a spec that hits the API, VCR saves the HTTP response in a fixture file and uses this file to run against in the future.

Here's an example (the character integration specs):

it "fetches character data" do
  VCR.use_cassette('character_mortawa') do
    character = api.character 'nazjatar', 'mortawa'
    character['level'].should == 85
  end
end

it "fetches additional character data" do
  VCR.use_cassette('character_mortawa_titles') do
    character = api.character 'nazjatar', 'mortawa', :fields => 'titles'
    character['titles'].find { |t| t['selected'] == true }['name'].should == "Twilight Vanquisher %s"
  end
end

it "fetches characters with non-ASCII characters in their name" do
  VCR.use_cassette('character_nonstandard_name') do
    character = api.character 'nazjatar', 'Hikô'
    character['level'].should == 85
  end
end

You should always wrap tests that hit the actual API in the VCR.use_cassette block, and the resulting fixture file should be checked in with your test.

Building the Documentation

If you have the necessary gems installed (defined in the documentation group in the Gemfile), you can easily generate the documentation via

yard

The generated documentation can be found in doc/; open doc/index.html to view it.

License

Battlenet is released under the MIT license.

Copyright (c) 2011 Brandon Tilley

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.

battlenet's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

battlenet's Issues

fail_silently defaults to nil

The fail_silently accessor is not set to false by default and no exceptions are raised unless it is explicitly set.

Commenting out line 116 in spec/unit/battlenet_spec.rb I would except would not cause the test to fail.

Update the VCR cassetes

Update the VCR cassetes so they can assure the lib still works with the latest API modifications.

Reimplement APIError Exception class

Glad to see this gem is getting some love again. The 1.0.0 release removed the APIError exception and now just has a string. This makes it more difficult to see why an exception was thrown. If possible I would like to request this be revered back to pre 1.0.0.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.