title: structuring simple external API calls with MVC in rails
body: <p>First time trying to create a simple web app with external API call, and I'm not sure how to structure it properly. Any tips with be greatly appreciated!</p>
  
  <p>Imagine there exists 5 players. Each player has a name. The API call will return the player ID given the name. I want to display them (for right now) on the show page.</p>
  
  <p>Player Controller Show</p>
  
  <pre><code>def show
          @player = Player.find(params[:id])
  
          api = RiotApi.new
          @info = api.get_summoner_id("randomplayer") #returns JSON format {"randomplayer" =&gt; {"id"=&gt;12345, ... } }  end
  </code></pre>
  
  <p>Player Show Page</p>
  
  <pre><code>some other code...
  &lt;%= @info["randomplayer"]["id"]%&gt;
  </code></pre>
  
  <p>Right now there are plenty of things wrong with it that I would like to fix.</p>
  
  <p>First is the API call exists within the show page. I believe the MVC structure propells me to add the API call in the model instead, but how do I call it back to the controller and the view? </p>
  
  <p>Second is I am hard coding how to get id itself. Although this is for testing purposes (just want to see I am actually on the right track), this does not utilize the Player class at all. Furthermore, @info entirely depends on what I define it as in the show action, which is definitely not what I want.</p>
  
  <p>How should I approach this?</p>