Created
March 4, 2011 21:28
-
-
Save flockonus/855734 to your computer and use it in GitHub Desktop.
Feito com base em nifty_scaffold
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
class Admin::BulkiesController < ApplicationController | |
#layout 'admin' | |
#before_filter :admin_area | |
def index | |
return redirect_to '/admin/bulkies/auto/add_stores' | |
end | |
# Here the user gets a list of his spreadsheets from his GoogleDocs, if auth | |
def add_stores | |
unless session[:gdocs_sheet_auth] | |
flash[:notice] = "Login Requerido" | |
return redirect_to( {:action => 'new', :return_to =>"add_stores"} ) | |
end | |
@pairs = [] | |
session[:gdocs_sheet_auth].spreadsheets.each do |ss| | |
( @pairs << [ss.title, ss.key] ) rescue 0 | |
end | |
end | |
# expects a :key and :title as param, retrive that sheet using Auth & validate, persist, mark | |
def add_stores1 | |
@resp = Admin::Bulky.import_restaurants( session[:gdocs_sheet_auth].spreadsheet_by_key(params[:key]).worksheets[0] ) | |
if @resp.is_a?( String ) | |
flash[:error] = ("Falha. #{@resp}").gsub(?\n.chr, '<br/>').html_safe | |
elsif @resp.is_a?( Hash ) | |
flash[:notice] = "Sucesso! Importação completa." | |
end | |
end | |
# /LOGIN AUTH/ | |
def new | |
#return render :text => "bull2" | |
end | |
def create | |
begin | |
@auth = GoogleSpreadsheet.login(params[:email], params[:senha]) | |
rescue Exception => e | |
e | |
end | |
if @auth | |
session[:gdocs_sheet_auth] = @auth | |
flash[:notice] = "Login efetuado com sucesso no Google Docs" | |
return redirect_to( "/admin/bulkies/auto/#{params[:return_to]}" ) | |
else | |
flash[:notice] = "Falha na autenticação, tente novamente." | |
return redirect_to( { :action => :new, :return_to => params[:return_to] } ) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment