Skip to content

Instantly share code, notes, and snippets.

@marioizquierdo
Created October 25, 2011 21:20
Show Gist options
  • Save marioizquierdo/1314322 to your computer and use it in GitHub Desktop.
Save marioizquierdo/1314322 to your computer and use it in GitHub Desktop.
Add a Bnet Profile to your dev users
# Copy paste this method in the rails console
# If you have a user in your dev environment, you can add a bnet profile like this:
#
# add_bnet_profile_to :login => 'LiquidTyler', :bnet_id => 416097, :bnet_name => "LiquidTyler"
# add_bnet_profile_to :mlg_id => 1234, :bnet_id => 416097, :bnet_name => "LiquidTyler"
# add_bnet_profile_to :user => liquid, :bnet_id => 416097, :bnet_name => "LiquidTyler"
#
# So, you need to specify the bnet_id and the bnet_name of this user, and any of
# user model, login, mlg_id or id to identify the user.
def add_bnet_profile_to(options)
user = if options[:login]
User.find_by_login(options[:login])
elsif options[:mlg_id]
User.find_by_mlg_id options[:mlg_id]
elsif options[:id]
User.find options[:id]
elsif options[:user]
options[:user]
else
raise 'please provide a user identification'
end
bnet_url = "http://us.battle.net/sc2/en/profile/#{options[:bnet_id]}/1/#{options[:bnet_name]}/"
profile = BattleNetProfile.create :profile_url => bnet_url, :character_code => "1#{rand 10}#{rand 10}", :mlg_id => user.mlg_id
puts "#{options[:login].inspect} BattleNetProfile added. Try this to see how much wins this user have:
User.find_by_mlg_id(#{user.mlg_id}).battle_net_accounts.first.wins"
end
# And then, you will be able to add bent profiles to existing users with something like this:
add_bnet_profile_to :login => 'LiquidTyler', :bnet_id => 416097, :bnet_name => "LiquidTyler"
add_bnet_profile_to :login => 'LiquidJinro', :bnet_id => 1314421, :bnet_name => 'LiquidJinro'
add_bnet_profile_to :login => 'QxGiNkA', :bnet_id => 2928823, :bnet_name => 'QxGiNkA'
add_bnet_profile_to :login => 'guitsaru', :bnet_id => 1918894, :bnet_name => "guitsaru"
add_bnet_profile_to :login => 'logankoester', :bnet_id => 1485031, :bnet_name => "logankoester"
add_bnet_profile_to :login => 'AgoraSteve', :bnet_id => 2995518, :bnet_name => "MLGSteve"
add_bnet_profile_to :login => 'tothemario', :bnet_id => 3022871, :bnet_name => "MLGmario"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment