bnet 0.0.4 → 0.0.5
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.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/TODO.md +8 -2
- data/bnet.gemspec +1 -0
- data/fixtures/cassettes/SC2_Jabito_Ladder_records.yml +1031 -0
- data/fixtures/cassettes/SC2_Jabito_s_Ladder_Records.yml +1445 -0
- data/fixtures/cassettes/SC2_Naniwa_ladder_profile_found.yml +1112 -0
- data/lib/bnet.rb +1 -1
- data/lib/bnet/bnet_resource.rb +3 -0
- data/lib/bnet/starcraft2/ladder.rb +101 -0
- data/lib/bnet/starcraft2/profile.rb +6 -2
- data/lib/bnet/version.rb +1 -1
- data/spec/bnet/starcraft2/ladder_spec.rb +80 -0
- data/spec/bnet/starcraft2/profile_spec.rb +29 -5
- data/spec/spec_helper.rb +2 -0
- metadata +22 -2
    
        data/lib/bnet.rb
    CHANGED
    
    | @@ -25,7 +25,7 @@ require 'bnet/diablo3/skill' | |
| 25 25 | 
             
            require 'bnet/diablo3/follower'
         | 
| 26 26 | 
             
            # require 'bnet/community' #TODO remove?
         | 
| 27 27 | 
             
            require 'bnet/starcraft2'
         | 
| 28 | 
            -
             | 
| 28 | 
            +
            require 'bnet/starcraft2/ladder'
         | 
| 29 29 | 
             
            require 'bnet/starcraft2/match'
         | 
| 30 30 | 
             
            require 'bnet/starcraft2/career'
         | 
| 31 31 | 
             
            require 'bnet/starcraft2/profile'
         | 
    
        data/lib/bnet/bnet_resource.rb
    CHANGED
    
    
| @@ -0,0 +1,101 @@ | |
| 1 | 
            +
            class Bnet::Starcraft2::Ladder < Bnet::BnetResource
         | 
| 2 | 
            +
              attr_accessor :raw_attributes, :characters, :ladder_name, :ladder_id,
         | 
| 3 | 
            +
                :division, :rank, :league, :matchmaking_queue, :wins, :losses
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              #TODO make character object for :characters
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              PARAMS_MAPPING = {
         | 
| 8 | 
            +
                "ladderName"        => :ladder_name,
         | 
| 9 | 
            +
                "ladderId"          => :ladder_id,
         | 
| 10 | 
            +
                "division"          => :division,
         | 
| 11 | 
            +
                "rank"              => :rank,
         | 
| 12 | 
            +
                "league"            => :league,
         | 
| 13 | 
            +
                "matchMakingQueue" => :matchmaking_queue,
         | 
| 14 | 
            +
                "wins"              => :wins,
         | 
| 15 | 
            +
                "losses"            => :losses
         | 
| 16 | 
            +
              }
         | 
| 17 | 
            +
             | 
| 18 | 
            +
             | 
| 19 | 
            +
              def self.find_current(profile, args = {})
         | 
| 20 | 
            +
                profile_id = profile.profile_id
         | 
| 21 | 
            +
                name = profile.name
         | 
| 22 | 
            +
                realm = profile.realm || '1'
         | 
| 23 | 
            +
                locale = args[:locale] || 'en_US'
         | 
| 24 | 
            +
                api_key  = args[:api_key] || Bnet.configuration.api_key
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                client = Bnet::Starcraft2.new(region: profile.region)
         | 
| 27 | 
            +
                call_url = client.url + "profile/#{profile_id}/#{realm}/#{name}/ladders?apikey=#{api_key}&locale=#{locale}"
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                begin
         | 
| 30 | 
            +
                  data = open(call_url)
         | 
| 31 | 
            +
                  raw_collection_response = JSON.parse(data.read)
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                  if Bnet::API.valid_call?(data.status, raw_collection_response)
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                    ladders = raw_collection_response["currentSeason"].collect do |raw_ladder_character_response|
         | 
| 36 | 
            +
                      raw_characters = raw_ladder_character_response["characters"]
         | 
| 37 | 
            +
                      raw_ladders = raw_ladder_character_response["ladder"].collect do |raw_ladder| 
         | 
