Created
April 30, 2018 15:51
-
-
Save marklocklear/4b79d7a0195b02db6decfa6256fde089 to your computer and use it in GitHub Desktop.
Rails iTunes Search
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
#model | |
class Coursera | |
include HTTParty | |
def self.for term | |
HTTParty.get("http://itunes.apple.com/search", | |
{query: {term: term}, format: :json}) | |
end | |
end | |
#controller | |
class CoursesController < ApplicationController | |
def index | |
@search_term = "poison" | |
@response = Coursera.for(@search_term) | |
end | |
end | |
#view | |
<h1>Searching for <%= @search_term %></h1> | |
<table border="1"> | |
<tr> | |
<th>Band</th> | |
<th>Track Name</th> | |
<th>Release Date</th> | |
</tr> | |
<% @response['results'].each do |r| %> | |
<tr> | |
<td><%= r["artistName"] %></td> | |
<td><%= r["trackName"] %></td> | |
<td><%= r["releaseDate"] %></td> | |
</tr> | |
<% end %> | |
</table> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment