Ember Data abstraction for the GitHub REST API v3.
ember install ember-data-github
You need to choose how you wish to authenticate your GitHub requests using OAuth. ember-data-github
provides a simpleand direct mechanism that is specific to itself. Alternatively, you can use a more general authentication framework likeember-simple-auth
.
If you already have a token to use the OAuth endpoints, such as a Personal access token, you must set the propertynamed githubAccessToken
on github-session
service with the currently logged in user's GitHub access token.
ember-simple-auth
If you are using ember-simple-auth (ESA) to authenticate, perhaps withtorii and ESA's torii-provider
, you can authenticate by creating a githubauthorizer and extending ember-data-github
's adapter for each model you use. See the respective addon docs andGitHub'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'
});
this.get('store').findRecord('github-user', '#');
this.get('store').findRecord('github-user', 'jimmay5469'); // get a user by user login
this.get('store').findRecord('github-user', 917672); // get a user by user id
this.get('store').findRecord('github-repository', 'jimmay5469/old-hash'); // get a repository by repository name
this.get('store').findRecord('github-repository', 34598603); // get a repository by repository id
this.get('store').query('github-repository', { user: 'elwayman02' }); // get repositories owned by user
this.get('store').query('github-repository', { user: 'elwayman02', type: 'all' }); // get all repositories for user
this.get('store').query('github-repository', { user: 'elwayman02', sort: 'updated', direction: 'asc' }); // get repositories owned by user sorted by last updated, ascending
Note: At this time we only support getting file contents.
this.get('store').queryRecord('github-repository-contents', { repo: 'jmar910/test-repo-yay', file: 'app.json' }); // get file contents from repo
this.get('store').query('github-branch', { repo: 'jimmay5469/old-hash' });
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-release', { repo: 'jimmay5469/old-hash' });
this.get('store').queryRecord('github-release', { repo: 'jimmay5469/old-hash', releaseId: 1 });
this.get('store').queryRecord('github-compare', { repo: 'jimmay5469/old-hash', base: '1234', head: '5678' });
this.get('store').query('github-pull', { repo: 'jimmay5469/old-hash' });
this.get('store').queryRecord('github-pull', { repo: 'jimmay5469/old-hash', pullId: 1 });
this.get('store').findRecord('github-organization', { org: 'my-org' });
this.get('store').query('github-members', { org: 'my-org' })
this.get('store').queryRecord('github-blob', { repo: 'jimmay5469/old-hash', sha: '47c5438403ca875f170db2aa07d1bfa3689406e3' });
this.get('store').queryRecord('github-tree', { repo: 'jimmay5469/old-hash', sha: '47c5438403ca875f170db2aa07d1bfa3689406e3' });
This addon uses ember-cli-mirage in its tests. It is often beneficial for consuming apps to be able to re-use the factories and models defined in mirage, so if you would like to use these in your tests you can add the mirage-support
object to your ember-cli-build.js
file:
module.exports = function(defaults) {
let app = new EmberApp(defaults, {
...
'mirage-support': {
includeAll: true
}
...
});
return app.toTree();
};
As long as ember-cli-mirage
is not disabled, the files in this addon's mirage-support
directory will be merged with the consuming app's namespace, and be made available to that mirage context.The 'mirage-support'
key has 3 options:
Key | Type | Description |
---|---|---|
includeAll |
Boolean |
If true , includes the full mirage-support tree, i.e. no-brainer just use it all. |
exclude |
{Array of GlobStrings,RegExps,Functions } |
This value gets passed directly to broccoli-funnel , only if includeAll is specified. Allows for excluding certain files from import. |
include |
{Array of GlobStrings,RegExps,Functions } |
Passed dirctly to broccoli-funnel . Allows to pick only certain files to be imported into app namespace. |
git clone git@github.com:elwayman02/ember-data-github.git
cd ember-data-github
yarn
ember serve
ember test
– Runs the test suite on the current Ember versionember test --server
– Runs the test suite in "watch mode"ember try:each
– Runs the test suite against multiple Ember versionsember build
For more information on using ember-cli, visit https://ember-cli.com/.
写在前面 最近比较忙,换了新工作还要学习很多全新的技术栈,并给自己找了很多借口来不去坚持写博客。常常具有讽刺意味的是,更多剩下的时间并没有利用而更多的是白白浪费,也许这就是青春吧,挥霍吧,这不是我想要的,既然这样,我还要继续写下去,坚持把博客做好,争取进前100博客,在此谨记。
在Ember应用中,序列化器会格式化与后台交互的数据,包括发送和接收的数据。默认情况下会使用JSON API序列化数据。如果你的后端使用不同的格式,Ember Data允许你自定义序列化器或者定义一个完全不同的序列化器。 Ember Data内置了三个序列化器。JSONAPISerializer是默认的序列化器,用与处理后端的JSON API。JSONSerialize
<!DOCTYPE html> <html> <head> <meta name="description" content="ED: Reading" /> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/handlebar
ember-data-tasks An alternative Ember Data store that returns Ember Concurrency tasks instead of promises. Install ember install ember-data-tasks This addon comes in three phases: Phase 1: Store Overr
ember-data-contentful This is an Ember Data adapter/serializer that uses the READ ONLY Content Delivery API from contentful Setup in your app ember install ember-data-contentful After installing the a
Ember Data Copyable Intelligently copy an Ember Data model and all of its relationships Features Shallow & deep copy an Ember Data model Shallow & deep copy model relationships Handles cyclical relati
目前,我们的应用程序使用硬编码的数据作为租赁列表中定义的rentals路由处理程序。随着应用程序的发展,我们希望在服务器上保留我们的租用数据,并且更容易地对数据进行高级操作,如查询。 Ember提供了一个名为Ember Data的数据管理的库来帮助处理持久的应用程序数据。 Ember Data要求你通过扩展DS.Model来定义要提供给应用程序的数据的结构。 可以使用Ember CLI生成Embe
ember-data-url-templates ember-data-url-templates is an addon to allow building urls with url templates instead ofdefining buildURL as described in RFC #4. ember-data-url-templates is under early deve
Ember检查器是一个浏览器插件,用于调试Ember应用程序。 灰烬检查员包括以下主题 - S.No. 灰烬检查员方式和描述 1 安装Inspector 您可以安装Ember检查器来调试您的应用程序。 2 Object Inspector Ember检查器允许与Ember对象进行交互。 3 The View Tree 视图树提供应用程序的当前状态。 4 检查路由,数据选项卡和库信息 您可以看到检查