From c8e13a692fb23054eeb13cbcbaed9aa61a1f4322 Mon Sep 17 00:00:00 2001 From: taylordowns2000 Date: Thu, 2 Feb 2017 14:37:09 -0500 Subject: [PATCH] bump to 1.1, allow hostUrl for custom deployments --- README.md | 3 ++- lib/Adaptor.js | 3 ++- package.json | 2 +- src/Adaptor.js | 29 ++++++++++++++++------------- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 540001a..c3de7c3 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,8 @@ enter it from the project screen. I.e., the last part of this url: `https://www. "appId": "the-long-uuid-in-the-url-that-designates-a-unique-commcare-project", "password": "shhh", "username": "openfn-test", - "applicationName": "some-proof-of-concept" + "applicationName": "some-proof-of-concept", + "hostUrl": "https://www.commcarehq.org" } ``` diff --git a/lib/Adaptor.js b/lib/Adaptor.js index 55babf3..7aad04d 100644 --- a/lib/Adaptor.js +++ b/lib/Adaptor.js @@ -125,9 +125,10 @@ function submit(formData) { var username = _state$configuration.username; var password = _state$configuration.password; var appId = _state$configuration.appId; + var hostUrl = _state$configuration.hostUrl; - var url = 'https://www.commcarehq.org/a/'.concat(applicationName, '/receiver/', appId, '/'); + var url = (hostUrl || "https://www.commcarehq.org").concat('/a/', applicationName, '/receiver/', appId, '/'); console.log("Posting to url: ".concat(url)); console.log("Raw JSON body: ".concat(JSON.stringify(jsonBody))); diff --git a/package.json b/package.json index 860cdd6..6c6a431 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "language-commcare", - "version": "1.0.4", + "version": "1.1.0", "description": "commcare Language Pack for OpenFn", "main": "lib/index.js", "scripts": { diff --git a/src/Adaptor.js b/src/Adaptor.js index 632b148..091855a 100644 --- a/src/Adaptor.js +++ b/src/Adaptor.js @@ -53,30 +53,33 @@ export function submit(formData) { const body = js2xmlparser("data", jsonBody); const { + // this should be called project URL. + // it is what lives after www.commcarehq.org/a/... applicationName, username, password, - appId + appId, + hostUrl } = state.configuration; - const url = `https://www.commcarehq.org/a/`.concat(applicationName, '/receiver/', appId, '/') + const url = (hostUrl || "https://www.commcarehq.org").concat('/a/', applicationName, '/receiver/', appId, '/'); console.log("Posting to url: ".concat(url)); console.log("Raw JSON body: ".concat(JSON.stringify(jsonBody))); console.log("X-form submission: ".concat(body)); return clientPost({ - url, - body, - username, - password - }) - .then((result) => { - console.log("Success:", result); - return {...state, - references: [result, ...state.references] - } - }) + url, + body, + username, + password + }) + .then((result) => { + console.log("Success:", result); + return {...state, + references: [result, ...state.references] + } + }); } }