jvcalderon / gist-client

A client to consume Gist API with JS
MIT License
9 stars 0 forks source link

"Uncaught Error: You need to set token before by setToken() method" for public gist #9

Open pozabil opened 2 years ago

pozabil commented 2 years ago

Hello! Related to jvcalderon/gist-client#1, I'm trying to get one gist by id in my rails application

document.addEventListener('turbolinks:load', function() {
    if ($('.gist-link')) {
        let GistClient = require("gist-client")
        let gistClient = new GistClient()

        $('.gist-link').each(function() {
            let gistId = $(this).attr('href').split('/').pop()

            console.log(gistId)

            gistClient.getOneById(gistId)
                .then(response => {
                    console.log('RESPONSE')
                    console.log(response)
                }).catch(err => {
                    console.log('ERROR')
                    console.log(err)
                })
        })
    }
})

but i get error Uncaught Error: You need to set token before by setToken() method

I checked source code of lib, and find next lines in gist-client/lib/gistClient.js:

    this.getOneById = (gistId) => {
        _checkToken()
        return request(_getBaseConfiguredResource(API_DOMAIN + `/gists/${gistId}`))
            .then(res => { return res.data })
    }

getOneById function check token every time, when i try to get gist by id. I think this is a bug, right?

Best Regards!

romatoom commented 1 year ago

@pozabil I have the same problem. Have you solved it?

pozabil commented 1 year ago

@romatoom

No, I just decided to use another library ( https://github.com/k33g/gh3 ), but install latest version from git master using bower dependencies.

But u can use this library, just downoad source code, and modified issued file.