{"size": 1188, "ext": "js", "max_stars_repo_path": "src/api_server/sources/eventbrite/base.js", "max_stars_repo_name": "goldenking0412/conexdispatch-api-server", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/api_server/sources/eventbrite/base.js", "max_issues_repo_name": "goldenking0412/conexdispatch-api-server", "max_issues_repo_issues_event_min_datetime": "2018-12-14T03:19:23.000Z", "max_issues_repo_issues_event_max_datetime": "2019-11-14T20:08:15.000Z", "max_forks_repo_path": "src/api_server/sources/eventbrite/base.js", "max_forks_repo_name": "goldenking0412/conexdispatch-api-server", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 57, "max_forks_count": null, "avg_line_length": 22.8461538462, "max_line_length": 68, "alphanum_fraction": 0.585016835}
/*!
 * kin
 * Copyright(c) 2016-2017 Benoit Person
 * Apache 2.0 Licensed
 */

const KinRequest = require("../kin_request");

const _ = require("lodash");

const EVENTBRITE_API_BASE_URL = "https://www.eventbriteapi.com/v3/";
const EVENTBRITE_API_TIMEOUT = 8 * 1000;

class EventbriteRequest extends KinRequest {
    constructor(req, source_id) {
        super(req, source_id, EVENTBRITE_API_BASE_URL);
    }

    get source_name() {
        return "eventbrite";
    }

    is_invalid_creds_error(err) {
        const eventbrite_error = _.get(err, "error");
        if (!_.isEmpty(eventbrite_error)) {
            // TODO: check on `error` status string as well?
            return eventbrite_error.status_code === 401;
        }
        return false;
    }

    api_request_options(access_token, overrides) {
        return _.merge(
            {
                headers: {
                    Authorization: `Bearer ${access_token}`
                },
                json: true,
                timeout: EVENTBRITE_API_TIMEOUT
            },
            overrides
        );
    }
}

module.exports = {
    EVENTBRITE_API_BASE_URL,
    EVENTBRITE_API_TIMEOUT,

    EventbriteRequest
};