| 38 | 
            +
                        ladder = from_api(raw_ladder)
         | 
| 39 | 
            +
                        ladder.characters = raw_characters
         | 
| 40 | 
            +
                        ladder
         | 
| 41 | 
            +
                      end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                      raw_ladders
         | 
| 44 | 
            +
                    end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                    ladders.flatten!
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                  else
         | 
| 49 | 
            +
                    ladders = []
         | 
| 50 | 
            +
                  end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                rescue OpenURI::HTTPError => e
         | 
| 53 | 
            +
                  ladders = []
         | 
| 54 | 
            +
                end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                return ladders
         | 
| 57 | 
            +
             | 
| 58 | 
            +
              end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
              def self.find_previous(profile, args ={} )
         | 
| 61 | 
            +
                profile_id = profile.profile_id
         | 
| 62 | 
            +
                name = profile.name
         | 
| 63 | 
            +
                realm = profile.realm || '1'
         | 
| 64 | 
            +
                locale = args[:locale] || 'en_US'
         | 
| 65 | 
            +
                api_key  = args[:api_key] || Bnet.configuration.api_key
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                client = Bnet::Starcraft2.new(region: profile.region)
         | 
| 68 | 
            +
                call_url = client.url + "profile/#{profile_id}/#{realm}/#{name}/ladders?apikey=#{api_key}&locale=#{locale}"
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                begin
         | 
| 71 | 
            +
                  data = open(call_url)
         | 
| 72 | 
            +
                  raw_collection_response = JSON.parse(data.read)
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                  if Bnet::API.valid_call?(data.status, raw_collection_response)
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                    ladders = raw_collection_response["previousSeason"].collect do |raw_ladder_character_response|
         | 
| 77 | 
            +
                      raw_characters = raw_ladder_character_response["characters"]
         | 
| 78 | 
            +
                      raw_ladders = raw_ladder_character_response["ladder"].collect do |raw_ladder| 
         | 
| 79 | 
            +
                        ladder = from_api(raw_ladder)
         | 
| 80 | 
            +
                        ladder.characters = raw_characters
         | 
| 81 | 
            +
                        ladder
         | 
| 82 | 
            +
                      end
         | 
| 83 | 
            +
             | 
| 84 | 
            +
                      raw_ladders
         | 
| 85 | 
            +
                    end
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                    ladders.flatten!
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                  else
         | 
| 90 | 
            +
                    ladders = []
         | 
| 91 | 
            +
                  end
         | 
| 92 | 
            +
             | 
| 93 | 
            +
                rescue OpenURI::HTTPError => e
         | 
| 94 | 
            +
                  ladders = []
         | 
| 95 | 
            +
                end
         | 
| 96 | 
            +
             | 
| 97 | 
            +
                return ladders
         | 
| 98 | 
            +
             | 
| 99 | 
            +
              end
         | 
| 100 | 
            +
             | 
| 101 | 
            +
            end
         | 
| @@ -83,8 +83,12 @@ class Bnet::Starcraft2::Profile < Bnet::BnetResource | |
| 83 83 | 
             
                @matches ||= Bnet::Starcraft2::Match.all(self)
         | 
| 84 84 | 
             
              end
         | 
| 85 85 |  | 
| 86 | 
            -
              def  | 
| 87 | 
            -
                 | 
| 86 | 
            +
              def current_ladder_season
         | 
| 87 | 
            +
                @ladders ||= Bnet::Starcraft2::Ladder.find_current(self)
         | 
| 88 | 
            +
              end
         | 
| 89 | 
            +
             | 
| 90 | 
            +
              def previous_ladder_season
         | 
| 91 | 
            +
                @ladders ||= Bnet::Starcraft2::Ladder.find_previous(self)
         | 
| 88 92 | 
             
              end
         | 
| 89 93 |  | 
| 90 94 | 
             
              def self.from_api(response)
         | 
    
        data/lib/bnet/version.rb
    CHANGED
    
    
| @@ -0,0 +1,80 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Bnet::Starcraft2::Ladder do
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              describe '.find_current(profile)', vcr: {cassette_name: 'SC2 Jabito Ladder records'} do
         | 
