RestKit with Three20 Integration

I am trying to work with Restkit to call my web server api, but everything does not work. My controller just shows an activity indicator and nothing happens.

I have an api call that supposedly returns the top 50 videos, for example: http://example.com/services/getTop50Video

Return in format:

<results>
<mysql_host>72.9.41.97</mysql_host>
<results>        
    <title/>
    <views/>
    <video_id>j2xFxHgENt4</video_id>
    <thumbnail>http://img.youtube.com/vi/j2xFxHgENt4/2.jpg</thumbnail>
    <url/>
</results>
...
</results>

My delegate application code :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Configure RestKit Object Manager
    RKObjectManager* objectManager = [RKObjectManager objectManagerWithBaseURL:@"http://example.com/services"];

    RKObjectMapper* mapper =  objectManager.mapper;
    [mapper registerClass:[YouTubeVideo class] forElementNamed:@"video"];

     // Other non relevant stuff
}

TWYouTubeVideo Class :

@implementation TWYouTubeVideo

@synthesize title = _title;
@synthesize numberOfViews = _numberOfViews;
@synthesize videoID = _videoID;
@synthesize thumbnailURL = _thumbnailURL;


+ (NSDictionary*)elementToPropertyMappings {
    return [NSDictionary dictionaryWithKeysAndObjects:
            @"title", @"title",
            @"views", @"numberOfViews",
            @"video_id", @"videoID",
            @"thumbnail", @"thumbnailURL",
            nil];
}

My controller code :

-(id) initWithResourcePath:(NSString*) requestedResourcePath
{
    if (self = [super init])
    {
        self.resourcePath = requestedResourcePath;
    }
    return self;
}

- (void)createModel {
    self.model = [[[RKRequestTTModel alloc] initWithResourcePath:self.resourcePath] autorelease];
}


- (void)didLoadModel:(BOOL)firstTime {
    [super didLoadModel:firstTime];

    RKRequestTTModel* model = (RKRequestTTModel*)self.model;
    NSMutableArray* items = [NSMutableArray arrayWithCapacity:[model.objects count]];

        for (YouTubeVideo* video in model.objects) {
            TableSubtitleItem *item = [TableSubtitleItem itemWithText:video.title
                                                                 subtitle:[NSString stringWithFormat:@"%@ views", video.numberOfViews]
                                                                 imageURL:video.thumbnailURL
                                                             defaultImage:[YouTubeVideo defaultThumbnail]
                                                                      URL:nil
                                                             accessoryURL:nil];

            [items addObject:item];
        }


    // Ensure that the datasource model is still the RKRequestTTModel;
    // Otherwise isOutdated will not work.
    TTListDataSource* dataSource = [TTListDataSource dataSourceWithItems:items];
    dataSource.model = model;
    self.dataSource = dataSource;
}

And pressing the controller :

SecondYouTubeController* viewController = [[SecondYouTubeController alloc] initWithResourcePath:@"/getTop50VideoXML?json=true"];
[self.navigationController pushViewController:viewController animated:YES];
[viewController release];    

Firstly, I think I need to somehow tell the parser that the video objects appear inside the node's “response”. Secondly, I’m not sure that I am making all the challenges, as it should.

I would really like to help here.

+5
2

"", keyPath RKRequestTTModel "".

XML? RestKit XML- ( , ). JSON? , , , , , RKParser, XML / Cocoa ( ).

+2

, XML RestKit 0.20.

- : https://github.com/RestKit/RKXMLReaderSerialization

, :

pod 'RKXMLReaderSerialization', :git => 'https://github.com/RestKit/RKXMLReaderSerialization.git', :branch => 'master'

:

[RKMIMETypeSerialization registerClass:[RKXMLReaderSerialization class] forMIMEType:@"application/xml"];
0

All Articles