npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-gitlab-api

v0.1.8

Published

A deadly simple Vue.js plugin to consume GitLab API.

Downloads

12

Readme

vue-gitlab-api

A deadly simple Vue.js plugin to consume GitLab API.

Head to the extensive JSDoc API documentation for vue-gitlab-api, or keep on reading for an easy process to integrate it in your application.

Using it

Install and import

npm install vue-gitlab-api

In your main application JS file (typically main.js if you are using vue-cli webpack template), simply use the plugin:

// vue-resource is needed too
import VueResource from 'vue-resource'
Vue.use(VueResource)

// import vue-gitlab-api
import GitLabAPI from 'vue-gitlab-api'
Vue.use(GitLabAPI, { url: 'https://gitlab.com', token: 'user Private Token or Personal Access Token' })

You can configure application wide options while Vue.use'ing this plugin:

| Name | Description | |---------|---------------------------------------------------------------------------------------| | url | your GitLab instance URL (defaults to https://gitlab.com) | | token | your GitLab user Private Token or Personal Access Token use to connect to the API |

Consume GitLab API

From anywhere now, you can simply consume GitLab API:

Vue.GitLabAPI.get('/projects', {}, [this.myGitLabData, 'projects'])

You can also use it in your .vue components with this.GitLabAPI:

this.GitLabAPI.get('/projects', {}, [this.myGitLabData, 'projects'])

That was it! Now that you are bootstrapped in, have a look at all the methods available to you in the extensive JSDoc API documentation available on these auto-generated GitLab Pages.

Important: if you want your filled-in property this.myGitLabData.projects to be reactive "the Vue.js way", you MUST define this variable as a data in your components or vues, with a default value of an empty object (read myGitLabData: {}). See how to do it on a vue component on this example:

<template>
  <div>
    <p>Projects grabbed: {{ projectsCount }}</p>
  </div>
</template>

<script>
export default {
  data () {
    return {
      myGitLabData: {}
    }
  },
  mounted: function () {
    this.GitLabAPI.get('projects', {}, [this.myGitLabData, 'projects'])
  },
  computed: {
    projectsCount: function () {
      if (this.myGitLabData.projects) {
        return this.myGitLabData.projects.length
      }
      return 'none yet...'
    }
  }
}
</script>

This is due to the fact Vue does not allow to add new reactive properties dynamically. Read more about it on the awesome Vue.js guide.

During your application workflow, you could want to change GitLab instance URL, and/or user authentication token. These methods will let you do it easily:

// set application wide GitLabAPI url value
this.GitLabAPI.setUrl('https://your.gitlab-instance.com')

// set application wide GitLabAPI token value
this.GitLabAPI.setToken('other user Private Token or Personal Access Token')

Vuex store module

Using Vuex? You can attach vue-gitlab-api Vuex module to your application store. Within one of your .vue components, simply register it before you using it from your application:

// registers GitLabAPI Vuex module to your application Vuex store
this.GitLabAPI.registerStore(this.$store)

// you are now able to read this state
this.$store.state.GitLabAPI.downloading

Here are Vuex states provided by vue-gitlab-api to your application:

| Vuex state | Type | Description | |---------------|---------|----------------------------------------------------| | downloading | Boolean | Defines if vue-gitlab-api is currently downloading | | running | Number | Count vue-gitlab-api requests running now |

Have a look at Vuex for more details, or read on this complete example:

import Vue from 'vue'

// your application is using Vuex
import Vuex from 'vuex'
Vue.use(Vuex)

// remember vue-resource is needed for vue-gitlab-api
import VueResource from 'vue-resource'
Vue.use(VueResource)

// using vue-gitlab-api
import GitLabAPI from 'vue-gitlab-api'
Vue.use(GitLabAPI, { url: 'https://gitlab.com', token: 'user Private Token' })

// declare your Vuex store
const store = new Vuex.Store({})

// this is your application
const app = new Vue({
  el: '#app',
  mounted: {
    // register GitLabAPI Vuex store!
    this.GitLabAPI.registerStore(store)
  },
  computed: {
    // with this computed property, do something insanely simple such as:
    // <p v-if="downloading">Downloading from GitLab...</p>
    downloading: function () {
      if (typeof store.state.GitLabAPI !== 'undefined') {
        return store.state.GitLabAPI.downloading
      } else {
        return false
      }
    }
  }
})

Contributing

Initial scaffolding was done with vue-cli webpack template. For detailed explanation on how things work, checkout the guide and docs for vue-loader.

Simply said, one can start working on its own customized version of vue-gitlab-api in no time:

# install dependencies
npm install

# run unit tests
npm run unit

# build JSDoc API documentation (defaults to the ./out folder)
./node_modules/.bin/jsdoc src/GitLabAPI.js

# serve with hot reload at localhost:8080
npm run dev

What's next?

Without any obligation nor due date, one could expect to be done this non-exhaustive list of improvements grouped on issues labeled Feature.

You can read on the Changelog too, for historical and upcoming new features, changes, deprecations, removed features, bug and security fixes.

Support

Your are free to open an issue right in this GitLab repository whether you should be facing a problem or a bug. Please advise this is not a commercial product, so one could experience random response time. Positive, friendly and productive conversations are expected on the issues. Screenshots and steps to reproduce are highly appreciated. Chances are you may get your issue solved if you follow these simple guidelines.

Credits

License

The vue-gitlab-api plugin is distributed under the MIT License (MIT). Please have a look at the dependencies licenses if you plan on using, building, or distributing this plugin.