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

Change subject: Update: add revision and time ID support to page summary client
......................................................................

Update: add revision and time ID support to page summary client

Add page revision and render time UUID support to the page data client.
The page data client will also want this functionality.

- Add revision and time ID parameters to page revision client.
- Unmarshal ETag as a proper model.
- Move RESTBase URL to response definitions file.

Bug: T173317
Change-Id: Icf55b128842cb7ad36c40d9ed2a8fcd2aea39bef
---
M src/common/data-clients/page-summary-data-client.ts
M src/common/marshallers/page-restbase-mount-everest-expected.test.json
M src/common/marshallers/page-unmarshaller.test.ts
M src/common/marshallers/page-unmarshaller.ts
M src/common/marshallers/restbase.ts
A src/common/models/etag.ts
M src/common/models/page/summary.ts
7 files changed, 39 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/marvin refs/changes/15/381915/1

diff --git a/src/common/data-clients/page-summary-data-client.ts 
b/src/common/data-clients/page-summary-data-client.ts
index bbee03c..ca1edee 100644
--- a/src/common/data-clients/page-summary-data-client.ts
+++ b/src/common/data-clients/page-summary-data-client.ts
@@ -8,12 +8,17 @@
 // https://en.wikipedia.org/api/rest_v1/#!/Page_content/get_page_summary_title
 export interface Params {
   titlePath: PageTitlePath;
+  revision?: number;
+  timeID?: string;
   redirect?: PageRedirect;
 }
 
-const url = ({ titlePath, redirect }: Params) => {
+const url = ({ titlePath, revision, timeID, redirect }: Params) => {
+  const revisionPath = revision === undefined ? "" : `/${revision}`;
+  const timeIDPath = timeID === undefined ? "" : `/${timeID}`;
   const redirectParam = redirect === undefined ? "" : `&redirect=${redirect}`;
-  return 
`https://en.wikipedia.org/api/rest_v1/page/summary/${titlePath}${redirectParam}`;
+  return `${RESTBase.PageSummary
+    .BASE_URL}/${titlePath}${revisionPath}${timeIDPath}${redirectParam}`;
 };
 
 const HEADERS = {
diff --git 
a/src/common/marshallers/page-restbase-mount-everest-expected.test.json 
b/src/common/marshallers/page-restbase-mount-everest-expected.test.json
index d56cfec..2609114 100644
--- a/src/common/marshallers/page-restbase-mount-everest-expected.test.json
+++ b/src/common/marshallers/page-restbase-mount-everest-expected.test.json
@@ -29,5 +29,8 @@
     "latitude": 27.98805556,
     "longitude": 86.92527778
   },
-  "etag": "802006980/4f754377-a235-11e7-a776-efb84f18649a"
+  "etag": {
+    "revision": 802006980,
+    "timeID": "4f754377-a235-11e7-a776-efb84f18649a"
+  }
 }
diff --git a/src/common/marshallers/page-unmarshaller.test.ts 
b/src/common/marshallers/page-unmarshaller.test.ts
index a2e488b..20c9bee 100644
--- a/src/common/marshallers/page-unmarshaller.test.ts
+++ b/src/common/marshallers/page-unmarshaller.test.ts
@@ -4,9 +4,10 @@
 import { unmarshalPageSummary } from "./page-unmarshaller";
 import { RESTBase } from "./restbase";
 
-const ETAG = "802006980/4f754377-a235-11e7-a776-efb84f18649a";
+const ETAG_REVISION = 802006980;
+const ETAG_TIME_ID = "4f754377-a235-11e7-a776-efb84f18649a";
 const HEADERS = new fetch.Headers();
-HEADERS.append("etag", ETAG);
+HEADERS.append("etag", `${ETAG_REVISION}/${ETAG_TIME_ID}`);
 
 const NOW = new Date(Date.now()).toString();
 
@@ -31,7 +32,7 @@
         titleHTML: "displaytitle",
         descriptionText: "description",
         lastModified: new Date(Date.parse(NOW)),
-        etag: ETAG,
+        etag: { revision: ETAG_REVISION, timeID: ETAG_TIME_ID },
         wikiLanguageCode: "en",
         localeDirection: "ltr",
         extractText: "extract",
diff --git a/src/common/marshallers/page-unmarshaller.ts 
b/src/common/marshallers/page-unmarshaller.ts
index 6122404..ea9b92f 100644
--- a/src/common/marshallers/page-unmarshaller.ts
+++ b/src/common/marshallers/page-unmarshaller.ts
@@ -1,4 +1,5 @@
 import { PageImage, PageThumbnail } from "../models/page/image";
