mirror of
https://github.com/samsonjs/gitter.git
synced 2026-04-27 15:07:41 +00:00
resolve name conflicts, update readme
This commit is contained in:
parent
3363be22e8
commit
58de0b9836
2 changed files with 15 additions and 23 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
gitter
|
gitter
|
||||||
======
|
======
|
||||||
|
|
||||||
A GitHub client inspired by pengwynn/octopussy.
|
A GitHub client inspired by [pengwynn/octopussy](/pengwynn/octopussy).
|
||||||
|
|
||||||
v2 API
|
v2 API
|
||||||
|
|
||||||
|
|
|
||||||
36
lib/index.js
36
lib/index.js
|
|
@ -68,7 +68,7 @@ module.exports = {
|
||||||
following: function(user, cb) {
|
following: function(user, cb) {
|
||||||
return new User(user).getFollowing(cb)
|
return new User(user).getFollowing(cb)
|
||||||
},
|
},
|
||||||
list: function(user, cb) {
|
repos: function(user, cb) {
|
||||||
return new User(user).getRepos(cb)
|
return new User(user).getRepos(cb)
|
||||||
},
|
},
|
||||||
watched: function(user, cb) {
|
watched: function(user, cb) {
|
||||||
|
|
@ -78,8 +78,8 @@ module.exports = {
|
||||||
|
|
||||||
// Define resources //
|
// Define resources //
|
||||||
|
|
||||||
Blob = createResource('blob/show/:repo/:sha/:path', {
|
Blob = createResource('blob/show/:repo/:tree/:path', {
|
||||||
has: [ ['commits', 'commits/list/:repo/:sha/:path'] ]
|
has: [ ['commits', 'commits/list/:repo/:tree/:path'] ]
|
||||||
})
|
})
|
||||||
Branch = createResource('commits/show/:repo/:branch', {
|
Branch = createResource('commits/show/:repo/:branch', {
|
||||||
has: [ ['commits', 'commits/list/:repo/:branch'] ]
|
has: [ ['commits', 'commits/list/:repo/:branch'] ]
|
||||||
|
|
@ -102,6 +102,11 @@ Tree = createResource('tree/show/:repo/:sha', {
|
||||||
, ['fullTree', 'tree/full/:repo/:sha']
|
, ['fullTree', 'tree/full/:repo/:sha']
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
Tree.prototype._processData = function(data) {
|
||||||
|
Resource.prototype._processData.call(this, data)
|
||||||
|
this.blobs = this.data()
|
||||||
|
}
|
||||||
|
|
||||||
User = createResource('user/show/:user', {
|
User = createResource('user/show/:user', {
|
||||||
has: [ 'followers'
|
has: [ 'followers'
|
||||||
, 'following'
|
, 'following'
|
||||||
|
|
@ -148,7 +153,8 @@ function createResource(route, options) {
|
||||||
return this._fetch({ prop: dataProp
|
return this._fetch({ prop: dataProp
|
||||||
, route: route || this._route + '/' + prop
|
, route: route || this._route + '/' + prop
|
||||||
, processData: function(d) {
|
, processData: function(d) {
|
||||||
getter(this, dataProp, function() { return camelize(unpack(d)) })
|
getter(this, dataProp, function() { return camelize(unpack(d)) },
|
||||||
|
{configurable: true})
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
, result: function(resource) { return resource[dataProp] }
|
, result: function(resource) { return resource[dataProp] }
|
||||||
}, cb.bind(this), force)
|
}, cb.bind(this), force)
|
||||||
|
|
@ -180,7 +186,7 @@ function Resource(/* ...args, opt: data or callback */) {
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
|
|
||||||
// set the resource path
|
// set the resource path
|
||||||
this.path = this.resolve(this._route)
|
this.urlPath = this.resolve(this._route)
|
||||||
|
|
||||||
if (typeof last === 'function') this.fetch(last)
|
if (typeof last === 'function') this.fetch(last)
|
||||||
else if (typeof last === 'object') this.data(last)
|
else if (typeof last === 'object') this.data(last)
|
||||||
|
|
@ -197,13 +203,9 @@ function Resource(/* ...args, opt: data or callback */) {
|
||||||
// Otherwise cached data is set to the data param.
|
// Otherwise cached data is set to the data param.
|
||||||
Resource.prototype.data = function(data) {
|
Resource.prototype.data = function(data) {
|
||||||
if (!data) return this._data
|
if (!data) return this._data
|
||||||
if (typeof data === 'string') return this._data && this._data[data]
|
if (typeof data === 'string' && typeof this._data === 'object') return this._data[data]
|
||||||
|
|
||||||
getter(this, '_data', function() { return data }, {configurable: true})
|
getter(this, '_data', function() { return data }, {configurable: true})
|
||||||
if (!this._propsDefined) {
|
|
||||||
getter(this, '_propsDefined', function() { return true })
|
|
||||||
dataProps(Object.getPrototypeOf(this), Object.keys(this._data))
|
|
||||||
}
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -213,7 +215,7 @@ Resource.prototype.data = function(data) {
|
||||||
// force: if true load data from github, bypassing the local cache
|
// force: if true load data from github, bypassing the local cache
|
||||||
Resource.prototype.fetch = function(cb, force) {
|
Resource.prototype.fetch = function(cb, force) {
|
||||||
return this._fetch({ prop: '_data'
|
return this._fetch({ prop: '_data'
|
||||||
, route: this.path
|
, route: this.urlPath
|
||||||
, processData: this._processData.bind(this)
|
, processData: this._processData.bind(this)
|
||||||
, result: function(resource) { return resource }
|
, result: function(resource) { return resource }
|
||||||
}, cb.bind(this), force)
|
}, cb.bind(this), force)
|
||||||
|
|
@ -292,7 +294,7 @@ function camel(s) { // created_at => createdAt
|
||||||
return s.replace(/_(.)/g, function(_, l) { return l.toUpperCase() })
|
return s.replace(/_(.)/g, function(_, l) { return l.toUpperCase() })
|
||||||
}
|
}
|
||||||
function camelize(obj) { // camelize all keys of an object, or all objects in an array
|
function camelize(obj) { // camelize all keys of an object, or all objects in an array
|
||||||
if (!obj) return obj
|
if (!obj || typeof obj === 'string') return obj
|
||||||
if (Array.isArray(obj)) return obj.map(camelize)
|
if (Array.isArray(obj)) return obj.map(camelize)
|
||||||
return Object.keys(obj).reduce(function(newObj, k) {
|
return Object.keys(obj).reduce(function(newObj, k) {
|
||||||
newObj[camel(k)] = obj[k]
|
newObj[camel(k)] = obj[k]
|
||||||
|
|
@ -323,16 +325,6 @@ function paramsFromRoute(route) {
|
||||||
.map(function(s) { return s.slice(1) })
|
.map(function(s) { return s.slice(1) })
|
||||||
}
|
}
|
||||||
|
|
||||||
// define getters for a list of data properties
|
|
||||||
function dataProps(obj, keys) {
|
|
||||||
keys.forEach(function(key) {
|
|
||||||
if (obj.hasOwnProperty(key))
|
|
||||||
console.warn('property "' + key + '" already exists, skipping')
|
|
||||||
else
|
|
||||||
getter(obj, key, function() { return this.data(key) }, {enumerable: true})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function slice(x) { return [].slice.call(x) }
|
function slice(x) { return [].slice.call(x) }
|
||||||
|
|
||||||
function titleCaseFirst(s) { return s.charAt(0).toUpperCase() + s.slice(1) }
|
function titleCaseFirst(s) { return s.charAt(0).toUpperCase() + s.slice(1) }
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue