bn 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +22 -0
- data/README.md +202 -0
- data/Rakefile +14 -0
- data/VERSION +1 -0
- data/bn.gemspec +23 -0
- data/lib/bn.rb +9 -0
- data/lib/bn/api.rb +19 -0
- data/lib/bn/api/base.rb +78 -0
- data/lib/bn/api/d3.rb +44 -0
- data/lib/bn/api/sc2.rb +74 -0
- data/lib/bn/api/wow.rb +10 -0
- data/lib/bn/entity.rb +19 -0
- data/lib/bn/entity/base.rb +16 -0
- data/lib/bn/entity/d3/hero.rb +164 -0
- data/lib/bn/entity/d3/profile.rb +185 -0
- data/lib/bn/error/api/base.rb +11 -0
- data/lib/bn/error/api/invalid_key.rb +14 -0
- data/lib/bn/error/api/invalid_locale.rb +16 -0
- data/lib/bn/error/api/invalid_region.rb +14 -0
- data/lib/bn/error/base.rb +10 -0
- data/lib/bn/error/middleware/base.rb +11 -0
- data/lib/bn/error/middleware/invalid_api_request.rb +38 -0
- data/lib/bn/error/middleware/invalid_http_response.rb +26 -0
- data/lib/bn/helpers/has_attributes.rb +45 -0
- data/lib/bn/middleware.rb +13 -0
- data/lib/bn/middleware/api_error.rb +27 -0
- data/lib/bn/middleware/base.rb +21 -0
- data/lib/bn/middleware/d3.rb +9 -0
- data/lib/bn/middleware/d3/profile.rb +39 -0
- data/lib/bn/middleware/http_response.rb +24 -0
- data/lib/bn/middleware/key_converter.rb +28 -0
- metadata +117 -0
data/lib/bn/api/wow.rb
ADDED
data/lib/bn/entity.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module BN
|
2
|
+
# The Entity namespace.
|
3
|
+
module Entity
|
4
|
+
# The valid regions for the API.
|
5
|
+
# Contains name, host, and valid locales for each region.
|
6
|
+
REGIONS = {
|
7
|
+
us: { name: "US", uri: "https://us.api.battle.net", locales: %w(en_US es_MX pt_BR) },
|
8
|
+
eu: { name: "Europe", uri: "https://us.api.battle.net", locales: %w(en_GB es_ES fr_FR ru_RU de_DE pt_PT it_IT) },
|
9
|
+
kr: { name: "Korea", uri: "https://kr.api.battle.net", locales: %w(ko_KR) },
|
10
|
+
tw: { name: "Taiwan", uri: "https://tw.api.battle.net", locales: %w(zh_TW) },
|
11
|
+
cn: { name: "China", uri: "https://api.battlenet.com.cn", locales: %w(zh_CN) },
|
12
|
+
sea: { name: "South East Asia", uri: "https://sea.api.battle.net", locales: %w(en_US) }
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
require "bn/api/d3"
|
18
|
+
require "bn/api/sc2"
|
19
|
+
require "bn/api/wow"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "bn/helpers/has_attributes"
|
2
|
+
|
3
|
+
module BN
|
4
|
+
module Entity
|
5
|
+
# The base class for game entities.
|
6
|
+
class Base
|
7
|
+
include Helpers::HasAttributes
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def convert_time(value)
|
12
|
+
value.is_a?(Time) ? value : Time.at(value.to_i)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
require "bn/entity/base"
|
2
|
+
|
3
|
+
module BN
|
4
|
+
module Entity
|
5
|
+
module D3
|
6
|
+
# A hero within Diablo 3.
|
7
|
+
class Hero < Base
|
8
|
+
MAX_LEVEL = 70
|
9
|
+
|
10
|
+
def initialize(attributes={})
|
11
|
+
super
|
12
|
+
|
13
|
+
@level ||= 1
|
14
|
+
@paragon_level ||= 0
|
15
|
+
@hardcore ||= false
|
16
|
+
@seasonal ||= false
|
17
|
+
@dead ||= false
|
18
|
+
end
|
19
|
+
|
20
|
+
# @method id
|
21
|
+
# Get the ID.
|
22
|
+
#
|
23
|
+
# @return [Integer]
|
24
|
+
|
25
|
+
# @method id=
|
26
|
+
# Set the ID.
|
27
|
+
#
|
28
|
+
# @param [#to_i] value
|
29
|
+
# @return [Integer]
|
30
|
+
attribute(:id) { |value| value.to_i }
|
31
|
+
|
32
|
+
# @method name
|
33
|
+
# Get the name.
|
34
|
+
#
|
35
|
+
# @return [String]
|
36
|
+
|
37
|
+
# @method name=
|
38
|
+
# Set the name.
|
39
|
+
#
|
40
|
+
# @param [#to_s] value
|
41
|
+
# @return [String]
|
42
|
+
attribute(:name) { |value| value.to_s.strip }
|
43
|
+
|
44
|
+
# @method hero_class
|
45
|
+
# Get the hero class.
|
46
|
+
#
|
47
|
+
# @return [Symbol]
|
48
|
+
|
49
|
+
# @method hero_class=
|
50
|
+
# Set the hero class.
|
51
|
+
#
|
52
|
+
# @param [#to_sym] value
|
53
|
+
# @return [Symbol]
|
54
|
+
attribute(:hero_class) { |value| value.to_sym }
|
55
|
+
|
56
|
+
# @method gender
|
57
|
+
# Get the gender.
|
58
|
+
#
|
59
|
+
# @return [Symbol]
|
60
|
+
|
61
|
+
# @method gender=
|
62
|
+
# Set the gender.
|
63
|
+
#
|
64
|
+
# @param [#to_sym] value
|
65
|
+
# @return [Symbol]
|
66
|
+
attribute(:gender) { |value| value.to_sym }
|
67
|
+
|
68
|
+
# @method level
|
69
|
+
# Get the level.
|
70
|
+
#
|
71
|
+
# @return [Integer]
|
72
|
+
|
73
|
+
# @method level=
|
74
|
+
# Set the level.
|
75
|
+
#
|
76
|
+
# @param [#to_i] value
|
77
|
+
# @return [Integer]
|
78
|
+
attribute(:level) { |value| validate_level(value) }
|
79
|
+
|
80
|
+
# @method paragon_level
|
81
|
+
# Get the paragon level.
|
82
|
+
#
|
83
|
+
# @return [Integer]
|
84
|
+
|
85
|
+
# @method paragon_level=
|
86
|
+
# Set the paragon level.
|
87
|
+
#
|
88
|
+
# @param [#to_i] value
|
89
|
+
# @return [Integer]
|
90
|
+
attribute(:paragon_level) { |value| validate_level(value, true) }
|
91
|
+
|
92
|
+
# @method kills
|
93
|
+
# Get the number of kills per enemy type.
|
94
|
+
#
|
95
|
+
# @return [Hash]
|
96
|
+
|
97
|
+
# @method kills=
|
98
|
+
# Set the number of kills per enemy type.
|
99
|
+
#
|
100
|
+
# @param [#to_h] value
|
101
|
+
# @return [Hash]
|
102
|
+
attribute(:kills) { |value| value.to_h }
|
103
|
+
|
104
|
+
# @method hardcore
|
105
|
+
# Get whether this hero is hardcore.
|
106
|
+
#
|
107
|
+
# @return [Boolean]
|
108
|
+
|
109
|
+
# @method hardcore=
|
110
|
+
# Set whether this hero is hardcore.
|
111
|
+
#
|
112
|
+
# @param [Boolean] value
|
113
|
+
# @return [Boolean]
|
114
|
+
attribute(:hardcore) { |value| !!value }
|
115
|
+
|
116
|
+
# @method seasonal
|
117
|
+
# Get whether this hero is seasonal.
|
118
|
+
#
|
119
|
+
# @return [Boolean]
|
120
|
+
|
121
|
+
# @method seasonal=
|
122
|
+
# Set whether this hero is seasonal.
|
123
|
+
#
|
124
|
+
# @param [Boolean] value
|
125
|
+
# @return [Boolean]
|
126
|
+
attribute(:seasonal) { |value| !!value }
|
127
|
+
|
128
|
+
# @method last_updated
|
129
|
+
# Get the last updated time.
|
130
|
+
#
|
131
|
+
# @return [Time]
|
132
|
+
|
133
|
+
# @method last_updated=
|
134
|
+
# Set the last updated time.
|
135
|
+
#
|
136
|
+
# @param [Time, #to_i] value
|
137
|
+
# @return [Time]
|
138
|
+
attribute(:last_updated) { |value| convert_time(value) }
|
139
|
+
|
140
|
+
# @method dead
|
141
|
+
# Get whether this hero is dead.
|
142
|
+
#
|
143
|
+
# @return [Boolean]
|
144
|
+
|
145
|
+
# @method dead=
|
146
|
+
# Set whether this hero is dead.
|
147
|
+
#
|
148
|
+
# @param [Boolean] value
|
149
|
+
# @return [Boolean]
|
150
|
+
attribute(:dead) { |value| !!value }
|
151
|
+
|
152
|
+
protected
|
153
|
+
|
154
|
+
def validate_level(value, paragon=false)
|
155
|
+
value = value.to_i
|
156
|
+
value = 0 if value < MAX_LEVEL
|
157
|
+
value = MAX_LEVEL if !paragon && value > MAX_LEVEL
|
158
|
+
|
159
|
+
value
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
@@ -0,0 +1,185 @@
|
|
1
|
+
require "bn/entity/base"
|
2
|
+
require "bn/entity/d3/hero"
|
3
|
+
|
4
|
+
module BN
|
5
|
+
module Entity
|
6
|
+
module D3
|
7
|
+
# A profile within Diablo 3.
|
8
|
+
class Profile < Base
|
9
|
+
# @method battle_tag
|
10
|
+
# Get the battle tag.
|
11
|
+
#
|
12
|
+
# @return [String]
|
13
|
+
|
14
|
+
# @method battle_tag=
|
15
|
+
# Set the battle tag.
|
16
|
+
#
|
17
|
+
# @param [#to_s] value
|
18
|
+
# @return [String]
|
19
|
+
attribute(:battle_tag) { |value| value.to_s.strip }
|
20
|
+
|
21
|
+
# @method paragon_level
|
22
|
+
# Get the paragon level.
|
23
|
+
#
|
24
|
+
# @return [Integer]
|
25
|
+
|
26
|
+
# @method paragon_level=
|
27
|
+
# Set the paragon level.
|
28
|
+
#
|
29
|
+
# @param [#to_i] value
|
30
|
+
# @return [Integer]
|
31
|
+
attribute(:paragon_level) { |value| value.to_i }
|
32
|
+
|
33
|
+
# @method paragon_level_hardcore
|
34
|
+
# Get the paragon hardcore level.
|
35
|
+
#
|
36
|
+
# @return [Integer]
|
37
|
+
|
38
|
+
# @method paragon_level_hardcore=
|
39
|
+
# Set the paragon hardcore level.
|
40
|
+
#
|
41
|
+
# @param [#to_i] value
|
42
|
+
# @return [Integer]
|
43
|
+
attribute(:paragon_level_hardcore) { |value| value.to_i }
|
44
|
+
|
45
|
+
# @method paragon_level_season
|
46
|
+
# Get the paragon season level.
|
47
|
+
#
|
48
|
+
# @return [Integer]
|
49
|
+
|
50
|
+
# @method paragon_level_season=
|
51
|
+
# Set the paragon season level.
|
52
|
+
#
|
53
|
+
# @param [#to_i] value
|
54
|
+
# @return [Integer]
|
55
|
+
attribute(:paragon_level_season) { |value| value.to_i }
|
56
|
+
|
57
|
+
# @method paragon_level_season_hardcore
|
58
|
+
# Get the paragon season hardcore level.
|
59
|
+
#
|
60
|
+
# @return [Integer]
|
61
|
+
|
62
|
+
# @method paragon_level_season_hardcore=
|
63
|
+
# Set the paragon season hardcore level.
|
64
|
+
#
|
65
|
+
# @param [#to_i] value
|
66
|
+
# @return [Integer]
|
67
|
+
attribute(:paragon_level_season_hardcore) { |value| value.to_i }
|
68
|
+
|
69
|
+
# @method guild_name
|
70
|
+
# Get the guild name.
|
71
|
+
#
|
72
|
+
# @return [String]
|
73
|
+
|
74
|
+
# @method guild_name=
|
75
|
+
# Set the guild name.
|
76
|
+
#
|
77
|
+
# @param [#to_s] value
|
78
|
+
# @return [String]
|
79
|
+
attribute(:guild_name) { |value| value.to_s }
|
80
|
+
|
81
|
+
# @method heroes
|
82
|
+
# Get the heroes.
|
83
|
+
#
|
84
|
+
# @return [<Hero>]
|
85
|
+
|
86
|
+
# @method heroes=
|
87
|
+
# Set the heroes.
|
88
|
+
#
|
89
|
+
# @param [#to_a] value
|
90
|
+
# @return [<Hero>]
|
91
|
+
attribute(:heroes) { |value| value.to_a.collect { |hero| convert_hero(hero) } }
|
92
|
+
|
93
|
+
# @method last_hero_played
|
94
|
+
# Get the last hero played.
|
95
|
+
#
|
96
|
+
# @return [Hero]
|
97
|
+
|
98
|
+
# @method heroes=
|
99
|
+
# Set the last hero played.
|
100
|
+
#
|
101
|
+
# @param [Hero, #to_h] value
|
102
|
+
# @return [Hero]
|
103
|
+
attribute(:last_hero_played) { |value| convert_hero(value) }
|
104
|
+
|
105
|
+
# @method last_updated
|
106
|
+
# Get the last updated time.
|
107
|
+
#
|
108
|
+
# @return [Time]
|
109
|
+
|
110
|
+
# @method last_updated=
|
111
|
+
# Set the last updated time.
|
112
|
+
#
|
113
|
+
# @param [Time, #to_i] value
|
114
|
+
# @return [Time]
|
115
|
+
attribute(:last_updated) { |value| convert_time(value) }
|
116
|
+
|
117
|
+
# @method kills
|
118
|
+
# Get the number of kills per enemy type.
|
119
|
+
#
|
120
|
+
# @return [Hash]
|
121
|
+
|
122
|
+
# @method kills=
|
123
|
+
# Set the number of kills per enemy type.
|
124
|
+
#
|
125
|
+
# @param [#to_h] value
|
126
|
+
# @return [Hash]
|
127
|
+
attribute(:kills) { |value| value.to_h }
|
128
|
+
|
129
|
+
# @method highest_hardcore_level
|
130
|
+
# Get the highest hardcore level.
|
131
|
+
#
|
132
|
+
# @return [Integer]
|
133
|
+
|
134
|
+
# @method highest_hardcore_level=
|
135
|
+
# Set the highest hardcore level.
|
136
|
+
#
|
137
|
+
# @param [#to_i] value
|
138
|
+
# @return [Integer]
|
139
|
+
attribute(:highest_hardcore_level) { |value| value.to_i }
|
140
|
+
|
141
|
+
# @method time_played
|
142
|
+
# Get the time played.
|
143
|
+
#
|
144
|
+
# @return [Hash]
|
145
|
+
|
146
|
+
# @method time_played=
|
147
|
+
# Set the time played.
|
148
|
+
#
|
149
|
+
# @param [#to_h] value
|
150
|
+
# @return [Hash]
|
151
|
+
attribute(:time_played) { |value| value.to_h }
|
152
|
+
|
153
|
+
# @method progression
|
154
|
+
# Get the act progression.
|
155
|
+
#
|
156
|
+
# @return [Hash]
|
157
|
+
|
158
|
+
# @method time_played=
|
159
|
+
# Set the act progression.
|
160
|
+
#
|
161
|
+
# @param [#to_h] value
|
162
|
+
# @return [Hash]
|
163
|
+
attribute(:progression) { |value| value.to_h }
|
164
|
+
|
165
|
+
# @method fallen_heroes
|
166
|
+
# Get the fallen heroes.
|
167
|
+
#
|
168
|
+
# @return [<Hero>]
|
169
|
+
|
170
|
+
# @method fallen_heroes=
|
171
|
+
# Set the fallen heroes.
|
172
|
+
#
|
173
|
+
# @param [#to_a] value
|
174
|
+
# @return [<Hero>]
|
175
|
+
attribute(:fallen_heroes) { |value| value.to_a }
|
176
|
+
|
177
|
+
protected
|
178
|
+
|
179
|
+
def convert_hero(value)
|
180
|
+
value.is_a?(Hero) ? value : Hero.new(value)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "bn/error/api/base"
|
2
|
+
|
3
|
+
module BN
|
4
|
+
module Error
|
5
|
+
module API
|
6
|
+
# Raised when the locale is invalid.
|
7
|
+
class InvalidLocale < Base
|
8
|
+
attribute(:region)
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
"Invalid locale for region '#{@region[:name]}'. Must be one of the following: #{@region[:locales]}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|