Skip to content

Commit c99121b

Browse files
author
Dean Hudson
committed
Move the JS SDK here so we can open source it w/o affecting the docs
0 parents  commit c99121b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+16894
-0
lines changed

jsdoc-conf.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"opts": {
3+
"lenient": true,
4+
"destination": "./www/docs/",
5+
"recurse": true
6+
},
7+
"tags": {
8+
"allowUnknownTags": true
9+
},
10+
"source": {
11+
"include": "./www/app",
12+
"includePattern": ".+\\.js(doc)?$",
13+
"excludePattern": "(^|\\/|\\\\)_"
14+
},
15+
"plugins": ["plugins/markdown"]
16+
}

www-built/app.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
requirejs.config({
2+
baseUrl: "lib",
3+
paths: {
4+
app: "../app"
5+
}
6+
});;

www-built/app/all.js

+4,269
Large diffs are not rendered by default.

www-built/app/api.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
define([ "require", "jquery", "underscore", "./util", "./initialize" ], function(require) {
2+
var $ = require("jquery"), _ = require("underscore"), util = require("./util"), prop = util.getProperty, root = this, OA_API = function(api) {
3+
var cfg = prop(root, "OA.config") || require("./initialize")();
4+
function prep(endpoint, params, callback, errback, method) {
5+
return {
6+
timeout: 5e4,
7+
type: typeof method == "undefined" ? "GET" : method,
8+
data: params,
9+
success: function(data, textStatus, jqXHR) {
10+
callback(textStatus, data);
11+
},
12+
error: function(jqXHR, textStatus, errorThrown) {
13+
callback(textStatus, !1);
14+
}
15+
};
16+
}
17+
function key(type) {
18+
return type == "stream" ? cfg().stream_key : cfg().info_key;
19+
}
20+
return api.setConfig = function(conf) {
21+
cfg = conf;
22+
23+
}, api.config = function() {
24+
return _.clone(cfg());
25+
}, api.streamRequest = function(endpoint, params, callback, method) {
26+
var api_call = prep(endpoint, params, callback, method), config = cfg();
27+
return api_call.data.limit = config.max_particles, api_call.data.api_key = key("stream"), api_call.url = config.base_api_url + "/stream/" + endpoint + "?callback=?", $.ajax(api_call);
28+
}, api.infoRequest = function(endpoint, params, callback, method) {
29+
var api_call = prep(endpoint, params, callback, method);
30+
return api_call.data.api_key = key("info"), api_call.url = cfg().base_api_url + "/info/" + endpoint, $.ajax(api_call);
31+
}, api.sourceRequest = function(endpoint, params, callback, method) {
32+
var api_call = prep(endpoint, params, callback, method);
33+
return api_call.data.api_key = key("info"), api_call.url = cfg().base_api_url + "/source/" + endpoint, $.ajax(api_call);
34+
}, api.searchRequest =
35+
function(endpoint, params, callback, method) {
36+
var api_call = prep(endpoint, params, callback, method);
37+
return api_call.data.api_key = key("info"), api_call.url = cfg().base_api_url + "/search/" + endpoint, $.ajax(api_call);
38+
}, api;
39+
}(OA_API || {});
40+
return OA_API;
41+
});;

