Hello, I am begginer with ciq sdk and trying to make this app work with SDK 1.2.1:
https://github.com/danielsiwiec/waypoints-app
This is the code in question:
class Http {
function _req(url, params, options, callback) {
if (Comms has :makeWebRequest ) {
Comms.makeWebRequest(url, params, options, callback);
} else if (Comms has :makeJsonRequest ) {
Comms.makeJsonRequest(url, params, options, callback);
} else {
throw new Toybox.Lang.Exception("No Communication API");
}
}
function get(url, callback) {
var options = {
:method => Comms.HTTP_REQUEST_METHOD_GET,
:responseType => Comms.HTTP_RESPONSE_CONTENT_TYPE_JSON
};
_req(url, null, options, callback);
}
function post(url, body, callback) {
var options = {
:method => Comms.HTTP_REQUEST_METHOD_POST,
:responseType => Comms.HTTP_RESPONSE_CONTENT_TYPE_TEXT_PLAIN
};
_req(url, body, options, callback);
}
}
class HashView extends Ui.View {
var text;
var http;
var locationStore;
var analytics;
function initialize() {
View.initialize();
http = new Http();
locationStore = new LocationStore();
analytics = new Analytics();
}
function callback(responseCode, data){
if (responseCode == 200) {
var lat = data["geo"]["lat"];
var long = data["geo"]["long"];
var name = data["name"];
var location = new Position.Location({:latitude => lat, :longitude => long, :format => :degrees});
text = "Location\n" + name + "\nadded.";
try {
locationStore.save(location, {:name => name});
} catch (ex) {
System.println(ex.getErrorMessage());
text = "No wypt API";
}
} else {
text = "Comms error or \nwrong hash";
}
WatchUi.requestUpdate();
}
Problem is all response content types are from 1.3.0 onward.
If I remove response type from code app gets wrong response code and goes to this line.
"Comms error or \nwrong hash";
function post(url, body, callback) {
var options = {
:method => Comms.HTTP_REQUEST_METHOD_POST,
:responseType => Comms.HTTP_RESPONSE_CONTENT_TYPE_TEXT_PLAIN
};
_req(url, body, options, callback);
}
Any way around this, using only available makeJsonRequest?
Thanks,
Igor.