jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/365425 )

Change subject: Offline compilations endpoint groundwork
......................................................................


Offline compilations endpoint groundwork

Lays the groundwork for the forthcoming offline compilations endpoint.
A formal spec is forthcoming and this will need updating when that's
finalized.  (Marked with todos where applicable.)

The endpoint path will need finalizing as well.

Bug: T170732
Change-Id: I6713ccc027fe37434081c7eccf511fb8af8f14f2
---
M lib/mobile-util.js
A routes/compilations.js
M spec.yaml
A test/features/compilations/compilations.js
4 files changed, 168 insertions(+), 10 deletions(-)

Approvals:
  BearND: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/mobile-util.js b/lib/mobile-util.js
index 51bf9da..5741b0f 100644
--- a/lib/mobile-util.js
+++ b/lib/mobile-util.js
@@ -9,13 +9,10 @@
 mUtil.CONTENT_TYPES = {
     mobileSections: { name: 'mobile-sections', version: '0.12.0' },
     definition: { name: 'definition', version: '0.7.2' },
-
     random: { name: 'random', version: '0.6.0' },
-
     announcements: { name: 'announcements', version: '0.1.0' },
-
+    compilations: { name: 'compilations', version: '0.1.0' },
     onthisday: { name: 'onthisday', version: '0.2.0' },
-
     unpublished: { name: 'unpublished', version: '0.0.0' }
 };
 
diff --git a/routes/compilations.js b/routes/compilations.js
new file mode 100644
index 0000000..5a66487
--- /dev/null
+++ b/routes/compilations.js
@@ -0,0 +1,36 @@
+'use strict';
+
+const sUtil = require('../lib/util');
+const mUtil = require('../lib/mobile-util');
+
+/**
+ * The main router object
+ */
+const router = sUtil.router();
+
+// todo: populate after we've decided what offline compilations to serve. 
(T169905)
+function getCompilations() { return []; }
+
+/**
+ * GET /compilations
+ * Gets information about the available offline compilations
+ */
+router.get('/compilations', (req, res) => {
+    const response = { compilations: getCompilations() };
+    const hash = mUtil.hashCode(JSON.stringify(response));
+
+    res.status(200);
+    mUtil.setContentType(res, mUtil.CONTENT_TYPES.compilations);
+    mUtil.setETag(res, hash);
+    res.set('cache-control', 'public, max-age=7200, s-maxage=14400');
+    res.json(response);
+});
+
+module.exports = function() {
+    return {
+        // todo: update when endpoint path is finalized
+        path: '/',
+        api_version: 1,
+        router
+    };
+};
diff --git a/spec.yaml b/spec.yaml
index 3618cf5..6d9634a 100644
--- a/spec.yaml
+++ b/spec.yaml
@@ -98,6 +98,32 @@
 #                  caption_HTML: /.+/
 #                  countries: [ /.+/ ]
 
+  # from routes/compilations.js
+  /{domain}/v1/compilations:
+    get:
+      tags:
+        - Offline compilations
+      description: Gets information about the offline compilations available 
for download
+      produces:
+        - application/json
+      responses:
+        '200':
+          description: Offline compilation information
+          schema:
+            $ref: '$/definitions/compilations'
+        default:
+          description: Error
+          schema:
+            $ref: '#/definitions/problem'
+      x-amples:
+        - title: Offline compilations
+          response:
+            status: 200
+            headers:
+              content-type: application/json
+            body:
+              compilations: []
+
   # from routes/on-this-day.js
   /{domain}/v1/feed/onthisday/{type}/{mm}/{dd}:
     get:
@@ -696,20 +722,20 @@
     required:
       - $merge
 
-  thumbnail:
+  image_props:
     type: object
     properties:
       source:
         type: string
-        description: Thumbnail image URI
+        description: URI
       width:
         type: integer
         minimum: 0
-        description: Thumbnail width
+        description: width (px)
       height:
         type: integer
         minimum: 0
-        description: Thumnail height
+        description: height (px)
     required:
       - source
       - width
@@ -851,10 +877,10 @@
         description: Image title
       thumbnail:
         description: Image thumbnail
