class Www::ApplicativesController < WwwController

  #before_filter :show_landing, only: [:index]
  require 'feedzirra'

  def index
    @first_rounded_link = www_page_path(Page.find(9))
    @secod_rounded_link = Page.find(17).link
    @third_rounded_link = new_www_information_request_path
    @transparency = Page.find(6)
    #@tweet = Twitter.user_timeline("GobAbiertoSV").first rescue nil
    begin
      news_feed = Feedzirra::Feed.fetch_and_parse('http://www.transparenciaactiva.gob.sv/articles')
      @news_entries = news_feed.entries.slice(0, 3)
    rescue
      @news_entries = []
    end

    #render layout: false
  end

  def subscribe
    render layout: false
  end

  protected
    def show_landing
      cookies[:yo_reporto] ||= Time.current
      begin
        if (Time.current - Time.zone.parse(cookies[:yo_reporto])) > 3600
          cookies[:yo_reporto] = Time.current
          redirect_to yo_reporto_www_applicatives_url and return
        end
      rescue
        redirect_to yo_reporto_www_applicatives_url and return
      end
    end

  private
    def certified_page
      @certified_page ||= Page.find(Config[:www][:certified_page_id])
    end
    helper_method :certified_page

end
