Class: Diablo3

Inherits:
Object
  • Object
show all
Defined in:
lib/diablo3-simple.rb

Overview

The main D3 class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server = 'us', btag) ⇒ Diablo3

Returns a new instance of Diablo3.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/diablo3-simple.rb', line 31

def initialize(server='us', btag)

  @server = server
  @btag = btag

  @btag.gsub!('#','-')
  api_url = URI.escape("http://#{@server}.battle.net/api/d3/profile/#{@btag}/")
  ret = Net::HTTP.get(URI.parse(api_url))
  @data = JSON(ret)


  if @data.empty?
    raise "D3_cannot_retrieve_info"
  elsif @data['code'].eql?('OOPS')
    raise "D3_possible_invalid_battletag"
  end

  @global_progression = OpenStruct.new(@data['progression'])

end

Instance Attribute Details

#global_progressionObject

Diablo 3 simple class to retrieve info from Blizzard official D3 API

Usage:

require 'diablo3-simple'
d3 = Diablo3.new(<server>, <battletag> )  
server should be 'us' or 'eu' (it may work with other regions if they use like <server>.battle.net pattern)
battletag is the user battletag

d3 = Diablo3.new('us', 'sikora#1521' )
heroes = d3.list_heroes  #returns a hash whose key is the hero id and value is the respective Hero class
heroes[1234].name #return the hero's name whose id is 1234

You can fetch the global progression information using:
prog = d3.global_progression
then you'll have access to
prog.normal 
prog.nightmare...inferno

refer to https://github.com/Blizzard/d3-api-docs for more information about the fetched data


29
30
31
# File 'lib/diablo3-simple.rb', line 29

def global_progression
  @global_progression
end

Instance Method Details

#list_heroesObject



52
53
54
55
56
57
58
59
# File 'lib/diablo3-simple.rb', line 52

def list_heroes
  heroes = Hash.new
  @data['heroes'].map do |h|
    heroes[h['id']] = Hero.new(@server, @btag, h['id'], h)
  end

  heroes
end