Restkit 20 failed to match all (0) response descriptors - restkit-0.20

I don't know if failed to match all (0) response descriptors means there are 0 descriptors?
Here are some logs:
PATH:
search/patients?q=qwer&start=0&max=40
BASE URL:
https://amb.XXX.com/
RKRESPONSEDESCRIPTORS:
(
"<RKResponseDescriptor: 0xaaca6a0 method=(GET) pathPattern=search/patients?q=qwer&start=0&max=40 keyPath=(null) statusCodes=(null) : <RKObjectMapping:0xaab4f80 objectClass=NSMutableDictionary propertyMappings=(\n \"<RKAttributeMapping: 0x9edf630 final_page => finalPage>\",\n \"<RKRelationshipMapping: 0xaac9750 results => patientSearchResultDetails>\"\n)>>"
)
restkit.object_mapping:RKMapperOperation.m:378 Executing mapping operation for representation: {
"final_page" = 1;
results = (
{
age = "39 years";
"date_of_birth" = "1975-01-15";
gender = Male;
mrns = {
effective = (
10000423
);
ineffective = (
);
};
"name_full_formatted" = "DOE, PETER";
"person_id" = 1390007;
"phone_numbers" = {
home = "(816) 555-5555";
};
"preferred_name" = PETE;
"primary_care_provider" = {
name = "Test, Physician4";
};
}
);
}
and targetObject: (null)
2014-04-16 12:45:03.263 IONShell[31463:4f03] D restkit.object_mapping:RKMapperOperation.m:404 Finished performing object mapping. Results: (null)
2014-04-16 12:45:03.264 IONShell[31463:4e1b] E restkit.network:RKObjectRequestOperation.m:208 GET 'https://amb.XXX.com/search/patients?q=qwer&start=0&max=40' (200 OK / 0 objects) [request=1.5086s mapping=0.0000s total=1.5143s]:
error=Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No response descriptors match the response loaded." UserInfo=0xa9eead0 {NSErrorFailingURLStringKey=https://amb.XXX.com/search/patients?q=qwer&start=0&max=40, NSLocalizedFailureReason=A 200 response was loaded from the URL 'https://amb.XXX.com/search/patients?q=qwer&start=0&max=40', which failed to match all (0) response descriptors:, NSLocalizedDescription=No response descriptors match the response loaded., keyPath=null, NSErrorFailingURLKey=https://amb.XXX.com/search/patients?q=qwer&start=0&max=40, NSUnderlyingError=0xa9e3f40 "No mappable object representations were found at the key paths searched."}
Does (0) mean my RKObjectManager has no response descriptors? Or am I missing something else? This is driving me nuts.
thanks