-        $ref: '#/definitions/thumbnail'
+        $ref: '#/definitions/image_props'
       image:
         description: Full-size image
-        $ref: '#/definitions/thumbnail'
+        $ref: '#/definitions/image_props'
       description:
         description: Description of an image
         $ref: '#/definitions/image_description'
@@ -923,6 +949,64 @@
       - text
       - countries
 
+  compilations:
+    type: object
+    properties:
+      compilations:
+        type: array
+        description: list of available offline article compilations
+        items:
+          $ref: '#/definitions/compilation'
+    required:
+      - compilations
+
+  compilation:
+    type: object
+    properties:
+      name:
+        type: string
+        description: The name of the compilation
+      url:
+        type: string
+        description: Download URL for the compilation file
+      lang:
+        type: array
+        description: A list of wiki language codes documenting the language(s) 
of the articles in the compilation
+      summary:
+        type: string
+        description: A short description of the compilation contents
+      description:
+        type: string
+        description: A detailed description of the compilation contents
+      media:
+        type: string
+        enum:
+          - all
+          - images
+          - none
+      image_thumb:
+        type: object
+        description: Thumbnail image (320px) representing the collection
+        $ref: '#/definitions/image_props'
+      image_feature:
+        type: object
+        description: Feature-size image (640px) representing the collection
+        $ref: '#/definitions/image_props'
+      count:
+        type: integer
+        description: The number of articles included in the compilation
+      size:
+        type: integer
+        description: The size of the compilation, in bytes
+      timestamp:
+        type: integer
+        description: Unix timestamp for the compilation file creation
+    required:
+      - name
+      - count
+      - size
+      - timestamp
+
   action:
     type: object
     properties:
diff --git a/test/features/compilations/compilations.js 
b/test/features/compilations/compilations.js
new file mode 100644
index 0000000..28cab99
--- /dev/null
+++ b/test/features/compilations/compilations.js
@@ -0,0 +1,41 @@
+'use strict';
+
+const preq   = require('preq');
+const assert = require('../../utils/assert.js');
+const server = require('../../utils/server.js');
+const headers = require('../../utils/headers.js');
+
+describe('compilations', function() {
+
+    this.timeout(20000); // eslint-disable-line no-invalid-this
+
+    before(() => {
+        return server.start();
+    });
+
+    it('should respond to GET request with expected headers, incl. CORS and 
CSP headers', () => {
+        return 
headers.checkHeaders(`${server.config.uri}en.wikipedia.org/v1/compilations`);
+    });
+
+    // todo: update when spec is finalized
+    it('should return a valid response', () => {
+        return preq.get({ uri: 
`${server.config.uri}en.wikipedia.org/v1/compilations` })
+            .then((res) => {
+                assert.status(res, 200);
+                assert.equal(res.headers['cache-control'], 'public, 
max-age=7200, s-maxage=14400');
+                res.body.compilations.forEach((elem) => {
+                    assert.ok(elem.name, 'name should be present');
+                    assert.ok(typeof elem.count === 'number', 'count should be 
present & valid');
+                    assert.ok(typeof elem.size === 'number', 'size should be 
present & valid');
+                    assert.ok(typeof elem.timestamp === 'number', 'timestamp 
should be present');
+                });
+            });
+    });
+
+    it('should return 0 compilations', () => {
+        return preq.get({ uri: 
`${server.config.uri}en.wikipedia.org/v1/compilations` })
+            .then((res) => {
+                assert.ok(res.body.compilations.length === 0);
+            });
+    });
+});

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I6713ccc027fe37434081c7eccf511fb8af8f14f2
Gerrit-PatchSet: 13
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: Mholloway <[email protected]>
Gerrit-Reviewer: BearND <[email protected]>
Gerrit-Reviewer: Dbrant <[email protected]>
Gerrit-Reviewer: Fjalapeno <[email protected]>
Gerrit-Reviewer: GWicke <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Jhernandez <[email protected]>
Gerrit-Reviewer: Mholloway <[email protected]>
Gerrit-Reviewer: Mhurd <[email protected]>
Gerrit-Reviewer: Mobrovac <[email protected]>
Gerrit-Reviewer: Niedzielski <[email protected]>
Gerrit-Reviewer: Ppchelko <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to