rbattlenet 2.0.0 → 2.1.0

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 (46) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -3
  3. data/lib/rbattlenet/endpoints/wow/character.rb +41 -1
  4. data/lib/rbattlenet/endpoints/wow/character/{pvp_bracket_statistics.rb → achievement_statistics.rb} +2 -2
  5. data/lib/rbattlenet/endpoints/wow/character/active_quests.rb +9 -0
  6. data/lib/rbattlenet/endpoints/wow/character/completed_dungeons.rb +9 -0
  7. data/lib/rbattlenet/endpoints/wow/character/completed_quests.rb +9 -0
  8. data/lib/rbattlenet/endpoints/wow/character/completed_raids.rb +9 -0
  9. data/lib/rbattlenet/endpoints/wow/character/legacy.rb +27 -0
  10. data/lib/rbattlenet/endpoints/wow/character/professions.rb +9 -0
  11. data/lib/rbattlenet/endpoints/wow/character/pvp_bracket_2v2.rb +9 -0
  12. data/lib/rbattlenet/endpoints/wow/character/pvp_bracket_3v3.rb +9 -0
  13. data/lib/rbattlenet/endpoints/wow/character/pvp_bracket_rbg.rb +9 -0
  14. data/lib/rbattlenet/rbattlenet.rb +11 -10
  15. data/lib/rbattlenet/result_collection.rb +19 -19
  16. data/lib/rbattlenet/version.rb +1 -1
  17. data/rbattlenet.gemspec +1 -0
  18. data/spec/lib/wow/character/achievement_statistics_spec.rb +28 -0
  19. data/spec/lib/wow/character/active_quests_spec.rb +28 -0
  20. data/spec/lib/wow/character/completed_dungeons_spec.rb +28 -0
  21. data/spec/lib/wow/character/completed_quests_spec.rb +28 -0
  22. data/spec/lib/wow/character/completed_raids_spec.rb +28 -0
  23. data/spec/lib/wow/character/legacy_spec.rb +37 -0
  24. data/spec/lib/wow/character/professions_spec.rb +16 -0
  25. data/spec/lib/wow/character/pvp_bracket_2v2_spec.rb +16 -0
  26. data/spec/lib/wow/character/pvp_bracket_3v3_spec.rb +16 -0
  27. data/spec/lib/wow/character/pvp_bracket_rbg_spec.rb +16 -0
  28. data/spec/lib/wow/title_spec.rb +12 -0
  29. data/spec/vcr_cassettes/wow_character_achievement_statistics.yml +1144 -0
  30. data/spec/vcr_cassettes/wow_character_achievement_statistics_multiple.yml +1200 -0
  31. data/spec/vcr_cassettes/wow_character_active_quests.yml +63 -0
  32. data/spec/vcr_cassettes/wow_character_active_quests_multiple.yml +119 -0
  33. data/spec/vcr_cassettes/wow_character_completed_dungeons.yml +228 -0
  34. data/spec/vcr_cassettes/wow_character_completed_dungeons_multiple.yml +393 -0
  35. data/spec/vcr_cassettes/wow_character_completed_quests.yml +7916 -0
  36. data/spec/vcr_cassettes/wow_character_completed_quests_multiple.yml +7972 -0
  37. data/spec/vcr_cassettes/wow_character_completed_raids.yml +559 -0
  38. data/spec/vcr_cassettes/wow_character_completed_raids_multiple.yml +615 -0
  39. data/spec/vcr_cassettes/wow_character_professions.yml +721 -0
  40. data/spec/vcr_cassettes/{wow_character_pvp_bracket_statistics.yml → wow_character_pvp_bracket_2v2_statistics.yml} +10 -10
  41. data/spec/vcr_cassettes/wow_character_pvp_bracket_3v3_statistics.yml +58 -0
  42. data/spec/vcr_cassettes/wow_character_pvp_bracket_rbg_statistics.yml +58 -0
  43. data/spec/vcr_cassettes/wow_legacy_characters.yml +3104 -0
  44. data/spec/vcr_cassettes/wow_legacy_characters_multiple.yml +6678 -0
  45. metadata +78 -7
  46. data/spec/lib/wow/character/pvp_bracket_statistics_spec.rb +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2625bfff660d3951abff427ef9692123cf29185cbe43b6619c6f5892257be3f
4
- data.tar.gz: e40d9743740c68fcb4a583ed28e3cd355693d097f6f0c2a99c8f8a078589f97e
3
+ metadata.gz: 46f0a0e9ac24c1ddb686d226fe8f484236c7a9d2c380d70f817b424f6d8c271b
4
+ data.tar.gz: 66641411e1896c5d3d33e94a9e57bf4b1c330ffde0cc21f6dcdd42d7a88730de
5
5
  SHA512:
