Page MenuHomePhabricator

No OneTemporary

diff --git a/assets/js/ping/ping.js b/assets/js/ping/ping.js
index 6673c05..9a6e38e 100644
--- a/assets/js/ping/ping.js
+++ b/assets/js/ping/ping.js
@@ -1,58 +1,63 @@
/*
* The MIT License
*
* Copyright 2019 César de la Cal Bretschneider <cesar@magic3w.com>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/*
* This Javascript file provides an entry point to the Ping SDK. This should make
* it easy for your application to create and retrieve pings from the client
* itself, reducing load on the source application and making the application
* more responsive to the end user.
*/
-depend(['ping/sdk/ping', 'ping/sdk/feed', 'ping/sdk/feedback'], function (Ping, Feed, Feedback) {
+depend([
+ 'ping/sdk/ping',
+ 'ping/sdk/feed',
+ 'ping/sdk/feedback',
+ 'ping/sdk/activity',
+ 'ping/sdk/media'], function (Ping, Feed, Feedback, Activity, Media) {
/**
*
* @param {string} endpoint
* @param {string} token optional Only needed for authenticated requests
* @returns {pingL#33.Ping}
*/
var SDK = function (endpoint, token) {
this._endpoint = endpoint;
this._token = token;
};
SDK.prototype = {
feed : function () { return new Feed(this); },
feedback : function () { return new Feedback(this); },
- media : function () { },
+ media : function () { return new Media(this); },
ping : function () { return new Ping(this); },
- activity : function () {},
+ activity : function () { return new Activity(this); },
//Getters and setters
endpoint : function () { return this._endpoint; },
token : function () { return this._token; }
};
return SDK;
});
\ No newline at end of file
diff --git a/assets/js/ping/sdk/activity.js b/assets/js/ping/sdk/activity.js
new file mode 100644
index 0000000..dedf5f1
--- /dev/null
+++ b/assets/js/ping/sdk/activity.js
@@ -0,0 +1,123 @@
+/*
+ * The MIT License
+ *
+ * Copyright 2019 César de la Cal Bretschneider <cesar@magic3w.com>.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+depend(['m3/core/request'], function (request) {
+
+ /**
+ * The feed is in charge of delivering updates to the user from the authors
+ * they follow.
+ *
+ * @returns {pingL#25.Feed}
+ */
+ var Activity = function (ctx) {
+ this._ctx = ctx;
+ };
+
+ Activity.prototype = {
+ /**
+ * Reads the feed. If you pass the offset (the ID of the last ping you have
+ * available) it will return the feed starting at that point.
+ *
+ * The callback will receive a PingList object containing an array of pings
+ * as it's first and only parameter. This pinglist object gives you access
+ * to:
+ *
+ * * The array of pings the server returned
+ * * The context. Which allows you to make further calls to the SDK (for responses, for example)
+ * * A function that calls your function again with the next set of pings.
+ *
+ * This allows your application to simply let itself be called over and over
+ * to generate a timeline.
+ *
+ * @param {function} callback
+ * @param {int} offset
+ * @returns {undefined}
+ */
+ read : function (callback, offset) {
+
+ /*
+ * Construct an URI that idenitfies the user against Ping and send a
+ * request to Ping.
+ *
+ * The token will authenticate both the user and the application embedding
+ * the SDK since Ping will be able to retrieve metadata from PHPAS, allowing
+ * it to determine whether it should share the feed for this user with
+ * the application.
+ *
+ * Additionally, (although at the time of writing this is not the case)
+ * Ping should send a Access-Control header limited to the application's
+ * domain to ensure the user is not being attacked with XSRF to leak data.
+ *
+ * For this, Ping would also need to be able to understand the options
+ * header. Which (again, at this point) is not being supported, but as
+ * soon as it is, this should transparently become operational - only
+ * breaking non compliant applications.
+ */
+ var uri = this._ctx.endpoint().trim('/') + '/acticity.json?token=' + this._ctx.token() + (offset !== undefined? '&until=' + offset : '');
+ var ctx = this._ctx;
+ var slf = this;
+
+ /*
+ * Send the request to ping.
+ */
+ request(uri, null)
+ .then(JSON.parse)
+ .then(function (e) {
+ if (!e.payload) { throw {message : 'Invalid response', response : e}; }
+
+ var pl = [];
+ for (var i = 0; i < e.payload.length; i++) { pl.push(new Activity(ctx, e.payload[i])); }
+
+ return new ActivityList(
+ ctx,
+ pl,
+ function () { return e.until != 0? slf.read(callback, e.until) : null; }
+ );
+ })
+ .then(callback)
+ .catch(function (e) { console.error(e); });
+ }
+ };
+
+
+ var Activity = function (ctx, payload) {
+ this.payload = payload;
+ };
+
+ Activity.prototype = {
+
+ };
+
+ var ActivityList = function (ctx, pings, next) {
+ this._pings = pings;
+ this._ctx = ctx;
+ this._next = next;
+ };
+
+ ActivityList.prototype = {
+
+ };
+
+ return Activity;
+});
diff --git a/assets/js/ping/ping.js b/assets/js/ping/sdk/media.js
similarity index 54%
copy from assets/js/ping/ping.js
copy to assets/js/ping/sdk/media.js
index 6673c05..73fd27f 100644
--- a/assets/js/ping/ping.js
+++ b/assets/js/ping/sdk/media.js
@@ -1,58 +1,49 @@
/*
* The MIT License
*
* Copyright 2019 César de la Cal Bretschneider <cesar@magic3w.com>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-
-/*
- * This Javascript file provides an entry point to the Ping SDK. This should make
- * it easy for your application to create and retrieve pings from the client
- * itself, reducing load on the source application and making the application
- * more responsive to the end user.
- */
-depend(['ping/sdk/ping', 'ping/sdk/feed', 'ping/sdk/feedback'], function (Ping, Feed, Feedback) {
+depend(['m3/core/request'], function (request) {
- /**
- *
- * @param {string} endpoint
- * @param {string} token optional Only needed for authenticated requests
- * @returns {pingL#33.Ping}
- */
- var SDK = function (endpoint, token) {
- this._endpoint = endpoint;
- this._token = token;
+ var Media = function (ctx) {
+ this._ctx = ctx;
};
- SDK.prototype = {
- feed : function () { return new Feed(this); },
- feedback : function () { return new Feedback(this); },
- media : function () { },
- ping : function () { return new Ping(this); },
- activity : function () {},
-
- //Getters and setters
- endpoint : function () { return this._endpoint; },
- token : function () { return this._token; }
+ Media.prototype = {
+
+ push : function (payload, cb) {
+
+ var fd = new FormData();
+ fd.append('file', payload);
+
+ var uri = this._ctx.endpoint().trim('/') + '/media/upload.json?token=' + encodeURIComponent(this._ctx.token());
+
+ request(uri, fd)
+ .then(JSON.parse)
+ .then(function (resp) {
+ cb(resp);
+ });
+ }
};
- return SDK;
-});
\ No newline at end of file
+ return Media;
+});

File Metadata

Mime Type
text/x-diff
Expires
Wed, Apr 14, 2:54 PM (3 w, 6 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5474
Default Alt Text
(9 KB)

Event Timeline