i use reste library to handle api on titanium appcelerator :
this is my config :
api.config({
debug : true,
autoValidateParams : false,
validatesSecureCertificate : false,
timeout : 4000,
url : Kb.baseUrl,
models: [{
name: "product",
id: "id",
//content: "retArray",
collections: [{
name: "products",
content: "response",
read: "get_products"
}],
}],
methods : [
{
name : "get_products",
post : "api/get_product"
}
],
...
So this how i fetch (works perfectly) :
var p = Alloy.Collections.get_products;
p.fetch({
success:function(m,r){
console.log(r)
}
});
Now i have to past object to post (this not working, why?) :
p.fetch({
data:{'id':'2'},
success:function(m,r){ console.log(r); }
});
This second fetch not working, have you an idea ?
thanks.
In your config you're not specifying what to do with the id parameter. RESTe doesn't know (or care) about your API -- i.e if it's REST / PUT, GET based or POST, GET etc. So you need to tell it.
Change your method to:
{
name : "get_products",
post : "api/get_product/<id>"
}
and it should work fine. The flexibility here allows RESTe to work with APIs that don't conform to the normal REST pattern so if it required say:
"api/get_product?id=<id>"
for example.
Related
With the latest Sony Camera API, I'm able to get a list of the contents on the memory card. When I'm trying to download the images using a GET request, I'm getting a 500 error without any descriptive error messages.
I believe there might be something wrong with the URL I'm using for the get request.
This is the first result part of the JSON response from getContentList
{ "id" : 12, "result" : [
[
{
"isPlayable" : "false",
"content" : {
"thumbnailUrl" : "http:\/\/192.168.122.1:8080\/contentstransfer\/thumb\/index%3A%2F%2F1000%2F00000001-default%2F00000044-00000AF2_68_1_1000",
"original" : [
{
"stillObject" : "raw",
"url" : "http:\/\/192.168.122.1:8080\/contentstransfer\/orgraw\/index%3A%2F%2F1000%2F00000001-default%2F00000044-00000AF2_68_1_1000",
"fileName" : "_DSC7790.ARW"
}
],
"smallUrl" : "http:\/\/192.168.122.1:8080\/contentstransfer\/vga\/index%3A%2F%2F1000%2F00000001-default%2F00000044-00000AF2_68_1_1000",
"largeUrl" : "http:\/\/192.168.122.1:8080\/contentstransfer\/scn\/index%3A%2F%2F1000%2F00000001-default%2F00000044-00000AF2_68_1_1000"
},
"fileNo" : "7790",
"isBrowsable" : "false",
"isProtected" : "",
"title" : "",
"contentKind" : "still",
"createdTime" : "2017-01-12T13:49:00-08:00",
"folderNo" : "100",
"uri" : "image:content?contentId=index%3A%2F%2F1000%2F00000001-default%2F00000044-00000AF2_68_1_1000"
},
The url is encoded, but when I decode it I'm getting this for the thumbnailUrl:
http://192.168.122.1:8080/contentstransfer/thumb/index://1000/00000001-default/00000043-00000AF0_67_1_1000
Of course that is giving me a 500 error, but I believe the characters after thumb must be some URL for the camera to internally parse. So instead I'm just removing the back slashes to get this:
http://192.168.122.1:8080/contentstransfer/thumb/index%3A%2F%2F1000%2F00000001-default%2F00000043-00000AF0_67_1_1000
This still also gives me a 500 error. I'm not sure how else I'm supposed to use this URL. All the API documentation and references just say do a GET request, but the URL that comes in the JSON is not working.
I can only spoke for me: I want video-data instead of thumbnail-data and I just used the url as given through their "result" JSON-Object and I got no problems. For me this looks like this:
http://192.168.122.1:8080/contentstransfer/org/index%3A%2F%2F1000%2F00000100-default%2F00000047-00000C3D_71_256_1000
I want to use API to get the available OS list during OSReload.
I found the method SoftLayer_Account::getOperatingSystemReloadImages is mentioned.But cannot find the usage about this method.
Who can help me on this?
Thanks.
I was not able to find this method getOperatingSystemReloadImages. But I found a way to get OS reload options:
First, we need to know the package used to order the server. For example for Virtual Guests, the package used is 46. But if you want to confirm this, please execute the following Rest request:
https://[username]:[apikey]#api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/[vsi_id]/getBillingItem?objectMask=mask[package]
Method: GET
Then, to get ”Reload options”, execute:
https://[username]:[apikey]#api.softlayer.com/rest/v3/SoftLayer_Product_Package/46/getItemPrices?objectFilter={ "itemPrices": { "categories": { "categoryCode": { "operation": "os" } } } }&objectMask=mask[id,item[softwareDescription], categories[categoryCode]]
Method: GET
References:
SoftLayer_Virtual_Guest::getBillingItem
SoftLayer_Product_Package::getItemPrices
EDIT:
Now, in order to use ” SoftLayer_Virtual_Guest::reloadOperatingSystem”, we need add some parameters in Json body configuration: “token” and “config” (Ref: SoftLayer_Virtual_Guest::reloadOperatingSystem)
Below is a REST example:
URL:
https://[username]:[apikey]#api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/[virtual_Guest_ID]/reloadOperatingSystem
Method: POST
Json:
{
"parameters": [
"FORCE",
{
"itemPrices": [
{
"id": 45466
}
]
}
]
}
Where: 45466 is the new priceId of the OS
See this example to reload OS https://gist.github.com/softlayer/407058
I'm in the process of writing a node wrapper for RavenDB.
I'm using version 3 but as there are no HTTP docs for it, I've been relying on the 2.0 and 2.5 docs.
In regards to single document operations, I've used this doc page successfully for PUTs, DELETEs and multiple PATCHs to individual documents.
Similarly, I've used this doc page successfully for multiple PUTs and DELETEs of several documents in one HTTP call but the docs are a bit vague in regards to PATCHing mutliple documents in one call.
Under the "Batching Requests" heading, it clearly states it's possible:
Request batching in RavenDB is handled using the '/bulk_docs' endpoint, which accepts an array of operations to execute. The format for the operations is:
method - PUT, PATCH or DELETE.
...
For PUTs, I POST to /bulk_docs:
[
{
Method: 'PUT',
Key: 'users/1',
Document: { username: 'dummy' }
Metadata: { 'Raven-Entity-Type': 'Users' }
},
...
]
For DELETEs, I POST to /bulk_docs:
[
{
Method: 'DELETE',
Key: 'users/1'
},
...
]
For PATCHs, I've tried POSTing the following without any luck:
[
{
Method: 'PATCH',
Key: 'users/1',
Document: {
Type: 'Set',
Name:'username',
Value: 'new-username'
}
},
...
]
and
[
{
Method: 'PATCH',
Key: 'users/1',
Type: 'Set',
Name:'username',
Value: 'new-username'
},
...
]
All I'm getting back is 500 - Internal Server Error and without any examples of PATCHing multiple documents on that docs page I'm kind of stuck...
Any help would be appreciated :)
The structure for PATCH is :
[
{
Method: 'PATCH',
Key: 'users/1',
Patches: [{
Type: 'Set',
Name:'username',
Value: 'new-username'
}]
},
...
]
The full structure can be see here:
https://github.com/ayende/ravendb/blob/master/Raven.Abstractions/Commands/PatchCommandData.cs#L72
I have enabled the nativeOptions: {capture: true} in initOptions.js
logger : {enabled: true, level: 'debug', stringify: true, pretty: false,
tag: {level: false, pkg: true}, whitelist: [], blacklist: [], nativeOptions: {capture: true}}
In my main js file i have the following code.
function wlCommonInit(){
// Common initialization code goes here
WL.Logger.setNativeOptions({'capture': true});
var logger = WL.Logger.create({pkg: 'mypackage'});
logger.debug('Hello world - debug');
//[mypackage] Hello world
logger.log('Hello world - log');
//[mypackage] Hello world
logger.info('Hello world - info');
//[mypackage] Hello world
logger.warn('Hello world - warn');
//[mypackage] Hello world
logger.error('Hello world - error');
//[mypackage] Hello world
WL.Logger.send(); }
WL.Logger.send() suppose to call my adapter "WLClientLogReceiver". But i am not getting any call for this adapter.
Please let me know, i need to enable any other settings to upload my client side captured log to server.
function log(deviceInfo, logMessages) {
return true;}
<procedure name="log" securityTest="wl_unprotected" audit="true" />
logger : {enabled: true, level: 'debug', stringify: true, pretty: false, tag: {level: false, pkg: true}, whitelist: [], blacklist: [], nativeOptions: {capture: true}}
You have enabled the native capture as true in initOptions.js so no need to set it again.
You can log using your package that will help you in filtering the messages based on the package in your WLClientLogReceiver adapter.
var myloggerObject = WL.Logger.create({pkg: 'mypackage'});
myloggerObject.debug("Hello world");
you can specify your level in your js file to be logged in client device.
In the adapter you will get the log messages as an json array.
function log(deviceInfo, logMessages) {
/* The adapter can choose to process the parameters,
for example to forward them to a backend server for
safekeeping and further analysis.
The deviceInfo object may look like this:
{
"appName": "wlapp",
"appVersion": "1.0",
"deviceId": "66eed0c9-ecf7-355f-914a-3cedac70ebcc",
"model": "Galaxy Nexus - 4.2.2 - API 17 - 720x1280",
"systemName": "Android",
"systemVersion": "4.2.2",
"os.arch": "i686", // Android only
"os.version": "3.4.0-qemu+" // Android only
}
The logMessages parameter is a JSON array
that contains JSON object elements, and might look like this:
[{
"timestamp" : "17-02-2013 13:54:23:745", // "dd-MM-yyyy hh:mm:ss:S"
"level" : "ERROR", // ERROR||WARN||INFO||LOG|| DEBUG
"package" : "your_tag", // typically a class name
"msg" : "the message", // a helpful log message
"threadid" : 42, // (Android only)the current thread
"metadata" : { "$src" : "js" } // metadata placed on the log call
}]
*/
//sample log and filtering method
var logs= [{
"timestamp" : "17-02-2013 13:54:23:745", // "dd-MM-yyyy hh:mm:ss:S"
"level" : "ERROR", // ERROR||WARN||INFO||LOG|| DEBUG
"package" : "your_tag", // typically a class name
"msg" : "the message", // a helpful log message
"threadid" : 42, // (Android only)the current thread
"metadata" : { "$src" : "js" } // metadata placed on the log call
},
{
"timestamp" : "17-02-2013 13:54:23:745", // "dd-MM-yyyy hh:mm:ss:S"
"level" : "ERROR", // ERROR||WARN||INFO||LOG|| DEBUG
"package" : "mypackage", // typically a class name
"msg" : "my package message", // a helpful log message
"threadid" : 42, // (Android only)the current thread
"metadata" : { "$src" : "js" } // metadata placed on the log call
}
];
var filteredLogs = logs.filter(function(log){
if(log.package == mypackage) //comparing the package and returns the object
{ return log; }
});
WL.Logger.error(filteredLogs);// This is send only the filtered array to your server
}
If you log using metadata such as filename along with the debug message you will get those in the array in metadata attribute.
It is suggested to stringify and parse the object to avoid errors before parsing the device logs in the adapter.
var logs = JSON.stringify(JSON.parse(logs));
var filteredLogs = logs.filter ...
Hope this will work for you.
Make sure you test it using the device.
The send function is not attached to the LogInstance prototype, which is what you're using when you use a logger instance created with WL.Logger.create(). Please call
WL.Logger.send();
instead.
(Above was posted prior to OP's edit.)
Since setNativeOptions is an asynchronous call (it calls down through a Cordova plugin), it is possible it has not successfully turned capture on prior to completion of the subsequent logger calls. So at the time of the call to WL.Logger.send(); nothing has been collected yet.
Do this:
function wlCommonInit() {
// Common initialization code goes here
WL.Logger.setNativeOptions({'capture': true})
.then(function() {
var logger = WL.Logger.create({pkg: 'mypackage'});
logger.debug('Hello world - debug');
//[mypackage] Hello world
logger.log('Hello world - log');
//[mypackage] Hello world
logger.info('Hello world - info');
//[mypackage] Hello world
logger.warn('Hello world - warn');
//[mypackage] Hello world
logger.error('Hello world - error');
//[mypackage] Hello world
WL.Logger.send();
});
}
Be sure to check the server-side logs. The audit="true" in the adapter's descriptor file will print the parameters passed to the adapter inline in the server logs (messages.log on WebSphere Liberty).
Is there a way to output the json-string read by my store in sencha touch 2?
My store is not reading the records so I'm trying to see where went wrong.
My store is defined as follows:
Ext.define("NotesApp.store.Online", {
extend: "Ext.data.Store",
config: {
model: 'NotesApp.model.Note',
storeId: 'Online',
proxy: {
type: 'jsonp',
url: 'http://xxxxxx.com/qa.php',
reader: {
type: 'json',
rootProperty: 'results'
}
},
autoLoad: false,
listeners: {
load: function() {
console.log("updating");
// Clear proxy from offline store
Ext.getStore('Notes').getProxy().clear();
console.log("updating1");
// Loop through records and fill the offline store
this.each(function(record) {
console.log("updating2");
Ext.getStore('Notes').add(record.data);
});
// Sync the offline store
Ext.getStore('Notes').sync();
console.log("updating3");
// Remove data from online store
this.removeAll();
console.log("updated");
}
},
fields: [
{
name: 'id'
},
{
name: 'dateCreated'
},
{
name: 'question'
},
{
name: 'answer'
},
{
name: 'type'
},
{
name: 'author'
}
]
}
});
you may get all the data returned by the server through the proxy, like this:
store.getProxy().getReader().rawData
You can get all the data (javascript objects) returned by the server through the proxy as lasaro suggests:
store.getProxy().getReader().rawData
To get the JSON string of the raw data (the reader should be a JSON reader) you can do:
Ext.encode(store.getProxy().getReader().rawData)
//or if you don't like 'shorthands':
Ext.JSON.encode(store.getProxy().getReader().rawData)
You can also get it by handling the store load event:
// add this in the store config
listeners: {
load: function(store, records, successful, operation, eOpts) {
operation.getResponse().responseText
}
}
As far as I know, there's no way to explicitly observe your response results if you are using a configured proxy (It's obviously easy if you manually send a Ext.Ajax.request or Ext.JsonP.request).
However, you can still watch your results from your browser's developer tools.
For Google Chrome:
When you start your application and assume that your request is completed. Switch to Network tab. The hightlighted link on the left-side panel is the API url from which I fetched data. And on the right panel, choose Response. The response result will appear there. If you have nothing, it's likely that you've triggered a bad request.
Hope this helps.
Your response json should be in following format in Ajax request
{results:[{"id":"1", "name":"note 1"},{"id":"2", "name":"note 2"},{"id":"3", "name":"note 3"}]}
id and name are properties of your model NOte.
For jsonp,
in your server side, get value from 'callback'. that value contains a name of callback method. Then concat that method name to your result string and write the response.
Then the json string should be in following format
callbackmethod({results:[{"id":"1", "name":"note 1"},{"id":"2", "name":"note 2"},{"id":"3", "name":"note 3"}]});