+import { ETag } from "../models/etag";
 import { PageGeolocation } from "../models/page/geolocation";
 import { PageSummary } from "../models/page/summary";
 import { IsomorphicHeaders } from "../types/isomorphic-unfetch-extras";
@@ -68,12 +69,13 @@
     : [extractHTML];
 };
 
-export const unmarshalETag = (headers: IsomorphicHeaders): RESTBase.ETag => {
-  const eTag = headers.get("ETag");
-  if (!eTag) {
+export const unmarshalETag = (headers: IsomorphicHeaders): ETag => {
+  const etag = headers.get("ETag");
+  if (!etag) {
     throw new Error("ETag is undefined.");
   }
-  return eTag;
+  const [revision, timeID] = etag.split("/");
+  return { revision: parseInt(revision, 10), timeID };
 };
 
 export const unmarshalPageSummary = ({
diff --git a/src/common/marshallers/restbase.ts 
b/src/common/marshallers/restbase.ts
index e5055c3..6b884b7 100644
--- a/src/common/marshallers/restbase.ts
+++ b/src/common/marshallers/restbase.ts
@@ -1,4 +1,6 @@
 export namespace RESTBase {
+  export const BASE_URL: string = "https://en.wikipedia.org/api/rest_v1";;
+
   // 
https://phabricator.wikimedia.org/diffusion/GMOA/browse/master/spec.yaml;399c85e3e782ffa7fef2d4a73c4ee85e98c9114d$690
   // 
https://phabricator.wikimedia.org/diffusion/GMOA/browse/master/lib/util.js;552a924e45d11a0c20b284c252f0b02065a0d44c$210
   export interface Error {
@@ -13,11 +15,7 @@
   /**
    * A response ETag header indicating the revision and render time UUID or
    * "TID" separated by a slash (ex:
-   * `ETag: 701384379/154d7bca-c264-11e5-8c2f-1b51b33b59fc`). This ETag can be
-   * passed to the HTML save end point (as the base_etag POST parameter), and
-   * can also be used to retrieve the exact corresponding data-parsoid 
metadata,
-   * by requesting the specific revision and time UUID / TID indicated by the
-   * ETag.
+   * `ETag: 701384379/154d7bca-c264-11e5-8c2f-1b51b33b59fc`).
    */
   export type ETag = string;
 
@@ -25,6 +23,7 @@
   export namespace PageSummary {
     export const ACCEPT_HEADER: string =
       'application/json; charset=utf-8; 
profile="https://www.mediawiki.org/wiki/Specs/Summary/1.2.0";';
+    export const BASE_URL: string = `${RESTBase.BASE_URL}/page/summary`; // 
eslint-disable-line no-redeclare
 
     // 
https://phabricator.wikimedia.org/diffusion/GRES/browse/master/v1/summary.yaml;efa0412225221d49e901fdce0ba2ae88cd6ccc11$138
     export interface Thumbnail {
diff --git a/src/common/models/etag.ts b/src/common/models/etag.ts
new file mode 100644
index 0000000..76b0632
--- /dev/null
+++ b/src/common/models/etag.ts
@@ -0,0 +1,12 @@
+/**
+ * A response ETag header indicating the revision and render time UUID or
+ * "TID" (ex: `701384379/154d7bca-c264-11e5-8c2f-1b51b33b59fc`). This ETag can
+ * be passed to the HTML save end point (as the base_etag POST parameter), and
+ * can also be used to retrieve the exact corresponding data-parsoid metadata,
+ * by requesting the specific revision and time UUID / TID indicated by the
+ * ETag.
+ */
+export interface ETag {
+  revision: number;
+  timeID: string;
+}
diff --git a/src/common/models/page/summary.ts 
b/src/common/models/page/summary.ts
index 01f62f0..125cb5f 100644
--- a/src/common/models/page/summary.ts
+++ b/src/common/models/page/summary.ts
@@ -1,4 +1,4 @@
-import { RESTBase } from "../../marshallers/restbase";
+import { ETag } from "../etag";
 import { PageGeolocation } from "./geolocation";
 import { PageImage, PageThumbnail } from "./image";
 import { PageTitleText } from "./title";
@@ -16,7 +16,7 @@
   thumbnail?: PageThumbnail;
   image?: PageImage;
   geolocation?: PageGeolocation;
-  etag: RESTBase.ETag;
+  etag: ETag;
 }
 
 export const pageSummaryReviver = (key: string, value: any): any =>

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icf55b128842cb7ad36c40d9ed2a8fcd2aea39bef
Gerrit-PatchSet: 1
Gerrit-Project: marvin
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <[email protected]>
Gerrit-Reviewer: Sniedzielski <[email protected]>

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

Reply via email to