0

I am sorry cause I do not know any scripting language I am posting my concerns here. I am in need of script having the below functionality. I have created https://sites.google.com/site/iitmamritwater website.

I am in need a web service for a HTTP GET request like : https://sites.google.com/site/iitmamritwater?id=xxxxxxxxxx that would validate id as submitted in query param. Currently I have only 2 valid ID values each of 10 digits length. The web service response should state id validity with its balance - something like below:

If xxxxxxxxxx is one of the two possible correct values then response should be as below:

https://sites.google.com/site/iitmamritwater?id=xxxxxxxxxx

V;10.50;

If xxxxxxxxxy is not one of the two values then response should be as below:

https://sites.google.com/site/iitmamritwater?id=xxxxxxxxxy

N;00.00;

Its a very simple script but cause I do not know scripting I am stuck implementing the concept. I don't know even how to begin with - can some one please post the code for same - it would be highly helpful for me? It will save my project development time period.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Programmer
  • 8,303
  • 23
  • 78
  • 162
  • You are on SO since 2010 and you know nothing about scripting ? No personal offense but at least you should know that this is not the right place to ask someone to do it for you. Try the Google-apps-Script community on G+ instead, maybe you'll be more lucky. – Serge insas Nov 11 '14 at 22:05
  • @Sergeinsas I know scripting but not Google Apps Scripting. It seems that Google Apps scripting is not like PHP / NodeJS or C/C++. It seems one has to do some coding in Java - hence the concern as I do not know that language very well - to get a request, get the param, validate the params and generate a response? – Programmer Nov 12 '14 at 00:44

1 Answers1

2

See this answer for an example of serving multiple html pages using HtmlService. The basic idea is to write doGet() to accept a query parameter that it will use to select which html page to serve.

In your case, instead of serving HTML pages, you should use the ContentService to output the appropriate response, based on the evaluation of the received parameters.

function doGet(e) {
  if (!e.parameter.id) {
    // No id provided...
    return ContentService.createTextOutput('Error - no id');
  }

  // else, get response for given id
  var response = validateId( e.parameter.id );

  // ...and serve it as text output
  return ContentService.createTextOutput( response );
}

/**
 * Get a response string for the given id
 *
 * @param {string}      id   10 digit id
 * @returns {string}         Result of validation & lookup
 */

function validateId( id ) {
  return "Under construction";
}
Community
  • 1
  • 1
Mogsdad
  • 44,709
  • 21
  • 151
  • 275