/**
* @fileoverview This file is generated by BoosterClientGenerator, do not edit.
* If this file needs to change consider updating the exporter
* code and re-run the export.
*
* @author anders.rejdebrant@spark-vision.com (Anders Rejdebrant)
*/
goog.provide('spv.vds.ipprot.IpadClient');
goog.require('goog.events.EventTarget');
goog.require('goog.json');
goog.require('goog.net.Jsonp');
goog.require('goog.net.XhrIo');
goog.require('goog.Uri.QueryData');
goog.require('spv.vds.ipprot.metadata.MetaDataEntry');
goog.require('spv.vds.ipprot.specification.VolvoCarSpecification');
goog.require('spv.vds.ipprot.vds.ConfigQuickInfoResult');
goog.require('spv.vds.ipprot.volvoboosterweb.MailRequestResult');
goog.require('spv.vds.ipprot.volvoboosterweb.VolvoRetailer');
goog.require('spv.vds.ipprot.volvocampaigns.CampaignCollection');
/**
* @constructor
* @struct
* @param {string} service_url
* @param {boolean} use_jsonp
*/
spv.vds.ipprot.IpadClient = function(
service_url,
use_jsonp)
{
this._service_url = service_url;
if (use_jsonp)
{
this._send_http_request = spv.vds.ipprot.IpadClient.sendJsonpHttpRequest;
this._api_name = 'jsonp';
}
else
{
this._send_http_request = spv.vds.ipprot.IpadClient.sendJsonHttpRequest;
this._api_name = 'api';
}
};
/**
* @param {string} session_id
* @param {string} config_name
* @param {function(spv.vds.ipprot.vds.ConfigQuickInfoResult)} on_success
* @param {function(Error)} on_failure
*/
spv.vds.ipprot.IpadClient.prototype.get_config_quick_info = function(
session_id,
config_name,
on_success,
on_failure)
{
var full_url = this._service_url + '/' + this._api_name + '/get_config_quick_info';
var http_method = 'GET';
var query = new goog.Uri.QueryData();
query.set('session_id', typeof(session_id) == "object" ? goog.json.serialize(session_id) : session_id);
query.set('config_name', typeof(config_name) == "object" ? goog.json.serialize(config_name) : config_name);
/** @type {function(Object)} */
var on_http_success = function(result_obj)
{
on_success(result_obj['get_config_quick_info']);
}
this._send_http_request(full_url,
http_method,
query,
false,
on_http_success,
on_failure);
};
/**
* @param {string} model
* @param {string} item
* @param {function(Array.<spv.vds.ipprot.metadata.MetaDataEntry>)} on_success
* @param {function(Error)} on_failure
*/
spv.vds.ipprot.IpadClient.prototype.get_item_meta_data = function(
model,
item,
on_success,
on_failure)
{
var full_url = this._service_url + '/' + this._api_name + '/get_item_meta_data';
var http_method = 'GET';
var query = new goog.Uri.QueryData();
query.set('model', typeof(model) == "object" ? goog.json.serialize(model) : model);
query.set('item', typeof(item) == "object" ? goog.json.serialize(item) : item);
/** @type {function(Object)} */
var on_http_success = function(result_obj)
{
on_success(result_obj['get_item_meta_data']);
}
this._send_http_request(full_url,
http_method,
query,
false,
on_http_success,
on_failure);
};
/**
* @param {string} session_id
* @param {function(Object)} on_success
* @param {function(Error)} on_failure
*/
spv.vds.ipprot.IpadClient.prototype.loan_get_current_loan = function(
session_id,
on_success,
on_failure)
{
var full_url = this._service_url + '/' + this._api_name + '/loan_get_current_loan';
var http_method = 'GET';
var query = new goog.Uri.QueryData();
query.set('session_id', typeof(session_id) == "object" ? goog.json.serialize(session_id) : session_id);
/** @type {function(Object)} */
var on_http_success = function(result_obj)
{
on_success(result_obj['loan_get_current_loan']);
}
this._send_http_request(full_url,
http_method,
query,
false,
on_http_success,
on_failure);
};
/**
* @param {string} session_id
* @param {function(Object)} on_success
* @param {function(Error)} on_failure
*/
spv.vds.ipprot.IpadClient.prototype.loan_reset = function(
session_id,
on_success,
on_failure)
{
var full_url = this._service_url + '/' + this._api_name + '/loan_reset';
var http_method = 'POST';
var query = new goog.Uri.QueryData();
query.set('session_id', typeof(session_id) == "object" ? goog.json.serialize(session_id) : session_id);
/** @type {function(Object)} */
var on_http_success = function(result_obj)
{
on_success(result_obj['loan_reset']);
}
this._send_http_request(full_url,
http_method,
query,
false,
on_http_success,
on_failure);
};
/**
* @param {string} session_id
* @param {number} down_payment
* @param {number} interest_rate
* @param {number} number_of_months
* @param {function(Object)} on_success
* @param {function(Error)} on_failure
*/
spv.vds.ipprot.IpadClient.prototype.loan_set_loan_paramters = function(
session_id,
down_payment,
interest_rate,
number_of_months,
on_success,
on_failure)
{
var full_url = this._service_url + '/' + this._api_name + '/loan_set_loan_paramters';
var http_method = 'POST';
var query = new goog.Uri.QueryData();
query.set('session_id', typeof(session_id) == "object" ? goog.json.serialize(session_id) : session_id);
query.set('down_payment', typeof(down_payment) == "object" ? goog.json.serialize(down_payment) : down_payment);
query.set('interest_rate', typeof(interest_rate) == "object" ? goog.json.serialize(interest_rate) : interest_rate);
query.set('number_of_months', typeof(number_of_months) == "object" ? goog.json.serialize(number_of_months) : number_of_months);
/** @type {function(Object)} */
var on_http_success = function(result_obj)
{
on_success(result_obj['loan_set_loan_paramters']);
}
this._send_http_request(full_url,
http_method,
query,
false,
on_http_success,
on_failure);
};
/**
* @param {string} session_id
* @param {string} feed_id
* @param {function(spv.vds.ipprot.volvocampaigns.CampaignCollection)} on_success
* @param {function(Error)} on_failure
*/
spv.vds.ipprot.IpadClient.prototype.vcamp_get_campaigns = function(
session_id,
feed_id,
on_success,
on_failure)
{
var full_url = this._service_url + '/' + this._api_name + '/vcamp_get_campaigns';
var http_method = 'GET';
var query = new goog.Uri.QueryData();
query.set('session_id', typeof(session_id) == "object" ? goog.json.serialize(session_id) : session_id);
query.set('feed_id', typeof(feed_id) == "object" ? goog.json.serialize(feed_id) : feed_id);
/** @type {function(Object)} */
var on_http_success = function(result_obj)
{
on_success(result_obj['vcamp_get_campaigns']);
}
this._send_http_request(full_url,
http_method,
query,
false,
on_http_success,
on_failure);
};
/**
* @param {string} session_id
* @param {Function} on_success
* @param {function(Error)} on_failure
*/
spv.vds.ipprot.IpadClient.prototype.vcomp_disable_company_car_prices = function(
session_id,
on_success,
on_failure)
{
var full_url = this._service_url + '/' + this._api_name + '/vcomp_disable_company_car_prices';
var http_method = 'POST';
var query = new goog.Uri.QueryData();
query.set('session_id', typeof(session_id) == "object" ? goog.json.serialize(session_id) : session_id);
/** @type {function(Object)} */
var on_http_success = function(result_obj)
{
on_success();
}
this._send_http_request(full_url,
http_method,
query,
true,
on_http_success,
on_failure);
};
/**
* @param {string} session_id
* @param {Function} on_success
* @param {function(Error)} on_failure
*/
spv.vds.ipprot.IpadClient.prototype.vcomp_enable_company_car_prices = function(
session_id,
on_success,
on_failure)
{
var full_url = this._service_url + '/' + this._api_name + '/vcomp_enable_company_car_prices';
var http_method = 'POST';
var query = new goog.Uri.QueryData();
query.set('session_id', typeof(session_id) == "object" ? goog.json.serialize(session_id) : session_id);
/** @type {function(Object)} */
var on_http_success = function(result_obj)
{
on_success();
}
this._send_http_request(full_url,
http_method,
query,
true,
on_http_success,
on_failure);
};
/**
* @param {string} session_id
* @param {Object.<string, Object>} input_params
* @param {function(Object)} on_success
* @param {function(Error)} on_failure
*/
spv.vds.ipprot.IpadClient.prototype.vcomp_update_input_params = function(
session_id,
input_params,
on_success,
on_failure)
{
var full_url = this._service_url + '/' + this._api_name + '/vcomp_update_input_params';
var http_method = 'POST';
var query = new goog.Uri.QueryData();
query.set('session_id', typeof(session_id) == "object" ? goog.json.serialize(session_id) : session_id);
query.set('input_params', typeof(input_params) == "object" ? goog.json.serialize(input_params) : input_params);
/** @type {function(Object)} */
var on_http_success = function(result_obj)
{
on_success(result_obj['vcomp_update_input_params']);
}
this._send_http_request(full_url,
http_method,
query,
false,
on_http_success,
on_failure);
};
/**
* @param {string} session_id
* @param {Object} input_params
* @param {function(Object)} on_success
* @param {function(Error)} on_failure
*/
spv.vds.ipprot.IpadClient.prototype.vcomp_update_input_params_2 = function(
session_id,
input_params,
on_success,
on_failure)
{
var full_url = this._service_url + '/' + this._api_name + '/vcomp_update_input_params_2';
var http_method = 'POST';
var query = new goog.Uri.QueryData();
query.set('session_id', typeof(session_id) == "object" ? goog.json.serialize(session_id) : session_id);
query.set('input_params', typeof(input_params) == "object" ? goog.json.serialize(input_params) : input_params);
/** @type {function(Object)} */
var on_http_success = function(result_obj)
{
on_success(result_obj['vcomp_update_input_params_2']);
}
this._send_http_request(full_url,
http_method,
query,
false,
on_http_success,
on_failure);
};
/**
* @param {function(Array.<spv.vds.ipprot.volvoboosterweb.VolvoRetailer>)} on_success
* @param {function(Error)} on_failure
*/
spv.vds.ipprot.IpadClient.prototype.vret_get_retailers = function(
on_success,
on_failure)
{
var full_url = this._service_url + '/' + this._api_name + '/vret_get_retailers';
var http_method = 'GET';
var query = new goog.Uri.QueryData();
/** @type {function(Object)} */
var on_http_success = function(result_obj)
{
on_success(result_obj['vret_get_retailers']);
}
this._send_http_request(full_url,
http_method,
query,
false,
on_http_success,
on_failure);
};
/**
* @param {string} ids
* @param {function(Array.<spv.vds.ipprot.volvoboosterweb.VolvoRetailer>)} on_success
* @param {function(Error)} on_failure
*/
spv.vds.ipprot.IpadClient.prototype.vret_get_retailers_by_ids = function(
ids,
on_success,
on_failure)
{
var full_url = this._service_url + '/' + this._api_name + '/vret_get_retailers_by_ids';
var http_method = 'GET';
var query = new goog.Uri.QueryData();
query.set('ids', typeof(ids) == "object" ? goog.json.serialize(ids) : ids);
/** @type {function(Object)} */
var on_http_success = function(result_obj)
{
on_success(result_obj['vret_get_retailers_by_ids']);
}
this._send_http_request(full_url,
http_method,
query,
false,
on_http_success,
on_failure);
};
/**
* @param {string} session_id
* @param {string} customer_first_name
* @param {string} customer_surname
* @param {string} customer_email
* @param {string} customer_phone
* @param {string} preferred_contact_time
* @param {string} preferred_contact_media
* @param {boolean} want_newsletter
* @param {boolean} want_summary_pdf
* @param {string} retailer_id
* @param {function(spv.vds.ipprot.volvoboosterweb.MailRequestResult)} on_success
* @param {function(Error)} on_failure
*/
spv.vds.ipprot.IpadClient.prototype.vret_send_customer_and_retailer_mail = function(
session_id,
customer_first_name,
customer_surname,
customer_email,
customer_phone,
preferred_contact_time,
preferred_contact_media,
want_newsletter,
want_summary_pdf,
retailer_id,
on_success,
on_failure)
{
var full_url = this._service_url + '/' + this._api_name + '/vret_send_customer_and_retailer_mail';
var http_method = 'POST';
var query = new goog.Uri.QueryData();
query.set('session_id', typeof(session_id) == "object" ? goog.json.serialize(session_id) : session_id);
query.set('customer_first_name', typeof(customer_first_name) == "object" ? goog.json.serialize(customer_first_name) : customer_first_name);
query.set('customer_surname', typeof(customer_surname) == "object" ? goog.json.serialize(customer_surname) : customer_surname);
query.set('customer_email', typeof(customer_email) == "object" ? goog.json.serialize(customer_email) : customer_email);
query.set('customer_phone', typeof(customer_phone) == "object" ? goog.json.serialize(customer_phone) : customer_phone);
query.set('preferred_contact_time', typeof(preferred_contact_time) == "object" ? goog.json.serialize(preferred_contact_time) : preferred_contact_time);
query.set('preferred_contact_media', typeof(preferred_contact_media) == "object" ? goog.json.serialize(preferred_contact_media) : preferred_contact_media);
query.set('want_newsletter', typeof(want_newsletter) == "object" ? goog.json.serialize(want_newsletter) : want_newsletter);
query.set('want_summary_pdf', typeof(want_summary_pdf) == "object" ? goog.json.serialize(want_summary_pdf) : want_summary_pdf);
query.set('retailer_id', typeof(retailer_id) == "object" ? goog.json.serialize(retailer_id) : retailer_id);
/** @type {function(Object)} */
var on_http_success = function(result_obj)
{
on_success(result_obj['vret_send_customer_and_retailer_mail']);
}
this._send_http_request(full_url,
http_method,
query,
false,
on_http_success,
on_failure);
};
/**
* @param {string} session_id
* @param {string} customer_email
* @param {boolean} want_newsletter
* @param {boolean} want_summary_pdf
* @param {function(spv.vds.ipprot.volvoboosterweb.MailRequestResult)} on_success
* @param {function(Error)} on_failure
*/
spv.vds.ipprot.IpadClient.prototype.vret_send_customer_mail = function(
session_id,
customer_email,
want_newsletter,
want_summary_pdf,
on_success,
on_failure)
{
var full_url = this._service_url + '/' + this._api_name + '/vret_send_customer_mail';
var http_method = 'POST';
var query = new goog.Uri.QueryData();
query.set('session_id', typeof(session_id) == "object" ? goog.json.serialize(session_id) : session_id);
query.set('customer_email', typeof(customer_email) == "object" ? goog.json.serialize(customer_email) : customer_email);
query.set('want_newsletter', typeof(want_newsletter) == "object" ? goog.json.serialize(want_newsletter) : want_newsletter);
query.set('want_summary_pdf', typeof(want_summary_pdf) == "object" ? goog.json.serialize(want_summary_pdf) : want_summary_pdf);
/** @type {function(Object)} */
var on_http_success = function(result_obj)
{
on_success(result_obj['vret_send_customer_mail']);
}
this._send_http_request(full_url,
http_method,
query,
false,
on_http_success,
on_failure);
};
/**
* @param {string} encoded_config
* @param {string} encoding
* @param {string} localization_id
* @param {function(spv.vds.ipprot.specification.VolvoCarSpecification)} on_success
* @param {function(Error)} on_failure
*/
spv.vds.ipprot.IpadClient.prototype.vspec_get_specification = function(
encoded_config,
encoding,
localization_id,
on_success,
on_failure)
{
var full_url = this._service_url + '/' + this._api_name + '/vspec_get_specification';
var http_method = 'GET';
var query = new goog.Uri.QueryData();
query.set('encoded_config', typeof(encoded_config) == "object" ? goog.json.serialize(encoded_config) : encoded_config);
query.set('encoding', typeof(encoding) == "object" ? goog.json.serialize(encoding) : encoding);
query.set('localization_id', typeof(localization_id) == "object" ? goog.json.serialize(localization_id) : localization_id);
/** @type {function(Object)} */
var on_http_success = function(result_obj)
{
on_success(result_obj['vspec_get_specification']);
}
this._send_http_request(full_url,
http_method,
query,
false,
on_http_success,
on_failure);
};
/**
* @private
* @param {goog.Uri.QueryData} query
* @return {string}
*/
spv.vds.ipprot.IpadClient.makeSpecialQueryString = function (query)
{
var result = '';
var keys = query.getKeys();
for (var i = 0; i < keys.length; i++)
{
if (0 != i)
{
result += '&';
}
var key = keys[i];
var val = query.get(key, '').toString();
var val_enc = encodeURIComponent(val);
result += keys[i] + '=' + val_enc;
}
return result;
}
/**
* @private
* @param {goog.net.XhrIo} xhr
*/
spv.vds.ipprot.IpadClient.getProtocolErrorMessage = function(xhr)
{
var mess = 'protocol error: ' + xhr.getStatusText();
mess += ', ' + xhr.getResponseText();
return mess;
}
/**
* @private
* @param {goog.Uri.QueryData} query
* @return {Object}
*/
spv.vds.ipprot.IpadClient.makeJsonpPayload = function(query)
{
var result = {};
var keys = query.getKeys();
for (var i = 0; i < keys.length; i++)
{
var key = keys[i];
result[key] = query.get(key);
}
var t = new Date().getTime();
result['cachebuster'] = t;
return result;
}
/**
* @private
* @param {Object} response
* @return {Error}
*/
spv.vds.ipprot.IpadClient.makeResponseError = function(response)
{
var message = 'Jsonp error: ';
var error_carrier = spv.vds.ipprot.IpadClient.getResponseErrorCarrier(response);
if (null == error_carrier)
{
message += 'no error information available';
}
else
{
message += error_carrier['message'];
}
return new Error(message);
}
/**
* @private
* @param {Object} response
* @return {Object|null}
*/
spv.vds.ipprot.IpadClient.getResponseErrorCarrier = function(response)
{
if (!response)
{
return null;
}
if (!response['error'])
{
return null;
}
return response['error'];
}
/**
* @private
* @param {Object} response
* @return {boolean}
*/
spv.vds.ipprot.IpadClient.hasErrorCarrier = function(response)
{
return null != spv.vds.ipprot.IpadClient.getResponseErrorCarrier(response);
}
/**
* @private
* @param {string} url
* @param {string} http_method
* @param {goog.Uri.QueryData} query
* @param {boolean} return_is_void
* @param {function(Object)} on_success
* @param {function(Error)} on_failure
*/
spv.vds.ipprot.IpadClient.sendJsonHttpRequest = function(
url,
http_method,
query,
return_is_void,
on_success,
on_failure)
{
var cbk = function(e)
{
try
{
/** @type {goog.net.XhrIo} */
var xhr = e.target;
if (!xhr.isSuccess())
{
var mess = spv.vds.ipprot.IpadClient.getProtocolErrorMessage(xhr);
throw new Error(mess);
}
if (return_is_void)
{
on_success(null);
return;
}
var obj = xhr.getResponseJson();
if (obj == undefined)
{
throw new Error('http response is undefined');
}
on_success(obj);
}
catch (response_err)
{
on_failure(response_err);
}
};
if('POST' == http_method || 'GET' == http_method)
{
var body_query = spv.vds.ipprot.IpadClient.makeSpecialQueryString(query);
goog.net.XhrIo.send(url, cbk, 'POST', body_query);
}
else
{
throw new Error('Method not supported: ' + http_method);
}
};
/**
* @private
* @param {string} url
* @param {string} http_method
* @param {goog.Uri.QueryData} query
* @param {boolean} return_is_void
* @param {function(Object)} on_success
* @param {function(Error)} on_failure
*/
spv.vds.ipprot.IpadClient.sendJsonpHttpRequest = function(
url,
http_method,
query,
return_is_void,
on_success,
on_failure)
{
var on_jsonp_reply = function (response)
{
try
{
if (spv.vds.ipprot.IpadClient.hasErrorCarrier(response))
{
var err = spv.vds.ipprot.IpadClient.makeResponseError(response);
throw err;
}
if (return_is_void)
{
on_success(null);
return;
}
on_success(response);
}
catch (response_err)
{
on_failure(response_err);
}
};
var on_jsonp_error = function(response)
{
var jsonp_error = spv.vds.ipprot.IpadClient.makeResponseError(response);
on_failure(jsonp_error);
};
var payload = spv.vds.ipprot.IpadClient.makeJsonpPayload(query);
var jp = new goog.net.Jsonp(url);
var timeout_ms = 60 * 1000 * 10;
jp.setRequestTimeout(timeout_ms);
jp.send(payload, on_jsonp_reply, on_jsonp_error);
};