| 6 | 
            +
                subject {described_class.find_current(profile)}
         | 
| 7 | 
            +
                let(:profile) { Bnet::Starcraft2::Profile.new(profile_id: 2144359, name: 'JaBiTo', region: 'us') }
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                it "should return a collection of ladder objects" do
         | 
| 10 | 
            +
                  expect(subject).to include(
         | 
| 11 | 
            +
                    an_object_having_attributes(ladder_name: 'Arbiter Epsilon',
         | 
| 12 | 
            +
                                                ladder_id: 175161,
         | 
| 13 | 
            +
                                                division: 72,
         | 
| 14 | 
            +
                                                rank: 47,
         | 
| 15 | 
            +
                                                league: 'DIAMOND',
         | 
| 16 | 
            +
                                                matchmaking_queue: 'HOTS_SOLO',
         | 
| 17 | 
            +
                                                wins: 21,
         | 
| 18 | 
            +
                                                losses: 7
         | 
| 19 | 
            +
                                               )
         | 
| 20 | 
            +
                  )
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                it "assigns characters to ladder instances" do
         | 
| 24 | 
            +
                  subject[0].characters.each do |character|
         | 
| 25 | 
            +
                    expect(character).to_not be_empty
         | 
| 26 | 
            +
                    expect(character['id']).to eq(2144359)
         | 
| 27 | 
            +
                    expect(character['realm']).to eq(1)
         | 
| 28 | 
            +
                    expect(character['displayName']).to eq('JaBiTo')
         | 
| 29 | 
            +
                    expect(character['clanTag']).to be_empty
         | 
| 30 | 
            +
                    expect(character['clanName']).to be_empty
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
              describe '.find_previous(profile)', vcr: {cassette_name: 'SC2 Jabito Ladder records'} do
         | 
| 37 | 
            +
                subject {described_class.find_previous(profile)}
         | 
| 38 | 
            +
                let(:profile) { Bnet::Starcraft2::Profile.new(profile_id: 2144359, name: 'JaBiTo', region: 'us') }
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                it "should return Jabito's previous ladder records" do
         | 
| 41 | 
            +
                  expect(subject).to have_at_least(7).items
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                  expect(subject).to include(
         | 
| 44 | 
            +
                    an_object_having_attributes(ladder_name: 'Thor Oscar',
         | 
| 45 | 
            +
                                                ladder_id: 171549,
         | 
| 46 | 
            +
                                                division: 9,
         | 
| 47 | 
            +
                                                rank: 31,
         | 
| 48 | 
            +
                                                league: 'SILVER',
         | 
| 49 | 
            +
                                                matchmaking_queue: 'HOTS_FOURS',
         | 
| 50 | 
            +
                                                wins: 5,
         | 
| 51 | 
            +
                                                losses: 2
         | 
| 52 | 
            +
                                               ))
         | 
| 53 | 
            +
                end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                context "the hots 4v4 record" do
         | 
| 56 | 
            +
                  let( :coop_4v4_ladder) { subject[0]  }
         | 
| 57 | 
            +
                  it "assigns characters to ladder instances" do
         | 
| 58 | 
            +
                    expect(coop_4v4_ladder).to have_exactly(4).characters
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                    player_one = coop_4v4_ladder.characters[0]
         | 
| 61 | 
            +
                    expect(player_one).to_not be_empty
         | 
| 62 | 
            +
                    expect(player_one['id']).to eq(2068331)
         | 
| 63 | 
            +
                    expect(player_one['realm']).to eq(1)
         | 
| 64 | 
            +
                    expect(player_one['displayName']).to eq('SaiirupPC')
         | 
| 65 | 
            +
                    expect(player_one['clanTag']).to eq('pinoy')
         | 
| 66 | 
            +
                    expect(player_one['clanName']).to eq('xXxClan')
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                    player_two = coop_4v4_ladder.characters[1]
         | 
| 69 | 
            +
                    expect(player_two).to_not be_empty
         | 
| 70 | 
            +
                    expect(player_two['id']).to eq(2144359)
         | 
| 71 | 
            +
                    expect(player_two['realm']).to eq(1)
         | 