www-built/app/artistInfo.js

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
define([ "require", "jquery", "underscore", "./util", "./api", "./mediaCollection" ], function(require) {
2+
var $ = require("jquery"), _ = require("underscore"), util = require("./util"), prop = util.getProperty, api = require("./api"), MediaCollection = require("./mediaCollection");
3+
function ArtistInfo(data) {
4+
this._data = Object.freeze({
5+
oaArtistId: prop(data, "oa_artist_id"),
6+
name: prop(data, "name"),
7+
bio: prop(data, "bio.media.0.data.text") || prop(data, "bio.text"),
8+
coverPhoto: new MediaCollection(prop(data, "cover_photo.0.media")),
9+
factCard: prop(data, "fact_card.media.0.data"),
10+
profilePhoto: new MediaCollection(prop(data, "profile_photo.media")),
11+
styleTags: prop(data, "tags.media.0.data.tags")
12+
});
13+
}
14+
return ArtistInfo.prototype = {
15+
oaArtistId: function() {
16+
return this._data.oaArtistId;
17+
},
18+
name: function() {
19+
return this._data
20+
.name;
21+
},
22+
bio: function() {
23+
return this._data.bio;
24+
},
25+
coverPhoto: function() {
26+
return this._data.coverPhoto;
27+
},
28+
factCard: function() {
29+
return this._data.factCard;
30+
},
31+
profilePhoto: function() {
32+
return this._data.profilePhoto;
33+
},
34+
styleTags: function() {
35+
return this._data.styleTags;
36+
},
37+
asObject: function() {
38+
return {
39+
oaArtistId: this.oaArtistId(),
40+
name: this.name(),
41+
bio: this.bio(),
42+
coverPhoto: this.coverPhoto(),
43+
factCard: this.factCard(),
44+
profilePhoto: this.profilePhoto(),
45+
styleTags: this.styleTags()
46+
};
47+
}
48+
}, ArtistInfo.api = function() {
49+
return api;
50+
}, ArtistInfo.fetchByOaArtistId = function(id, cb) {
51+
return api.infoRequest("artists/" + id, {
52+
id_type: "oa:artist_id"
53+
54+
}, function(status, data) {
55+
cb(new ArtistInfo(data));
56+
});
57+
}, ArtistInfo.fetchByMbGid = function(id, cb) {
58+
return api.infoRequest("artists/" + id, {
59+
id_type: "musicbrainz:gid"
60+
}, function(status, data) {
61+
cb(new ArtistInfo(data));
62+
});
63+
}, ArtistInfo.fetchByAnchorId = function(id, cb) {
64+
return api.infoRequest("artists/" + id, {
65+
id_type: "oa:anchor_id"
66+
}, function(status, data) {
67+
cb(new ArtistInfo(data));
68+
});
69+
}, ArtistInfo;
70+
});;

www-built/app/aura.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
define([ "require", "jquery", "underscore", "./util", "./api", "./particle", "./particleCollection", "./mediaCollection", "./media" ], function(require) {
2+
var $ = require("jquery"), _ = require("underscore"), util = require("./util"), api = require("./api"), prop = util.getProperty, Particle = require("./particle"), ParticleCollection = require("./particleCollection"), MediaCollection = require("./mediaCollection"), Media = require("./media");
3+
function Aura(data) {
4+
this._data = Object.freeze({
5+
particleCount: prop(data, "total_particles"),
6+
nextParticleSet: prop(data, "next_particles"),
7+
particles: new ParticleCollection(prop(data, "particles"))
8+
});
9+
}
10+
return Aura.prototype = {
11+
particleCount: function() {
12+
return this._data.particleCount;
13+
},
14+
anchor: function() {
15+
return this._data.anchor;
16+
},
17+
nextParticleSet: function() {
18+
return this._data.nextParticleSet
19+
;
20+
},
21+
particles: function() {
22+
return this._data.particles;
23+
}
24+
}, Aura.api = function() {
25+
return api;
26+
}, Aura.fetchByOaArtistId = function(id, cb) {
27+
return api.streamRequest("artists/" + id, {
28+
id_type: "oa:artist_id"
29+
}, function(status, data) {
30+
cb(new Aura(data));
31+
});
32+
}, Aura.fetchByMbGid = function(id, cb) {
33+
return api.streamRequest("artists/" + id, {
34+
id_type: "musicbrainz:gid"
35+
}, function(status, data) {
36+
cb(new Aura(data));
37+
});
38+
}, Aura.fetchByAnchorId = function(id, cb) {
39+
return api.streamRequest("artists/" + id, {
40+
id_type: "oa:anchor_id"
41+
}, function(status, data) {
42+
cb(new Aura(data));
43+
});
44+
}, Aura;
45+
});;

www-built/app/factCard.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
define([ "require", "./util" ], function(require) {
2+
var util = require("./util"), prop = util.getProperty;
3+
function FactCard(data) {
4+
this._data = Object.freeze({
5+
birthname: prop(data, "birthname"),
6+
birthdate: prop(data, "birthdate"),
7+
birthplace: prop(data, "birthplace"),
8+
locationFormed: prop(data, "location_formed"),
9+
members: prop(data, "members"),
10+
labels: prop(data, "labels"),
11+
associatedActs: prop(data, "associated_acts"),
12+
website: prop(data, "website")
13+
});
14+
}
15+
return FactCard.prototype = {
16+
birthdate: function() {
17+
return this._data.birthdate;
18+
},
19+
birthname: function() {
20+
return this._data.birthname;
21+
},
22+
birthplace: function() {
23+
return this._data.birthplace;
24+
},
25+
locationFormed: function() {
26+
return this._data.locationFormed;
27+
},
28+
members: function() {
29+
30+
return this._data.members;
31+
},
32+
labels: function() {
33+
return this._data.labels;
34+
},
35+
associatedActs: function() {
36+
return this._data.associatedActs;
37+
},
38+
website: function() {
39+
return this._data.website;
40+
}
41+
}, FactCard;
42+
});;

