Created
August 29, 2012 23:01
-
-
Save JFickel/3520029 to your computer and use it in GitHub Desktop.
OpenURI::HTTPError in UsersController#update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def update | |
| @user = User.find(params[:id]) | |
| respond_to do |format| | |
| if @user.update_attributes(params[:user]) | |
| if @user.sc2_url? | |
| if @user.sc2_url[7,2] == 'us' | |
| @user.sc2_server = "US" | |
| end | |
| if @user.sc2_url[7,2] == 'eu' | |
| @user.sc2_server = "EU" | |
| end | |
| if @user.sc2_url[7,2] == 'kr' | |
| @user.sc2_server = "KOR" | |
| end | |
| @user.sc2_character = @user.sc2_url.split('/').last | |
| @user.sc2_identifier = @user.sc2_url.split('/')[6] | |
| @sc2_profile_doc = Nokogiri::HTML(open(@user.sc2_url)) | |
| @user.sc2_league = @sc2_profile_doc.xpath('//*[(@id = "career-stats")]//*[(((count(preceding-sibling::*) + 1) = 1) and parent::*)]//*[contains(concat( " ", @class, " " ), concat( " ", "league-name", " " ))]').text | |
| @sc2_ladder_doc = Nokogiri::HTML(open("http://us.battle.net/sc2/en/profile/#{@sc2_identifier}/1/#{@sc2_character}/ladder/leagues#current-rank")) | |
| @user.sc2_points = @sc2_ladder_doc.xpath('//*[(@id = "current-rank")]//*[(((count(preceding-sibling::*) + 1) = 4) and parent::*)][@class = "align-center"]').text | |
| @user.sc2_wins = @sc2_ladder_doc.xpath('//*[(@id = "current-rank")]//*[(((count(preceding-sibling::*) + 1) = 5) and parent::*)]').text | |
| @user.sc2_losses = @sc2_ladder_doc.xpath('//*[(@id = "current-rank")]//*[(((count(preceding-sibling::*) + 1) = 6) and parent::*)]').text | |
| end | |
| if @user.lol_summoner_name? | |
| @lol_na_doc = Nokogiri::HTML(open("http://competitive.na.leagueoflegends.com/ladders/na/current/rankedsolo5x5?summoner_name=#{@user.lol_summoner_name}")) | |
| @user.lol_rank = @lol_na_doc.xpath('//*[contains(concat( " ", @class, " " ), concat( " ", "views-field-rank", " " ))]').text | |
| @user.lol_wins = @lol_na_doc.xpath('//*[contains(concat( " ", @class, " " ), concat( " ", "views-field-wins", " " ))]').text | |
| @user.lol_losses = @lol_na_doc.xpath('//*[contains(concat( " ", @class, " " ), concat( " ", "views-field-losses", " " ))]').text | |
| @user.lol_rating = @lol_na_doc.xpath('//*[contains(concat( " ", @class, " " ), concat( " ", "views-field-rating", " " ))]').text | |
| end | |
| @user.save | |
| format.html { redirect_to @user, notice: 'User was successfully updated.' } | |
| format.json { head :no_content } | |
| else | |
| format.html { render action: "edit" } | |
| format.json { render json: @user.errors, status: :unprocessable_entity } | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment