Code Monkey home page Code Monkey logo

ember-data-github's Introduction

Ember Data Github

Build Status Ember Observer Score Code Climate

Ember Data abstraction for the GitHub API.

Installation

ember install ember-data-github

Usage

You need to choose how you wish to authenticate your GitHub requests using OAuth. ember-data-github provides a simple and direct mechanism that is specific to itself. Alternatively, you can use a more general authentication framework like ember-simple-auth.

Authenticating Directly

If you already have a token to use the OAuth endpoints, such as a Personal access token, you must set the property named githubAccessToken on github-session service with the currently logged in user's GitHub access token.

Authenticating with ember-simple-auth

If you are using ember-simple-auth (ESA) to authenticate, perhaps with torii and ESA's torii-provider, you can authenticate by creating a github authorizer and extending ember-data-github's adapter for each model you use. See the respective addon docs and GitHub's OAuth docs to set it up.

Once you have a token, the authorizer will look like

// app/authorizers/github.js

import { inject as service } from '@ember/service';
import { isEmpty } from '@ember/utils';
import Base from 'ember-simple-auth/authorizers/base';

export default Base.extend({
  session: service(),
  authorize(sessionData, block) {
    if (this.get('session.isAuthenticated') && !isEmpty(sessionData.access_token)) {
      block('Authorization', `token ${sessionData.access_token}`);
    }
  }
});

assuming access_token is the name of the property containing the token. This automatically injects the Authorization header into the API requests using ESA mechanisms.

An extended adapter for github-user would look like

// app/adapters/github-user.js

import GitHubUserAdapter from 'ember-data-github/adapters/github-user';
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';

export default GitHubUserAdapter.extend(DataAdapterMixin, {
  authorizer: 'authorizer:github'
});

Retrieving GitHub Data

The following examples show how to retrieve each supported GitHub entity as you might use it in your model hook.

this.get('store').findRecord('github-user', '#'); // get the current user
this.get('store').findRecord('github-user', 'jimmay5469'); // get a user
this.get('store').findRecord('github-repository', 'jimmay5469/old-hash'); // get a repository
this.get('store').findRecord('github-branch', 'jimmay5469/old-hash/branches/master'); // get a branch
this.get('store').queryRecord('github-branch', { repo: 'jimmay5469/old-hash', branch: 'master' }); // get a specific branch
this.get('store').query('github-branch', { repo: 'jimmay5469/old-hash' }); // get a repo's branches
this.get('store').queryRecord('github-release', { repo: 'jimmay5469/old-hash', releaseId: 1 }); // get a specific release
this.get('store').query('github-release', { repo: 'jimmay5469/old-hash' }); // get a repo's releases
this.get('store').queryRecord('github-blob', { repo: 'jimmay5469/old-hash', sha: '47c5438403ca875f170db2aa07d1bfa3689406e3' }); // get a file's contents

Contributing

Installation

  • git clone [email protected]:elwayman02/ember-data-github.git
  • cd ember-data-github
  • yarn
  • bower install

Running

Running Tests

  • npm test (Runs ember try:each to test your addon against multiple Ember versions)
  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit https://ember-cli.com/.

ember-data-github's People

Contributors

alexander-alvarez avatar appleton avatar catchamonkey avatar dhaulagiri avatar elwayman02 avatar ember-tomster avatar greenkeeper[bot] avatar greenkeeperio-bot avatar jimmay5469 avatar jrock2004 avatar nainterceptor avatar sivakumar-kailasam avatar srvance avatar topaxi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.