| 72 | 
            +
                    expect(player_two['displayName']).to eq('JaBiTo')
         | 
| 73 | 
            +
                    expect(player_two['clanTag']).to be_empty
         | 
| 74 | 
            +
                    expect(player_two['clanName']).to be_empty
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                  end
         | 
| 77 | 
            +
                end
         | 
| 78 | 
            +
             | 
| 79 | 
            +
              end
         | 
| 80 | 
            +
            end
         | 
| @@ -70,9 +70,8 @@ describe Bnet::Starcraft2::Profile do | |
| 70 70 | 
             
              describe '#matches' do
         | 
| 71 71 | 
             
                context 'Naniwa user is found', vcr: {cassette_name: 'SC2 Naniwa profile found' } do
         | 
| 72 72 | 
             
                  subject { profile.matches }
         | 
| 73 | 
            -
                  # subject { binding.pry }
         | 
| 74 73 | 
             
                  let(:profile) {
         | 
| 75 | 
            -
                     | 
| 74 | 
            +
                    Bnet::Starcraft2::Profile.find(profile_id: 2210662, name: 'NaNiwa', region: 'eu')
         | 
| 76 75 | 
             
                  }
         | 
| 77 76 |  | 
| 78 77 | 
             
                  it "returns a collection of matches for a given profile"  do
         | 
| @@ -86,8 +85,33 @@ describe Bnet::Starcraft2::Profile do | |
| 86 85 | 
             
                end
         | 
| 87 86 | 
             
              end
         | 
| 88 87 |  | 
| 89 | 
            -
              describe '# | 
