Sha256: 503fb98b9fdb352ecc564a4dec64af7bd83a1f603ad52e9c28983860a4268d4e

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

class Music::YearInReviewsController < ApplicationController
  before_filter :show_breadcrumbs
  
  def index
    begin
      @year_in_reviews = JSON.parse(
        HTTParty.get("#{Volontariat::HOSTS[Rails.env.to_s.to_sym]}/api/v1/users/#{Volontariat::USER_ID}/library/music/year_in_reviews.json?page=#{params[:page]}").body
      )
    rescue JSON::ParserError
    end
    
    if @year_in_reviews.nil?
      flash[:alert] = I18n.t('general.volontariat.request_failed')
      @year_in_reviews = { 'entries' => [] }
    else
      @pagination = HomePage::PaginationMetadata.new(@year_in_reviews)
    end
  end
  
  def show
    begin
      @year_in_review = JSON.parse(
        HTTParty.get("#{Volontariat::HOSTS[Rails.env.to_s.to_sym]}/api/v1/users/#{Volontariat::USER_ID}/library/music/year_in_reviews/#{params[:id]}.json").body
      )
    rescue JSON::ParserError
    end
    
    raise ActiveRecord::RecordNotFound if @year_in_review.nil?
  end
  
  def top_albums
    @year_in_review = { 'year' => params[:id] }
    
    begin
      @albums = JSON.parse(
        HTTParty.get("#{Volontariat::HOSTS[Rails.env.to_s.to_sym]}/api/v1/users/#{Volontariat::USER_ID}/library/music/year_in_reviews/#{params[:id]}/top_releases.json").body
      )
    rescue JSON::ParserError
    end
    
    raise ActiveRecord::RecordNotFound if @albums.nil?
  end
  
  def top_songs
    @year_in_review = { 'year' => params[:id] }
    
    begin
      @songs = JSON.parse(
        HTTParty.get("#{Volontariat::HOSTS[Rails.env.to_s.to_sym]}/api/v1/users/#{Volontariat::USER_ID}/library/music/year_in_reviews/#{params[:id]}/top_tracks.json").body
      )
    rescue JSON::ParserError
    end
    
    raise ActiveRecord::RecordNotFound if @songs.nil?
  end
  
  def resource
    @year_in_review
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
home_page_music-0.0.1 app/controllers/music/year_in_reviews_controller.rb