//
// FacebookLoginResponseJsonMapper.m
// Project
//
// Created by haibara on 6/16/16.
//
//

#import "FacebookLoginResponseJsonMapper.h"
#import "Lang.h"
#import "BeanUtils.h"
#import "CocoaUtils.h"
#import <BlocksKit/BlocksKit.h>
#import <RestKit/RKObjectMappingOperationDataSource.h>

@implementation FacebookLoginResponseJsonMapper

- (instancetype)init {
	if (self = [super init]) {
		self.objectMapping = [LoginResponseBody objectMappingForClass:[FacebookLoginResponse class]];
	}
	return self;
}

#pragma mark - Public

- (NSError *)parseWithJSONObject:(id)jsonObject {
	self.response = [[FacebookLoginResponse alloc] init];

	RKMappingOperation *mappingOperation = [[RKMappingOperation alloc] initWithSourceObject:jsonObject destinationObject:self.response mapping:self.objectMapping];
	RKObjectMappingOperationDataSource *mappingOperationDataSource = [[RKObjectMappingOperationDataSource alloc] init];
	mappingOperation.dataSource = mappingOperationDataSource;

	NSError *error = nil;
	[mappingOperation performMapping:&error];
	return error;
}

@end


