{"size": 1102, "ext": "js", "max_stars_repo_path": "src/api.js", "max_stars_repo_name": "crdx/sheet-storage", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/api.js", "max_issues_repo_name": "crdx/sheet-storage", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/api.js", "max_forks_repo_name": "crdx/sheet-storage", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.0454545455, "max_line_length": 59, "alphanum_fraction": 0.4773139746}
let google = require('googleapis');

module.exports = class {
    constructor(creds, sheetId) {
        this.creds = creds
        this.sheetId = sheetId
        this.sheets = google.sheets('v4')
    }

    buildConfig(range) {
        return {
            auth: this.creds,
            spreadsheetId: this.sheetId,
            range: range
        }
    }

    set(range, rows) {
        return new Promise((resolve, reject) => {
            let config = this.buildConfig(range)
            config.valueInputOption = 'USER_ENTERED'
            config.resource = { values: rows }

            this.sheets.spreadsheets.values.update(
                config,
                function(err, res) {
                    err ? reject(err) : resolve(res)
                }
            )
        })
    }

    get(range) {
        return new Promise((resolve, reject) => {
            this.sheets.spreadsheets.values.get(
                this.buildConfig(range),
                function(err, res) {
                    err ? reject(err) : resolve(res.values)
                }
            )
        })
    }
}
