EzDevInfo.com

sockit

String <-> Object Coder for Objective-C NimbusKit/sockit · GitHub sockit - string <-> object coder for objective-c

Path pattern matching /

I'm trying to build a response descriptor for calls to the Dropbox metadata API.

Using the DBMetadata class from the Dropbox OS X SDK, here is my mapping:

RKObjectMapping *metadataMapping;
metadataMapping = [RKObjectMapping mappingForClass:[DBMetadata class]];
[metadataMapping addAttributeMappingsFromDictionary:@{@"thumb_exists": @"thumbnailExists",
                                                      @"bytes"       : @"totalBytes",
                                                      @"modified"    : @"lastModifiedDate",
                                                      @"client_mtime": @"clientMtime",
                                                      @"path"        : @"path",
                                                      @"is_dir"      : @"isDirectory",
                                                      @"hash"        : @"hash",
                                                      @"size"        : @"humanReadableSize",
                                                      @"root"        : @"root",
                                                      @"icon"        : @"icon",
                                                      @"rev"         : @"rev",
                                                      @"revision"    : @"revision",
                                                      @"is_deleted"  : @"isDeleted"}];
[metadataMapping addRelationshipMappingWithSourceKeyPath:@"contents"
                                                 mapping:metadataMapping];

Here is my Response Descriptor (As much as I'd like to, I can't use :root:path, see NOTE 1):

RKResponseDescriptor *metadataResponse;
metadataResponse = [RKResponseDescriptor responseDescriptorWithMapping:metadataMapping
                                                                method:RKRequestMethodGET
                                                           pathPattern:@"metadata/dropbox:path"
                                                               keyPath:nil
                                                           statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[self.manager addResponseDescriptor:metadataResponse];

The manager is setup as:

NSURL *baseAPIURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@/%@/", kDBProtocolHTTPS, kDBDropboxAPIHost, kDBDropboxAPIVersion]];
self.manager = [RKObjectManager managerWithBaseURL:baseAPIURL];
self.manager.requestSerializationMIMEType = RKMIMETypeJSON;

The problem is that the @"metadata/dropbox:path" path pattern always fails:

DBMetadata *root;
root = [[DBMetadata alloc] initWithDictionary:@{@"root": @"dropbox",
                                                @"path": @"/"}];
[self.manager getObject:root
                   path:@"metadata/dropbox/"
             parameters:@{@"list": @"false"}
                success:...
                failure:...];

Result:

E restkit.network:RKObjectRequestOperation.m:213 GET 'https://api.dropbox.com/1/metadata/dropbox/?list=false' (200 OK / 0 objects) [request=0.0957s mapping=0.0000s total=0.0968s]: Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No response descriptors match the response loaded." UserInfo=0x6000000ee900 {NSLocalizedFailureReason=A 200 response was loaded from the URL 'https://api.dropbox.com/1/metadata/dropbox/?list=false', which failed to match all (0) response descriptors:, NSErrorFailingURLStringKey=https://api.dropbox.com/1/metadata/dropbox/?list=false, NSErrorFailingURLKey=https://api.dropbox.com/1/metadata/dropbox/?list=false, NSUnderlyingError=0x6000000569b0 "No mappable object representations were found at the key paths searched.", keyPath=null, NSLocalizedDescription=No response descriptors match the response loaded.}

But if I set the path pattern in the response descriptor to a static string (@"metadata/dropbox/"), it works:

I restkit.network:RKObjectRequestOperation.m:220 GET 'https://api.dropbox.com/1/metadata/dropbox/?list=false' (200 OK / 1 objects) [request=0.1027s mapping=0.0014s total=0.1034s]

Is it not possible to pass "/" as a path pattern parameter?

I also noticed that the error says that the response failed to match all (0) response descriptors. Shouldn't it be (1) in this case?


Source: (StackOverflow)

Datetime field in RKPaginator URL

I am using RestKit and I am trying to use the RKPaginator. However, I need to have a datetime field within the URL Request. I am building the following requestString, which is a NSString, and use it in:

RKPaginator *paginator = [objectManager paginatorWithPathPattern:requestString];


requestString is @“/api/rest/equipment/?count=3&limit=:perPage&offset=:offset&last_modified_date__gte=2014-03-31T17:20:26

However, I keep getting:

** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Parameters must be separated by non-parameter characters.'

This is due to the ":" in the datetime. So...

I tried with:

@“/api/rest/equipment/?count=3&limit=:perPage&offset=:offset&last_modified_date__gte=2014-03-31T17\\:20\\:26

however, I keep getting bad_access within the RestKit when I do that in the following function:

NSString *RKPathAndQueryStringFromURLRelativeToURL(NSURL *URL, NSURL *baseURL)
{
    if (baseURL) {
        if (! RKURLIsRelativeToURL(URL, baseURL)) return nil;
        return [[URL absoluteString] substringFromIndex:[[baseURL absoluteString] length]];
    } else {
        // NOTE: [URL relativeString] would return the same value as `absoluteString` if URL is not relative to a baseURL
        NSString *query = [URL query];
        NSString *pathWithPrevervedTrailingSlash = [CFBridgingRelease(CFURLCopyPath((CFURLRef)URL)) stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        return (query && [query length]) ? [NSString stringWithFormat:@"%@?%@", pathWithPrevervedTrailingSlash, query] : pathWithPrevervedTrailingSlash;
    }
}

Source: (StackOverflow)

Advertisements

Restkit - Matching a Path with ? and =

I've set up a response descriptor like this:

RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:exhibitMapping method:RKRequestMethodAny pathPattern:@"?json=exhibits/get_exhibits" keyPath:@"d.exhibits" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

And made the request like so:

[[RKObjectManager sharedManager] getObjectsAtPath:@"?json=exhibits/get_exhibits" parameters:nil success:

But I get this error:

2014-03-17 11:14:39.856 MuseumMap[6135:60b] E app:ExhibitTableViewController.m:49 Load failed with error: Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No response descriptors match the response loaded." UserInfo=0x8fb69f0 {NSErrorFailingURLStringKey=http://exhibits.wpengine.com/?json=exhibits/get_exhibits, NSLocalizedFailureReason=A 200 response was loaded from the URL 'http://exhibits.wpengine.com/?json=exhibits/get_exhibits', which failed to match all (1) response descriptors:
  <RKResponseDescriptor: 0x9480270 baseURL=http://exhibits.wpengine.com/ pathPattern=?json=exhibits/get_exhibits statusCodes=200-299> failed to match: response path '?json=exhibits/get_exhibits' did not match the path pattern '?json=exhibits/get_exhibits'., NSLocalizedDescription=No response descriptors match the response loaded., keyPath=null, NSErrorFailingURLKey=http://exhibits.wpengine.com/?json=exhibits/get_exhibits, NSUnderlyingError=0x8fb6990 "No mappable object representations were found at the key paths searched."}

My thought is that there is a problem matching because of either the ? or the = in the pathPattern but I've tried escaping those and it doesn't seem to make a difference. Anyone have any ideas why this wouldn't match? The error message being response path '?json=exhibits/get_exhibits' did not match the path pattern '?json=exhibits/get_exhibits'. seems a bit off.


Source: (StackOverflow)