{"size": 1007, "ext": "js", "max_stars_repo_path": "pages/api/get-promo.js", "max_stars_repo_name": "gabscar/palpite-box", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pages/api/get-promo.js", "max_issues_repo_name": "gabscar/palpite-box", "max_issues_repo_issues_event_min_datetime": "2021-05-11T19:13:56.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-09T01:41:50.000Z", "max_forks_repo_path": "pages/api/get-promo.js", "max_forks_repo_name": "gabscar/palpite-box", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 25.8205128205, "max_line_length": 62, "alphanum_fraction": 0.5521350546}

//pelo next pode usar o import
import {GoogleSpreadsheet} from 'google-spreadsheet'


//const { GoogleSpreadsheet } = require('google-spreadsheet')
//const credentials = require('../../credentials.json')


const doc = new GoogleSpreadsheet(process.env.DOC_ID)

export default async(req,res) =>{

    try{
        await doc.useServiceAccountAuth({
            client_email: process.env.SHEET_CLIENT,
            private_key: process.env.SHEET_KEY
        })
        await doc.loadInfo()
        
        const sheet = doc.sheetsByIndex[1]
        await sheet.loadCells('A3:B3')
       
        const celpromo = sheet.getCell(2 ,0)       
        const celltexto = sheet.getCell(2,1)
        

        res.end(JSON.stringify({
            showCupon : celpromo.value === 'VERDADEIRO',
            message : celltexto.value
        }))
    }catch(err){
        res.end(JSON.stringify({
            showCupon : false,
            message :    ''    
       }))
    }
    
}