| 90 | 
            -
                subject {profile. | 
| 91 | 
            -
                 | 
| 88 | 
            +
              describe '#current_ladder_season' do
         | 
| 89 | 
            +
                subject { profile.current_ladder_season }
         | 
| 90 | 
            +
                context "Jabito's ladder records user are found", vcr: {cassette_name: "SC2 Jabito's Ladder Records" } do
         | 
| 91 | 
            +
                  let(:profile) do
         | 
| 92 | 
            +
                    Bnet::Starcraft2::Profile.find(profile_id: 2144359, name: 'JaBiTo', region: 'us')
         | 
| 93 | 
            +
                  end
         | 
| 94 | 
            +
             | 
| 95 | 
            +
                  it "returns the current ladders statistics for the profile" do
         | 
| 96 | 
            +
                    expect(subject).to_not be_empty
         | 
| 97 | 
            +
                    expect(subject).to include( an_object_having_attributes(ladder_name: 'Arbiter Epsilon'))
         | 
| 98 | 
            +
                    expect(subject[0].characters[0]['displayName']).to eq('JaBiTo')
         | 
| 99 | 
            +
                  end
         | 
| 100 | 
            +
                end
         | 
| 101 | 
            +
              end
         | 
| 102 | 
            +
             | 
| 103 | 
            +
              describe "#previous_ladder_season" do
         | 
| 104 | 
            +
                subject { profile.previous_ladder_season }
         | 
| 105 | 
            +
                context "Jabito's ladder records user are found", vcr: {cassette_name: "SC2 Jabito's Ladder Records" } do
         | 
| 106 | 
            +
                  let(:profile) do
         | 
| 107 | 
            +
                    Bnet::Starcraft2::Profile.find(profile_id: 2144359, name: 'JaBiTo', region: 'us')
         | 
| 108 | 
            +
                  end
         | 
| 109 | 
            +
             | 
| 110 | 
            +
                  it "returns the previous ladder statisttics for the profile" do
         | 
| 111 | 
            +
                    expect(subject).to have(7).items
         | 
| 112 | 
            +
                    expect(subject).to include( an_object_having_attributes(ladder_name: 'Thor Oscar'))
         | 
| 113 | 
            +
                    expect(subject[0].characters[0]['displayName']).to eq('JaBiTo')
         | 
| 114 | 
            +
                  end
         | 
| 115 | 
            +
                end
         | 
| 92 116 | 
             
              end
         | 
| 93 117 | 
             
            end
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: bnet
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.5
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Buddy Magsipoc
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2014-09- | 
| 11 | 
            +
            date: 2014-09-11 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -66,6 +66,20 @@ dependencies: | |
| 66 66 | 
             
                - - '>='
         | 
| 67 67 | 
             
                  - !ruby/object:Gem::Version
         | 
| 68 68 | 
             
                    version: '0'
         | 
| 69 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 70 | 
            +
              name: rspec-collection_matchers
         | 
| 71 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 | 
            +
                requirements:
         | 
| 73 | 
            +
                - - '>='
         | 
| 74 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 75 | 
            +
                    version: '0'
         | 
| 76 | 
            +
              type: :development
         | 
| 77 | 
            +
              prerelease: false
         | 
| 78 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 | 
            +
                requirements:
         | 
| 80 | 
            +
                - - '>='
         | 
| 81 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 82 | 
            +
                    version: '0'
         | 
| 69 83 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 70 84 | 
             
              name: guard
         | 
| 71 85 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -197,7 +211,10 @@ files: | |
| 197 211 | 
             
            - TODO.md
         | 
| 198 212 | 
             
            - bnet.gemspec
         | 
| 199 213 | 
             
            - fixtures/cassettes/Bnet_Starcraft2_Match/_all_profile_/returns_a_collection_of_matches_for_a_given_profile.yml
         | 
| 214 | 
            +
            - fixtures/cassettes/SC2_Jabito_Ladder_records.yml
         | 
| 215 | 
            +
            - fixtures/cassettes/SC2_Jabito_s_Ladder_Records.yml
         | 
| 200 216 | 
             
            - fixtures/cassettes/SC2_Matches_for_Naniwa_Profile_found.yml
         | 
| 217 | 
            +
            - fixtures/cassettes/SC2_Naniwa_ladder_profile_found.yml
         | 
| 201 218 | 
             
            - fixtures/cassettes/SC2_Naniwa_profile_found.yml
         | 
| 202 219 | 
             
            - fixtures/cassettes/diablo_hero_found.yml
         | 
| 203 220 | 
             
            - fixtures/cassettes/diablo_hero_notf_found.yml
         | 
| @@ -224,6 +241,7 @@ files: | |
| 224 241 | 
             
            - lib/bnet/diablo3/skill.rb
         | 
| 225 242 | 
             
            - lib/bnet/starcraft2.rb
         | 
| 226 243 | 
             
            - lib/bnet/starcraft2/career.rb
         | 
| 244 | 
            +
            - lib/bnet/starcraft2/ladder.rb
         | 
| 227 245 | 
             
            - lib/bnet/starcraft2/match.rb
         | 
| 228 246 | 
             
            - lib/bnet/starcraft2/profile.rb
         | 
| 229 247 | 
             
            - lib/bnet/version.rb
         | 
| @@ -242,6 +260,7 @@ files: | |
| 242 260 | 
             
            - spec/bnet/diablo3/skill_spec.rb
         | 
| 243 261 | 
             
            - spec/bnet/diablo3_spec.rb
         | 
| 244 262 | 
             
            - spec/bnet/starcraft2/career_spec.rb
         | 
| 263 | 
            +
            - spec/bnet/starcraft2/ladder_spec.rb
         | 
| 245 264 | 
             
            - spec/bnet/starcraft2/match_spec.rb
         | 
| 246 265 | 
             
            - spec/bnet/starcraft2/profile_spec.rb
         | 
| 247 266 | 
             
            - spec/bnet/wow/character_spec.rb
         | 
| @@ -287,6 +306,7 @@ test_files: | |
| 287 306 | 
             
            - spec/bnet/diablo3/skill_spec.rb
         | 
| 288 307 | 
             
            - spec/bnet/diablo3_spec.rb
         | 
| 289 308 | 
             
            - spec/bnet/starcraft2/career_spec.rb
         | 
| 309 | 
            +
            - spec/bnet/starcraft2/ladder_spec.rb
         | 
| 290 310 | 
             
            - spec/bnet/starcraft2/match_spec.rb
         | 
| 291 311 | 
             
            - spec/bnet/starcraft2/profile_spec.rb
         | 
| 292 312 | 
             
            - spec/bnet/wow/character_spec.rb
         |