resolve name conflicts, update readme

This commit is contained in:
Sami Samhuri 2010-11-07 21:59:33 -08:00
parent 3363be22e8
commit 58de0b9836
2 changed files with 15 additions and 23 deletions

View file

@ -1,7 +1,7 @@
gitter
======
A GitHub client inspired by pengwynn/octopussy.
A GitHub client inspired by [pengwynn/octopussy](/pengwynn/octopussy).
v2 API

View file

@ -68,7 +68,7 @@ module.exports = {
following: function(user, cb) {
return new User(user).getFollowing(cb)
},
list: function(user, cb) {
repos: function(user, cb) {
return new User(user).getRepos(cb)
},
watched: function(user, cb) {
@ -78,8 +78,8 @@ module.exports = {
// Define resources //
Blob = createResource('blob/show/:repo/:sha/:path', {
has: [ ['commits', 'commits/list/:repo/:sha/:path'] ]
Blob = createResource('blob/show/:repo/:tree/:path', {
has: [ ['commits', 'commits/list/:repo/:tree/:path'] ]
})
Branch = createResource('commits/show/:repo/:branch', {
has: [ ['commits', 'commits/list/:repo/:branch'] ]
@ -102,6 +102,11 @@ Tree = createResource('tree/show/: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', {
has: [ 'followers'
, 'following'
@ -148,7 +153,8 @@ function createResource(route, options) {
return this._fetch({ prop: dataProp
, route: route || this._route + '/' + prop
, processData: function(d) {
getter(this, dataProp, function() { return camelize(unpack(d)) })
getter(this, dataProp, function() { return camelize(unpack(d)) },
{configurable: true})
}.bind(this)
, result: function(resource) { return resource[dataProp] }
}, cb.bind(this), force)
@ -180,7 +186,7 @@ function Resource(/* ...args, opt: data or callback */) {
}.bind(this))
// set the resource path
this.path = this.resolve(this._route)
this.urlPath = this.resolve(this._route)
if (typeof last === 'function') this.fetch(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.
Resource.prototype.data = function(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})
if (!this._propsDefined) {
getter(this, '_propsDefined', function() { return true })
dataProps(Object.getPrototypeOf(this), Object.keys(this._data))
}
return this
}
@ -213,7 +215,7 @@ Resource.prototype.data = function(data) {
// force: if true load data from github, bypassing the local cache
Resource.prototype.fetch = function(cb, force) {
return this._fetch({ prop: '_data'
, route: this.path
, route: this.urlPath
, processData: this._processData.bind(this)
, result: function(resource) { return resource }
}, cb.bind(this), force)
@ -292,7 +294,7 @@ function camel(s) { // created_at => createdAt
return s.replace(/_(.)/g, function(_, l) { return l.toUpperCase() })
}
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)
return Object.keys(obj).reduce(function(newObj, k) {
newObj[camel(k)] = obj[k]
@ -323,16 +325,6 @@ function paramsFromRoute(route) {
.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 titleCaseFirst(s) { return s.charAt(0).toUpperCase() + s.slice(1) }