Mvolz has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/375810 )

Change subject: [WIP] WaybackMachine support
......................................................................

[WIP] WaybackMachine support

Change-Id: I9d59e6a5c8e6e610b6b924a78271dc00655c4047
---
A lib/externalAPIs/WaybackMachine.js
A test/features/unit/externalAPIs/waybackMachine.js
2 files changed, 92 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/citoid 
refs/changes/10/375810/1

diff --git a/lib/externalAPIs/WaybackMachine.js 
b/lib/externalAPIs/WaybackMachine.js
new file mode 100644
index 0000000..adfe22e
--- /dev/null
+++ b/lib/externalAPIs/WaybackMachine.js
@@ -0,0 +1,58 @@
+'use strict';
+
+/**
+ * https://www.mediawiki.org/wiki/citoid
+ *
+ * Supplies methods to send requests to the Wayback Machine APIs
+ */
+
+/* Import Modules */
+var BBPromise = require('bluebird');
+var preq = require('preq');
+
+
+/**
+ * Constructor for CitoidService object
+ * @param {Object} app   Express app; contains logger, metrics, and 
configuration
+ */
+function WaybackMachine(app){
+
+    this.logger = app.logger;
+    this.userAgent = app.conf.userAgent;
+
+}
+
+// Requests to Wayback Availability JSON API at 
https://archive.org/help/wayback_api.php
+WaybackMachine.prototype.availability = BBPromise.method(function(url){
+    this.logger.log('debug/other', 'Making request to Wayback Machine 
availability API');
+
+    var endpoint = 'http://archive.org/wayback/available';
+    var self = this;
+
+    var qs = { // Basic query parameters
+        url: url // Encodes url
+    };
+
+    var requestOptions = {
+        uri : endpoint,
+        headers: {
+            'User-Agent': self.userAgent
+        },
+        qs: qs
+    };
+
+    // Make request to Wayback Availability service
+    return preq(requestOptions).then(function (res) {
+        if (res && res.status === 200 && res.archived_snapshots && 
res.archived_snapshots.closest && res.archived_snapshots.closest.status === 
"200") {
+            self.logger.log('debug/other', 'Archived copy of ' + url + ' 
available');
+            return res.archived_snapshots.closest;
+        } else {
+            self.logger.log('debug/other', 'No acceptable results from 
WaybackMachine availability service for url ' + url);
+            return BBPromise.reject('No acceptable results from WaybackMachine 
availability service');
+        }
+    });
+
+});
+
+/* Exports */
+module.exports = WaybackMachine;
diff --git a/test/features/unit/externalAPIs/waybackMachine.js 
b/test/features/unit/externalAPIs/waybackMachine.js
new file mode 100644
index 0000000..7a7b790
--- /dev/null
+++ b/test/features/unit/externalAPIs/waybackMachine.js
@@ -0,0 +1,34 @@
+var assert = require('../../../utils/assert.js');
+var WaybackMachine = require('../../../../lib/externalAPIs/WaybackMachine.js');
+var logStream = require('../../../utils/logStream');
+
+var app = {
+
+    logger:{
+        name: 'test-log',
+        level: 'trace',
+        stream: logStream()
+    },
+    conf: {userAgent:'test'}
+};
+
+var wayback = new WaybackMachine(app);
+
+describe('availability API :', function() {
+
+    var url;
+    var expected;
+
+    it.only('true positive', function() {
+        url = 'http://archive.org/wayback/available?url=www.example.com';
+        wayback.availability(url).then(function(results){
+            console.log(results.url);
+            assert.ok(results.url);
+        });
+    });
+
+    it('true negative', function() {
+        url = 'www.example.com/noarchive';
+        assert.deepEqual(result, expected);
+    });
+});
\ No newline at end of file

-- 
To view, visit https://gerrit.wikimedia.org/r/375810
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9d59e6a5c8e6e610b6b924a78271dc00655c4047
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/citoid
Gerrit-Branch: master
Gerrit-Owner: Mvolz <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to