6
- metadata.gz: 66a85707b1e2379f6310ef3db727a3428c046807e2280442da0cfd1e300c37cc1ca1997c0cc91efd4b048e0a8f86a029549b16fc43cdc6337239e3e141ed10c7
7
- data.tar.gz: 9f469785d675e271bd36705a83b7354cda046835f613812d795ef7b3492a218133f4b65b205c8b2d23f23564ee4b208d74a6d7fe5ba0e990ee46231ed6c131f1
6
+ metadata.gz: db1341a52e0881b9eeb0e45d5817f99834351c38b0e7a54081671be6f2486f53c1c823469a2087916f08cd65aa9132f8d1c76b86d579f0baddf4013d72577e24
7
+ data.tar.gz: cdd928eb7410dcebd8b736ced90fc8372f9aa744d4e5c13fa27bc9cff6a52528bfbca7b9b6660b5b55a28dd6ec3466f454eb8835fed11757f8810d329b89291c
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  A Ruby gem that wraps Blizzard's Game Data and Profile APIs.
4
4
 
5
+ ### Please note, this project is not actively maintained, but PRs are always welcome!
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
@@ -32,11 +34,13 @@ RBattlenet.set_options(region: "us", locale: "en_US")
32
34
  ```
33
35
 
34
36
  Singular requests will be returned as a `RBattlenet::Result` object. Requests with an array passed in will
35
- be returned as a `RBattlenet::ResultCollection` object. If you want to simply receive the raw HTTP response you can
36
- set that like so:
37
+ be returned as a `RBattlenet::ResultCollection` object by default. If you want to simply receive the raw HTTP response
38
+ or the response as a Hash you can set that like so:
37
39
 
38
40
  ```ruby