Figure it out. I needed to send down the query part of the string as params.
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:queryString, #"q", start, #"start", maxCount, #"max", nil];
[self loadObjectsAtResourcePath:#"search/patients" params:params objectMapping:mapping]

Related

Fetching error message in Mule 4 not working

I run the code in debug mode and realized that external service is returning me error message below error message is coming in the path
error.exception.cause.errorMessage.typedValue.value
Its value is as below.
typedValue.value = {"status"":"Bad Request", "message":"Invalid data"}
I want to get the message "Invalid data" in var.
My code is as follows
output application/java
var adminEmail = vars.adminEmail
var salesRepEmail = if (!isEmpty(vars.InitialRequest.Application.PreliminaryQuestions.SalesRepresentative.EmailAddress))
[vars.InitialRequest.Application.PreliminaryQuestions.SalesRepresentative.EmailAddress]
else
p('emailNotifications.nonStarterNotification.defaultEmail') splitBy(",")
var declineReason = error.exception.cause.errorMessage.typedValue.value
I have tried
var declineReason = if(error == null) vars.errorDescription else (error.exception.cause.errorMessage.typedValue.value default "Bad request") as String
Also tried
var declineReason = if(error == null) vars.errorDescription else flatten(error.exception.cause.errorMessage.typedValue.value.message)
error.exception.cause.errorMessage.typedValue.value returns null.

poloniex API request BUY SELL CANCEL cause error = "Invalid API key/secret pair.";

Hello To every one I am writing in swift 3 trading app. I have problem only with 3 commands buy sell and cancel , that ones cause error = "Invalid API key/secret pair."; others like returnOpenOrders , returnTradehistory returnBalances works fine and returns proper values.
That is may request function :
func getRawJSON(paramss:[String : Any]){
var paramss1:[String:Any] = [:]
let APIURL = "https://poloniex.com/tradingApi"
let timeNowInt = Int(NSDate().timeIntervalSince1970 ) * 10000000
var zdanie2:String! = ""
for (x,y) in paramss{
paramss1[x]=y
}
paramss1["nonce"]=timeNowInt
for (x,y) in paramss{
if (zdanie2 == "")
{zdanie2="\(x)=\(y)"
}
else
{
zdanie2=zdanie2+"&"+"\(x)=\(y)"
}
}
zdanie2=zdanie2+"&nonce=\(timeNowInt)"
let array: [UInt8] = Array(zdanie2.utf8)
let hmac: Array<UInt8> = try! HMAC(key: secretKey!.utf8.map({$0}), variant: .sha512).authenticate(array)
let hmacData = Data(bytes: hmac).toHexString()
let headers = ["Key": publicKey!,"Sign": hmacData] as [String : String]
request(APIURL,method: .post,parameters: paramss1,headers:headers).responseJSON {
response in
print(response)
print(response.request)
}
}
Here is my buy/sell function :
func buy(currencyPair:String,rate:Double,amount:Double){
return self.getRawJSON( paramss: ["command":"buy","currencyPair":currencyPair,"rate":rate ,"amount":amount])
}
func sell(currencyPair:String,rate:Double,amount:Double){
return self.getRawJSON( paramss: ["command":"sell","currencyPair":currencyPair,"rate": rate ,"amount":amount])
}
The output from headers parameters(var paramss1 ) is :
["amount": 2.0, "command": "sell", "nonce": 15308121310000000, "currencyPair": "BTC_XRP", "rate": 7.6000000000000004e-05]
The array for sign is :
amount=2.0&command=sell&currencyPair=BTC_XRP&rate=7.6e-05&nonce=15308121310000000
I really dont know what is wrong
Can you help with this problem ??
rate value is invalid.
rate and amount values must be like 1, 1.1, 1.00000001.
Invalid request:
amount=2.0&command=sell&currencyPair=BTC_XRP&rate=7.6e-05&nonce=15308121310000000
Valid request:
command=sell&amount=2.0&&currencyPair=BTC_XRP&rate=7.000006&nonce=15308121310000000

How do I properly return as JSON-ified version of Parse object?

I'm hitting a custom function on my server, getting a PFObject in my Convos objects and returning that object from JS, which results in this string in my Objective-C code:
"<convos: 0x6080002ae220, objectId: e1VYAIFCyQ, localId: (null)> {
\n buyerDeleted = NO;\n buyerId = NNfjWZrk8r;\n buyerPicture = \"<PFFile: 0x60800065de80>\";\n buyerSentMessage = YES;\n buyerSentTwoMessages = YES;\n buyerUnseen = 0;\n buyerUser = \"<PFUser: 0x6080002f1900, objectId: NNfjWZrk8r, localId: (null)>\";\n buyerUsername = corby;\n convoId = bQLQWNEtwmNNfjWZrk8r;\n lastSent = \"<messages: 0x60c0000b8600, objectId: iYVIjJ6A3q, localId: (null)>\";\n lastSentDate = \"2018-06-05 19:09:52 +0000\";\n profileConvo = YES;\n sellerDeleted = NO;\n sellerId = bQLQWNEtwm;\n sellerSentMessage = YES;\n sellerUnseen = 0;\n sellerUser = \"<PFUser: 0x6080002f1a80, objectId: bQLQWNEtwm, localId: (null)>\";\n sellerUsername = tough;\n source = profile;\n totalMessages = 3;\n
}"
I'm trying to take the convo object in my JS and run convo.toJSON() on it (which seems like the solution) and then return it but that seems to take an extremely long time.
Any tips on how to return that Parse object so that I can ultimately turn it into an NSDictionary and then a PFObject in the client?
I think we got you covered in slack, but for anyone else who finds this:
Don't use toJSON() from your server, just return the Parse.Object
In your Obj-C code, add this line to the success block of your call back:
PFObject *resultParseObject = (PFObject*)object, where object is the _Nullable id object parameter to the callback of your cloud function.

Writing a URL to an embed-field using PodioKit

I hope to find some help to diving deeper into Podiokit, the ObjC-API to Podio. I try to set a link-field's value to a URL. My first simple try looked like this:
NSDictionary *embedAttributes = [NSDictionary dictionaryWithObject: #"http://www.google.com" forKey: #"url"];
PKTEmbed *embed = [[PKTEmbed alloc] initWithDictionary: embedAttributes];
item[#"linkfield"] = embed;
I found an example using PHP but had no luck to transform it into Objective-C:
$attributes = array( 'url' => 'http://www.infranet.com' );
$embed = PodioEmbed::create( $attributes );
$attribute['embed']['embed\_id'] = $embed->embed\_id;
$attribute['file']['file\_id'] = $embed->files[0]->file\_id;
$this->orgItem->field('organizationlink')->set\_value($attribute);
Maybe someone knows how to get it right, would be fine :-)
[Edit] The PodioKit-Manual just says:
PKTEmbed *link = ...;
item[#"link"] = link;
[Edit 2] The error occurs when I try to save the item. The log says:
Error: Saving file Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: Ungültige Anforderung (400)" UserInfo=0x600000c7ee80 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x6000008358e0> { URL: https://api.podio.com/item/app/_xxxx_/ } { status code: 400, headers {
"Content-Length" = 263;
"Content-Type" = "application/json; charset=utf-8";
Date = "Sat, 27 Sep 2014 19:16:22 GMT";
Server = nginx;
"X-Podio-Request-Id" = yqyl6yku;
"X-Rate-Limit-Limit" = 250;
"X-Rate-Limit-Remaining" = 248;
} }, NSLocalizedDescription=Request failed: Ungültige Anforderung (400), NSErrorFailingURLKey=https://api.podio.com/item/app/_xxxx_/}
Thanks,
Michael / Hamburg
Sebastian at Podio here. You need to first create the PKTEmbed object server side, then use it as the value of the item field. So you would use:
PKTItem *item = ...;
[[PKTEmbed createEmbedForURLString:#"https://www.google.com"] onSuccess:^(PKTEmbed *embed) {
item[#"link-field"] = embed;
} onError:^(NSError *error) {
// Handle error
}];
The server will assign you an embedID and generate a thumbnail for you etc. I will look into adding the ability to simply provide a URL string directly, as I agree that makes a lot of sense.
Hope that helps!

Cocoa: Handling 407 http response cfnetwork

I am creating downloader application.
I am facing a problem with proxy authentication.
I am getting 407 response code i.e proxy authentication required. I have valid proxy authentication details.
Following is Code Flow:
1. Create Http request using CFHTTPMessageCreateRequest
2. Set necessary header field values like Cache-Control, Accept-Ranges, Range & User-Agent using CFHTTPMessageSetHeaderFieldValue
3. Create read stream using CFReadStreamCreateForHTTPRequest
4. Set proxy server URL & port properties on read stream using CFReadStreamSetProperty
5. Set kCFStreamPropertyHTTPShouldAutoredirect to kCFBooleanTrue using CFReadStreamSetProperty
6. open read stream using CFReadStreamOpen
7. In a loop wait for stream to get opened
while (1)
{
if (kCFStreamStatusOpen == CFReadStreamGetStatus)
{
if (CFReadStreamHasBytesAvailable)
{
Get Http response header using CFReadStreamCopyProperty
Get response code using CFHTTPMessageGetResponseStatusCode
if (200 || 206 is response code)
SUCCESS
else check if response code is 407.
}
}
}
I tried using following code
if (407 == nsiStatusCode)
{
CFStreamError err;
cfAuthentication = CFHTTPAuthenticationCreateFromResponse(NULL, cfHttpResponse);
if ((cfAuthentication) && (CFHTTPAuthenticationIsValid(cfAuthentication, &err)))
{
if (CFHTTPAuthenticationRequiresUserNameAndPassword(cfAuthentication))
{
CFHTTPMessageApplyCredentials(cfHttpRequest, cfAuthentication, (CFStringRef)pnsUserName, (CFStringRef)pnsPassword, &err);
}
}
}
but unable to make it work.
How do I handle 407 status code so as to communicate with authenticating HTTP server?
Thanks in advance.
Vaibhav.
Build a CFHTTPMessageRef
-(CFHTTPMessageRef)buildMessage
{
NSURL *myURL = [NSURL URLWithString:#"http://myurl.com"];
NSData *dataToPost = [[NSString stringWithString:#"POST Data It Doesn't Matter What It Is"] dataUsingEncoding:NSUTF8StringEncoding];
//Create with the default allocator (NULL), a post request,
//the URL, and pick either
//kCFHTTPVersion1_0 or kCFHTTPVersion1_1
CFHTTPMessageRef request = CFHTTPMessageCreateRequest(NULL, CSTR("POST"), (CFURLRef)myURL, kCFHTTPVersion1_1);
CFHTTPMessageSetBody(request, (CFDataRef)dataToPost);
//Unfortunately, this isn't smart enough to set reasonable headers for you
CFHTTPMessageSetHeaderFieldValue(request, CFSTR("HOST"), (CFStringRef)[myURL host]);
CFHTTPMessageSetHeaderFieldValue(request, CFSTR("Content-Length"), (CFStringRef)[NSString stringWithFormat:"%d", [dataToPost length]);
CFHTTPMessageSetHeaderFieldValue(request, CFSTR("Content-Type"), CFSTR("charset=utf-8"));
return [NSMakeCollectable(request) autorelease];
}
Send it to the server and read back the response
-(CFHTTPMessageRef)performHTTPRequest:(CFHTTPMessageRef)request
{
CFReadStreamRef requestStream = CFReadStreamCreateForHTTPRequest(NULL, request);
CFReadStreamOpen(requestStream);
NSMutableData *responseBytes = [NSMutableData data];
CFIndex numBytesRead = 0 ;
do
{
UInt8 buf[1024];
numBytesRead = CFReadStreamRead(requestStream, buf, sizeof(buf));
if(numBytesRead > 0)
[responseBytes appendBytes:buf length:numBytesRead];
} while(numBytesRead > 0);
CFHTTPMessageRef response = (CFHTTPMessageRef)CFReadStreamCopyProperty(requestStream, kCFStreamPropertyHTTPResponseHeader);
CFHTTPMessageSetBody(response, (CFDataRef)responseBytes);
CFReadStreamClose(requestStream);
CFRelease(requestStream);
return [NSMakeCollectable(response) autorelease];
}
Adding Authentication to an HTTP Request
-(void)addAuthenticationToRequest:(CFHTTPMessageRef)request withResponse:(CFHTTPMessageRef)response
{
CFHTTPAuthenticationRef authentication = CFHTTPAuthenticationCreateFromResponse(NULL, response);
[NSMakeCollectable(authentication) autorelease];
CFStreamError err;
Boolean success = CFHTTPMessageApplyCredentials(request, authentication, CFSTR("username"), CFSTR("password"), &err);
}
Putting It All Together
-(void)magicHappens
{
CFHTTPMessageRef request = [self buildMessage];
CFHTTPMessageRef response = [self performHTTPRequest: request];
UInt32 statusCode;
statusCode = CFHTTPMessageGetResponseStatusCode(response);
//An HTTP status code of 401 or 407 indicates that authentication is
//required I use an auth count to make sure we don't get stuck in an
//infinite loop if our credentials are bad. Sometimes, making the
//request more than once lets it go through.
//I admit I don't know why.
int authCount = 0;
while((statusCode == 401 || statusCode == 407) && authCount < 3)
{
request = [self buildMessage];
[self addAuthenticationToRequest:request withResponse:response];
response = [self performHTTPRequest: request];
statusCode = CFHTTPMessageGetResponseStatusCode;
authCount++;
}
NSData *responseBodyData = [(NSData*)CFHTTPMessageCopyBody(response) autorelease];
NSString *responseBody = [[[NSString alloc] initWithData:responseBodyData encoding:NSUTF8StringEncoding] autorelease];
NSLog(responseBody);
}
Refer this link.