Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save marklocklear/4b79d7a0195b02db6decfa6256fde089 to your computer and use it in GitHub Desktop.
Save marklocklear/4b79d7a0195b02db6decfa6256fde089 to your computer and use it in GitHub Desktop.
Rails iTunes Search
#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