39
- RBattlenet.set_options(raw_response: true)
41
+ RBattlenet.set_options(response_type: :struct) # Default
42
+ RBattlenet.set_options(response_type: :hash)
43
+ RBattlenet.set_options(response_type: :raw)
40
44
  ```
41
45
 
42
46
  #### Step 3. Call the API methods to request data
@@ -3,7 +3,7 @@ module RBattlenet
3
3
  class Character < RBattlenet::Endpoints::Base
4
4
  SUPPORTED_FIELDS = [:itself, :achievements, :appearance, :equipment, :hunter_pets, :keystones, :media,
5
5
  :mounts, :pets, :pvp_summary, :reputations, :specializations, :statistics, :status,
6
- :titles]
6
+ :titles, :legacy]
7
7
 
8
8
  class << self
9
9
  def path(character)
@@ -14,10 +14,30 @@ module RBattlenet
14
14
  RBattlenet::Wow::Character::Achievements
15
15
  end
16
16
 
17
+ def achievement_statistics
18
+ RBattlenet::Wow::Character::AchievementStatistics
19
+ end
20
+
21
+ def active_quests
22
+ RBattlenet::Wow::Character::ActiveQuests
23
+ end
24
+
17
25
  def appearance
18
26
  RBattlenet::Wow::Character::Appearance
19
27
  end
20
28
 
29
+ def completed_dungeons
30
+ RBattlenet::Wow::Character::CompletedDungeons
31
+ end
32
+
33
+ def completed_quests
34
+ RBattlenet::Wow::Character::CompletedQuests
35
+ end
36
+
37
+ def completed_raids
38
+ RBattlenet::Wow::Character::CompletedRaids
39
+ end
40
+
21
41
  def equipment
22
42
  RBattlenet::Wow::Character::Equipment
23
43
  end
@@ -42,6 +62,22 @@ module RBattlenet
42
62
  RBattlenet::Wow::Character::Pets
43
63
  end
44
64
 
65
+ def professions
66
+ RBattlenet::Wow::Character::Professions
67
+ end
68
+
69
+ def pvp_bracket_2v2
70
+ RBattlenet::Wow::Character::PvpBracket2v2
71
+ end
72
+
73
+ def pvp_bracket_3v3
74
+ RBattlenet::Wow::Character::PvpBracket3v3
75
+ end
76
+
77
+ def pvp_bracket_rbg
78
+ RBattlenet::Wow::Character::PvpBracketRbg
79
+ end
80
+
45
81
  def pvp_summary
46
82
  RBattlenet::Wow::Character::PvpSummary
47
83
  end
@@ -65,6 +101,10 @@ module RBattlenet
65
101
  def titles
66
102
  RBattlenet::Wow::Character::Titles
67
103
  end
104
+
105
+ def legacy
106
+ RBattlenet::Wow::Character::Legacy
107
+ end
68
108
  end
69
109
  end
70
110
  end
@@ -1,8 +1,8 @@
1
1
  module RBattlenet
2
2
  module Wow
3
- class Character::PvpBracketStatistics < RBattlenet::Endpoints::Base
3
+ class Character::AchievementStatistics < RBattlenet::Endpoints::Base
4
4
  def self.path(character)
5
- RBattlenet.uri("profile/wow/character/#{character[:realm]}/#{character[:name]}/pvp-bracket/#{character[:bracket]}?namespace=profile-")
5
+ RBattlenet.uri("profile/wow/character/#{character[:realm]}/#{character[:name]}/achievements/statistics?namespace=profile-")
6
6
  end
7
7
  end
8
8
  end
@@ -0,0 +1,9 @@
1
+ module RBattlenet
2
+ module Wow
3
+ class Character::ActiveQuests < RBattlenet::Endpoints::Base
4
+ def self.path(character)
5
+ RBattlenet.uri("profile/wow/character/#{character[:realm]}/#{character[:name]}/quests?namespace=profile-")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module RBattlenet
2
+ module Wow
3
+ class Character::CompletedDungeons < RBattlenet::Endpoints::Base
4
+ def self.path(character)
5
+ RBattlenet.uri("profile/wow/character/#{character[:realm]}/#{character[:name]}/encounters/dungeons?namespace=profile-")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module RBattlenet
2
+ module Wow
3
+ class Character::CompletedQuests < RBattlenet::Endpoints::Base
4
+ def self.path(character)
5
+ RBattlenet.uri("profile/wow/character/#{character[:realm]}/#{character[:name]}/quests/completed?namespace=profile-")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module RBattlenet
2
+ module Wow
3
+ class Character::CompletedRaids < RBattlenet::Endpoints::Base
4
+ def self.path(character)
5
+ RBattlenet.uri("profile/wow/character/#{character[:realm]}/#{character[:name]}/encounters/raids?namespace=profile-")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,27 @@
1
+ module RBattlenet
2
+ module Wow
3
+ class Character::Legacy < RBattlenet::Endpoints::Base
4
+ FIELDS = [
5
+ "items",
6
+ "reputation",
7
+ "audit",
8
+ "statistics",
9
+ "achievements",
10
+ "pets",
11
+ "pvp",
12
+ "professions",
13
+ "quests",
14
+ "mounts",
15
+ "titles",
16
+ ]
17
+
18
+ def self.path(character)
19
+ RBattlenet.uri("wow/character/#{character[:realm]}/#{character[:name]}?#{self.endpoints}")
20
+ end
21
+
22
+ def self.endpoints
23
+ "fields=#{FIELDS.join("&fields=")}"
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,9 @@
1
+ module RBattlenet
2
+ module Wow
3
+ class Character::Professions < RBattlenet::Endpoints::Base
4
+ def self.path(character)
5
+ RBattlenet.uri("profile/wow/character/#{character[:realm]}/#{character[:name]}/professions?namespace=profile-")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module RBattlenet
2
+ module Wow
3
+ class Character::PvpBracket2v2 < RBattlenet::Endpoints::Base
4
+ def self.path(character)
5
+ RBattlenet.uri("profile/wow/character/#{character[:realm]}/#{character[:name]}/pvp-bracket/2v2?namespace=profile-")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module RBattlenet
2
+ module Wow
3
+ class Character::PvpBracket3v3 < RBattlenet::Endpoints::Base
4
+ def self.path(character)
5
+ RBattlenet.uri("profile/wow/character/#{character[:realm]}/#{character[:name]}/pvp-bracket/3v3?namespace=profile-")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module RBattlenet
2
+ module Wow
3
+ class Character::PvpBracketRbg < RBattlenet::Endpoints::Base
4
+ def self.path(character)
5
+ RBattlenet.uri("profile/wow/character/#{character[:realm]}/#{character[:name]}/pvp-bracket/rbg?namespace=profile-")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,11 +1,14 @@
1
1
  module RBattlenet
2
2
  @@region = "eu"
3
3
  @@locale = "en_gb"
4
- @@raw = false
4
+ @@response_type = :struct
5
+ @@concurrency = 20
6
+ @@timeout = 120
5
7
 
6
8
  #Set Access Token for requests. Required
7
9
  def self.authenticate(client_id:, client_secret:)
8
- response = Typhoeus.post("https://#{@@region}.battle.net/oauth/token",
10
+ oauth_region = ["kr", "tw"].include?(@@region.downcase) ? "apac" : @@region
11
+ response = Typhoeus.post("https://#{oauth_region}.battle.net/oauth/token",
9
12
  body: { grant_type: :client_credentials },
10
13
  userpwd: "#{client_id}:#{client_secret}",
11
14
  )
@@ -14,8 +17,8 @@ module RBattlenet
14
17
  true
15
18
  end
16
19
 
17
- def self.set_options(region: @@region, locale: @@locale, raw_response: @@raw)
18
- @@region, @@locale, @@raw = region, locale, raw_response
20
+ def self.set_options(region: @@region, locale: @@locale, response_type: @@response_type, concurrency: @@concurrency, timeout: @@timeout)
21
+ @@region, @@locale, @@response_type, @@concurrency, @@timeout = region, locale, response_type, concurrency, timeout
19
22
  true
20
23
  end
21
24
 
@@ -23,19 +26,19 @@ module RBattlenet
23
26
 
24
27
  class << self
25
28
  def get(subjects)
26
- store = @@raw ? [] : RBattlenet::ResultCollection.new
29
+ store = @@response_type == :raw ? [] : RBattlenet::ResultCollection.new(@@response_type)
27
30
 
28
31
  headers = {}
29
32
  headers['Authorization'] = "Bearer #{@@token}" if @@token
30
33
 
31
34
  # Limit concurrency to prevent hitting the API request per-second cap.
32
- hydra = Typhoeus::Hydra.new(max_concurrency: 50)
35
+ hydra = Typhoeus::Hydra.new(max_concurrency: @@concurrency)
33
36
  subjects.each do |uris, subject|
34
37
  uris.each do |field, uri|
35
- request = Typhoeus::Request.new(URI.encode(uri), headers: headers)
38
+ request = Typhoeus::Request.new(URI.encode(uri), headers: headers, timeout: @@timeout)
36
39
 
37
40
  request.on_complete do |response|
38
- if @@raw
41
+ if @@response_type == :raw
39
42
  store << response
40
43
  else
41
44
  store.add(subject, field, response)
@@ -52,8 +55,6 @@ module RBattlenet
52
55
 
53
56
  hydra.run
54
57
  store.size == 1 ? store.first : store
55
- rescue => err
56
- raise RBattlenet::Errors::ConnectionError.new
57
58
  end
58
59
 
59
60
  def uri(path)
@@ -6,42 +6,35 @@ module RBattlenet
6
6
 
7
7
  attr_reader :results
8
8
 
9
- def initialize
9
+ def initialize(response_type)
10
+ @response_object = response_type == :hash ? HashResult : Result
11
+ @empty_response_object = response_type == :hash ? EmptyHashResult : EmptyResult
10
12
  @results = []
11
13
  end
12
14
 
13
15
  def add(subject, field, response)
14
16
  data = if response.code == 200
15
- result = JSON.parse(response.body, object_class: Result)
16
- result.is_a?(Array) ? Result.new(data: result.size == 1 ? result.first : result) : result
17
- else
18
- EmptyResult.new(status_code: response.code, response: response)
19
- end
17
+ result = JSON.parse(response.body, object_class: @response_object) rescue nil
18
+ result && (result.is_a?(Array) ? @response_object.new(data: result.size == 1 ? result.first : result) : result)
19
+ end || @empty_response_object.new(status_code: response.code)
20
20
 
21
- data.status_code ||= 200
22
- data.source, data.field = subject, field
21
+ data[:status_code] ||= 200
22
+ data[:source], data[:field] = subject, field
23
23
  @results << data
24
24
  end
25
25
 
26
26
  def complete(subject, results_needed)
27
- subject_results = @results.group_by(&:source)[subject]
27
+ subject_results = @results.group_by{ |result| result[:source] }[subject]
28
28
  if subject_results.size == results_needed
29
- @results.reject!{ |result| result.source == subject }
30
-
31
- unless base_result = subject_results.select{ |result| result.class == EmptyResult }.first
32
- base_result = subject_results.select{ |result| result.field == :itself }.first
33
- (subject_results - [base_result]).each{ |result| base_result << result }
34
- end
29
+ @results.reject!{ |result| result[:source] == subject }
30
+ base_result = subject_results.select{ |result| result[:field] == :itself }.first
31
+ (subject_results - [base_result]).each{ |result| base_result << result }
35
32
 
36
33
  @results << base_result
37
34
  base_result
38
35
  end
39
36
  end
40
37
 
41
- def has_errors?
42
- @results.map(&:class).include? EmptyResult
43
- end
44
-
45
38
  def_delegators :results, :first, :last, :size
46
39
  end
47
40
 
@@ -51,5 +44,12 @@ module RBattlenet
51
44
  end
52
45
  end
53
46
 
47
+ class HashResult < Hash
48
+ def <<(result)
49
+ self[result[:field]] = result[result[:field]] || result
50
+ end
51
+ end
52
+
54
53
  class EmptyResult < Result; end
54
+ class EmptyHashResult < HashResult; end
55
55
  end
@@ -1,3 +1,3 @@
1
1
  module RBattlenet
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "rspec", "~> 3.0"
25
25
  spec.add_development_dependency 'vcr', '~> 2.9.3'
26
26
  spec.add_development_dependency "webmock"
27
+ spec.add_development_dependency "byebug"
27
28
 
28
29
  spec.add_runtime_dependency "typhoeus", "~> 1.1"
29
30
  spec.add_runtime_dependency "require_all" # convenience
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe RBattlenet::Wow::Character::AchievementStatistics do
4
+ before do
5
+ RBattlenet.authenticate(client_id: ENV["CLIENT_ID"], client_secret: ENV["CLIENT_SECRET"])
6
+ end
7
+
8
+ describe "#find_character_achievement_statistics" do
9
+ it "fetches character data" do
10
+ with_connection("wow_character_achievement_statistics") do
11
+ result = RBattlenet::Wow::Character::AchievementStatistics.find(realm: "stormrage", name: "sheday")
12
+ expect(result.statistics.class).to eq Array
13
+ end
14
+ end
15
+ end
16
+
17
+ describe "#find_multiple_character_achievement_statisticss" do
18
+ it "fetches character data" do
19
+ with_connection("wow_character_achievement_statistics_multiple") do
20
+ collection = RBattlenet::Wow::Character::AchievementStatistics.find([
21
+ { realm: "stormrage", name: "sheday" },
22
+ { realm: "howling-fjord", name: "альвеоняша" },
23
+ ])
24
+ expect(collection.results.map(&:statistics).map(&:class)).to eq [Array, Array]
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe RBattlenet::Wow::Character::ActiveQuests do
4
+ before do
5
+ RBattlenet.authenticate(client_id: ENV["CLIENT_ID"], client_secret: ENV["CLIENT_SECRET"])
6
+ end
7
+
8
+ describe "#find_character_active_quests" do
9
+ it "fetches character data" do
10
+ with_connection("wow_character_active_quests") do
11
+ result = RBattlenet::Wow::Character::ActiveQuests.find(realm: "stormrage", name: "sheday")
12
+ expect(result.in_progress.class).to eq Array
13
+ end
14
+ end
15
+ end
16
+
17
+ describe "#find_multiple_character_active_questss" do
18
+ it "fetches character data" do
19
+ with_connection("wow_character_active_quests_multiple") do
20
+ collection = RBattlenet::Wow::Character::ActiveQuests.find([
21
+ { realm: "stormrage", name: "sheday" },
22
+ { realm: "howling-fjord", name: "альвеоняша" },
23
+ ])
24
+ expect(collection.results.map(&:in_progress).map(&:class)).to eq [Array, Array]
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe RBattlenet::Wow::Character::CompletedDungeons do
4
+ before do
5
+ RBattlenet.authenticate(client_id: ENV["CLIENT_ID"], client_secret: ENV["CLIENT_SECRET"])
6
+ end
7
+
8
+ describe "#find_character_completed_dungeons" do
9
+ it "fetches character data" do
10
+ with_connection("wow_character_completed_dungeons") do
11
+ result = RBattlenet::Wow::Character::CompletedDungeons.find(realm: "stormrage", name: "sheday")
12
+ expect(result.expansions.class).to eq Array
13
+ end
14
+ end
15
+ end
16
+
17
+ describe "#find_multiple_character_completed_dungeonss" do
18
+ it "fetches character data" do
19
+ with_connection("wow_character_completed_dungeons_multiple") do
20
+ collection = RBattlenet::Wow::Character::CompletedDungeons.find([
21
+ { realm: "stormrage", name: "sheday" },
22
+ { realm: "howling-fjord", name: "альвеоняша" },
23
+ ])
24
+ expect(collection.results.map(&:expansions).map(&:class)).to eq [Array, Array]
25
+ end
26
+ end
27
+ end
28
+ end