[MediaWiki-commits] [Gerrit] mediawiki...mobileapps[master]: Offline compilations endpoint groundwork

2017-07-31 Thread jenkins-bot (Code Review)
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 000..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 

[MediaWiki-commits] [Gerrit] mediawiki...mobileapps[master]: Offline compilations endpoint groundwork

2017-07-14 Thread Mholloway (Code Review)
Mholloway has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/365425 )

Change subject: Offline compilations endpoint groundwork
..

Offline compilations endpoint groundwork

Lays the groundwork for the forthcoming offline compilations endopint.
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, 122 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mobileapps 
refs/changes/25/365425/1

diff --git a/lib/mobile-util.js b/lib/mobile-util.js
index eee8f56..ce36582 100644
--- a/lib/mobile-util.js
+++ b/lib/mobile-util.js
@@ -9,13 +9,10 @@
 mUtil.CONTENT_TYPES = {
 mobileSections: { name: 'mobile-sections', version: '0.11.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 000..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..0991300 100644
--- a/spec.yaml
+++ b/spec.yaml
@@ -923,6 +923,50 @@
   - 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:
+  filename:
+type: string
+description: The compilation filename
+  summary:
+type: string
+description: A short description of the compilation's contents
+  description:
+type: string
+description: A detailed description of the compilation's contents
+  thumb_url:
+type: string
+description: The URL for a thumbnail icon representing the collection
+  image_url:
+type: string
+description: The URL for a full-size image representing the collection
+  article_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: A timestamp for the compilation file creation date 
(expressed in ms since midnight 1/1/70 UTC)
+required:
+  - filename
+  - article_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 000..2f9c4f9
--- /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(2); // 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/feed/announcements`);
+});
+
+// todo: update when spec is finalized
+it('should return a valid