www-built/app/initialize.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
define([ "require" ], function(require) {
2+
return function(config) {
3+
var root = this, OA = root.OA || {}, cfg = function() {
4+
return Object.freeze({
5+
base_api_url: "http://api.openaura.com/v1",
6+
stream_key: config.stream_key || "YOUR_STREAM_KEY",
7+
info_key: config.info_key || "YOUR_INFO_KEY",
8+
callback_url: config.callback_url || "YOUR_CALLBACK_URL",
9+
max_particles: config.max_particles || 100
10+
});
11+
};
12+
return OA.config = cfg;
13+
};
14+
});;

www-built/app/media.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
define([ "require", "./util" ], function(require) {
2+
var util = require("./util"), prop = util.getProperty;
3+
function Media(data) {
4+
this._data = Object.freeze({
5+
id: prop(data, "oa_media_id"),
6+
mediaType: prop(data, "mediaType"),
7+
url: prop(data, "url"),
8+
width: prop(data, "width"),
9+
height: prop(data, "height"),
10+
mime: prop(data, "mime"),
11+
data: prop(data, "data")
12+
});
13+
}
14+
return Media.prototype = {
15+
id: function() {
16+
return this._data.id;
17+
},
18+
mediaType: function() {
19+
return this._data.mediaType;
20+
},
21+
url: function() {
22+
return this._data.url;
23+
},
24+
width: function() {
25+
return this._data.width;
26+
},
27+
height: function() {
28+
return this._data.height;
29+
},
30+
mime: function() {
31+
return this._data.mime;
32+
},
33+
data: function() {
34+
35+
return this._data.data;
36+
},
37+
asObject: function() {
38+
return {
39+
id: this.id(),
40+
mediaType: this.mediaType(),
41+
url: this.url(),
42+
width: this.width(),
43+
height: this.height(),
44+
mime: this.mime(),
45+
data: this.data()
46+
};
47+
}
48+
}, Media;
49+
});;

www-built/app/mediaCollection.js

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
define([ "require", "underscore", "./util", "./media" ], function(require) {
2+
var _ = require("underscore"), util = require("./util"), prop = util.getProperty, Media = require("./media");
3+
function MediaCollection(data) {
4+
this._data = _.map(data, function(m) {
5+
return Object.freeze(new Media(m));
6+
});
7+
}
8+
return MediaCollection.prototype = {
9+
smallerThan: function(w, h) {
10+
return new MediaCollection(_.chain(this._data).filter(function(m) {
11+
return m.width() < w && m.height() < h;
12+
}).map(function(m) {
13+
return m.asObject();
14+
}).value());
15+
},
16+
largerThan: function(w, h) {
17+
return new MediaCollection(_.chain(this._data).filter(function(m) {
18+
return m.width() > w && m.height() > h;
19+
}).map(function(m) {
20+
return m.asObject();
21+
}).value());
22+
},
23+
within: function(minW, minH, maxW, maxH) {
24+
25+
return new MediaCollection(_.chain(this._data).filter(function(m) {
26+
return m.width() >= minW && m.height() >= minH && m.width() <= maxW && m.height() <= maxH;
27+
}).map(function(m) {
28+
return m.asObject();
29+
}).value());
30+
},
31+
widest: function() {
32+
var widest = this.first();
33+
return this.tail().each(function(m) {
34+
m.width() > widest.width() && (widest = m);
35+
}), widest;
36+
},
37+
tallest: function() {
38+
var tallest = this.first();
39+
return this.tail().each(function(m) {
40+
m.tallest() > tallest.height() && (tallest = m);
41+
}), tallest;
42+
},
43+
length: function() {
44+
return this._data.length;
45+
},
46+
toArray: function() {
47+
return this._data.slice();
48+
},
49+
each: function(fn) {
50+
_.each(this._data, fn);
51+
},
52+
filter: function(fn) {
53+
return new
54+
MediaCollection(_.chain(this._data).filter(fn).map(function(m) {
55+
return m.asObject();
56+
}).value());
57+
},
58+
map: function(fn) {
59+
return _.map(this._data, fn);
60+
},
61+
first: function() {
62+
return this._data.length ? this._data[0] : undefined;
63+
},
64+
last: function() {
65+
return this._data.slice(-1).pop();
66+
},
67+
tail: function() {
68+
return new MediaCollection(_.map(this._data.slice(1), function(m) {
69+
return m.asObject();
70+
}));
71+
}
72+
}, MediaCollection;
73+
});;

0 commit comments

Comments
 (0)