A deadly simple Vue.js plugin to consume GitHub API.
- License:
- Source:
- See:
Methods
(static) get(uri, params, fillIn, errorCb)
Issue a GET request on 'https://api.github.com' with params and a variable to fill in
Parameters:
Name | Type | Description |
---|---|---|
uri |
String | The GitHub API uri to consume such as '/user/repos' |
params |
Object | A parameters object such as { 'project_id': 72 } |
fillIn |
Array | requestCallback | The Vue.js defined data to fill in with results from GitHub API, or a callback function fed with full response |
errorCb |
errorCallback | A callback function in case of error (response is passed to callback) |
- Source:
Example
// -------------------------------------------------
// 1- With an array to fill in a Vue.js defined data
// -------------------------------------------------
// from anywhere in the global Vue scope
Vue.GitHubAPI.get('/user/repos', {}, [this.myGitHubData, 'repositories'])
// from a .vue component
this.GitHubAPI.get('/user/repos', {}, [this.myGitHubData, 'repositories'])
// ----------------------------------------------------------
// 2- With a callback function to play with the full response
// ----------------------------------------------------------
// from anywhere in the global Vue scope
Vue.GitHubAPI.get('/user/repos', {}, (response) => {
console.log('got response:', response)
})
// from a .vue component
this.GitHubAPI.get('/user/repos', {}, (response) => {
console.log('got response:', response)
})
(static) post(uri, params, fillIn, errorCb)
Issue a POST request on 'https://api.github.com' with params and a variable to fill in
Parameters:
Name | Type | Description |
---|---|---|
uri |
String | The GitHub API uri to consume such as '/user/repos' |
params |
Object | A parameters object such as { 'project_id': 72 } |
fillIn |
Array | requestCallback | The Vue.js defined data to fill in with results from GitHub API, or a callback function fed with full response |
errorCb |
errorCallback | A callback function in case of error (response is passed to callback) |
- Source:
Example
// from anywhere in the global Vue scope
Vue.GitHubAPI.post('/repos/OWNER_NAME/REPO_NAME/issues', {
title: 'My new issues from vue-github-api'
}, (response) => { console.log('posted it!', response) })
// from a .vue component
this.GitHubAPI.post('/repos/OWNER_NAME/REPO_NAME/issues', {
title: 'My new issues from vue-github-api'
}, (response) => { console.log('posted it!', response) })
(static) registerStore(store)
Register your application Vuex store to improve it with GitHubAPI Vuex store module
Parameters:
Name | Type | Description |
---|---|---|
store |
Object | Your application Vuex store |
- Source:
Example
// from within a .vue component
this.GitHubAPI.registerStore(this.$store)
(static) setToken(newToken)
Set application wide GitHubAPI token value
Parameters:
Name | Type | Description |
---|---|---|
newToken |
String | The new token value |
- Source:
Example
// from anywhere in the global Vue scope
Vue.GitHubAPI.setToken('your user token')
// from a .vue component
this.GitHubAPI.setToken('your user token')