diablo3-simple 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/diablo3-simple.rb +33 -0
  2. metadata +18 -2
@@ -2,8 +2,32 @@
2
2
  require 'net/http'
3
3
  require 'json'
4
4
  require 'D3/hero'
5
+ require 'ostruct'
5
6
 
7
+ # The main D3 class
6
8
  class Diablo3
9
+ # Diablo 3 simple class to retrieve info from Blizzard official D3 API
10
+ #
11
+ # Usage:
12
+ # require 'diablo3-simple'
13
+ # d3 = Diablo3.new(<server>, <battletag> )
14
+ # server should be 'us' or 'eu' (it may work with other regions if they use like <server>.battle.net pattern)
15
+ # battletag is the user battletag
16
+ #
17
+ # d3 = Diablo3.new('us', 'sikora#1521' )
18
+ # heroes = d3.list_heroes #returns a hash whose key is the hero id and value is the respective Hero class
19
+ # heroes[1234].name #return the hero's name whose id is 1234
20
+ #
21
+ # You can fetch the global progression information using:
22
+ # prog = d3.global_progression
23
+ # then you'll have access to
24
+ # prog.normal
25
+ # prog.nightmare...inferno
26
+ #
27
+ # refer to https://github.com/Blizzard/d3-api-docs for more information about the fetched data
28
+
29
+ attr_accessor :global_progression
30
+
7
31
  def initialize(server='us', btag)
8
32
 
9
33
  @server = server
@@ -14,6 +38,15 @@ class Diablo3
14
38
  ret = Net::HTTP.get(URI.parse(api_url))
15
39
  @data = JSON(ret)
16
40
 
41
+
42
+ if @data.empty?
43
+ raise "D3_cannot_retrieve_info"
44
+ elsif @data['code'].eql?('OOPS')
45
+ raise "D3_possible_invalid_battletag"
46
+ end
47
+
48
+ @global_progression = OpenStruct.new(@data['progression'])
49
+
17
50
  end
18
51
 
19
52
  def list_heroes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diablo3-simple
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,23 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
  date: 2012-08-12 00:00:00.000000000 Z
13
- dependencies: []
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.6.6
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.6.6
14
30
  description: The main goal is to provide a simple class that fetches Diablo3 information
15
31
  using Blizzard's official API.
16
32
  email: sikora@gmail.com