1

RestKit 0.20.0 を使用して、Devise を実行している RoR バックエンドにログインしようとしています。次のパラメータでリクエストを達成しようとしています:

Parameters: {"password"=>"[FILTERED]", "email"=>"email@mail.com"}

しかし、サーバーで実際に受信されるのは次のとおりです。

Parameters: {"password"=>"[FILTERED]", "email"=>"email@mail.com", "session"=>{"password"=>"[FILTERED]", "email"=>"email@mail.com"}}

このセッション パラメータがどこから来るのか、私にはわかりません。GET を実行するときは追加されず、POST を実行するときにのみ追加されます。ログインは成功しますが、応答は完全に間違っています。パラメータの正しいリストを使用することで、正しい応答が得られます。以下は、リクエストを送信するコードです。このセッションパラメータがどこから来たのかについてのアイデアはありますか?

- (void)loginWithblock:(void (^)(bool))block
{
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:_username, @"email", _password, @"password", nil];
NSString *url = [[MBMSettingsHelper sharedSettingsHelper] authenticationURL];

[[RKObjectManager sharedManager] postObject:nil path:url parameters:params
                                    success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
                                        block(YES);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
    block(NO);
}];
}

私の appdelegate には、次のマッパーがあります。

// Mappers for authentication
RKObjectMapping *requestMappingForAuthenticate = [RKObjectMapping requestMapping];
[requestMappingForAuthenticate addAttributeMappingsFromDictionary:@{
 @"username" : @"email",
 @"password": @"password"
 }];
RKRequestDescriptor *requestDescriptorForAuthenticate = [RKRequestDescriptor requestDescriptorWithMapping:requestMappingForAuthenticate objectClass:[MBMUserLoginRequest class] rootKeyPath:nil];

RKObjectMapping *responseMappingForAuthenticate = [RKObjectMapping requestMapping];
[responseMappingForAuthenticate addAttributeMappingsFromDictionary:@{
 @"success": @"success",
 @"auth_token": @"token",
 @"email": @"username",
 @"id": @"userId"}];
RKResponseDescriptor *responseDescriptorForAuthenticate = [RKResponseDescriptor responseDescriptorWithMapping:responseMappingForAuthenticate pathPattern:nil keyPath:nil statusCodes:nil];

[objectManager addResponseDescriptor:responseDescriptorForAuthenticate];
[objectManager addRequestDescriptor:requestDescriptorForAuthenticate];

編集:

RestKit ログは以下に掲載されています。ログイン後、マッパーがログイン応答を完全に異なるモデル (この場合はボート) にマッピングし始めるように見えますか?

2013-05-24 01:33:59.649 xxx[8153:637f] D restkit.object_mapping:RKMapperOperation.m:241 Asked to map source object {
"auth_token" = xxx;
email = "xxx";
id = 2;
success = 1;
} with mapping <RKObjectMapping:0x1d5213a0 objectClass=NSMutableDictionary propertyMappings=(
"<RKAttributeMapping: 0x1d51a120 id => boatId>",
"<RKAttributeMapping: 0x1d54ec90 year => year>",
"<RKAttributeMapping: 0x1d54ecb0 factory => manufacturer>",
"<RKAttributeMapping: 0x1d528b40 gearnumber => sterndriveNumber>",
"<RKAttributeMapping: 0x1d528b80 harbour => homeHarbour>",
"<RKAttributeMapping: 0x1d54ea80 enginemanufactory => engineManufacturer>",
"<RKAttributeMapping: 0x1d54e9f0 updated_at => updatedAt>",
"<RKAttributeMapping: 0x1d54ed00 created_at => createdAt>",
"<RKAttributeMapping: 0x1d54ee70 docknumber => dockNumber>",
"<RKAttributeMapping: 0x1d54ed30 insurancecompany => insuranceCompany>",
"<RKAttributeMapping: 0x1d54edd0 model => model>",
"<RKAttributeMapping: 0x1d54ede0 name => name>",
"<RKAttributeMapping: 0x1d54f0e0 enginemodel => engineModel>",
"<RKAttributeMapping: 0x1d54f170 enginenumber => engineNumber>",
"<RKAttributeMapping: 0x1d54ed40 engineyear => engineYear>",
"<RKAttributeMapping: 0x1d54ed50 geartype => sterndriveType>"
)>
2013-05-24 01:33:59.652 xxx[8153:637f] D restkit.object_mapping:RKMappingOperation.m:862 Starting mapping operation...
2013-05-24 01:33:59.653 xxx[8153:637f] T restkit.object_mapping:RKMappingOperation.m:863 Performing mapping operation: <RKMappingOperation 0x1e325070> for '__NSDictionaryM' object. Mapping values from object {
"auth_token" = xxx;
email = "xxx";
id = 2;
success = 1;
} to object {
} with object mapping (null)
2013-05-24 01:33:59.655 xxx[8153:637f] T restkit.object_mapping:RKMappingOperation.m:458 Mapping attribute value keyPath 'id' to 'boatId'
2013-05-24 01:33:59.656 xxx[8153:637f] T restkit.object_mapping:RKMappingOperation.m:480 Mapped attribute value from keyPath 'id' to 'boatId'. Value: 2
2013-05-24 01:33:59.657 xxx[8153:637f] T restkit.object_mapping:RKMappingOperation.m:525 Did not find mappable attribute value keyPath 'year'
2013-05-24 01:33:59.658 xxx[8153:637f] T restkit.object_mapping:RKMappingOperation.m:525 Did not find mappable attribute value keyPath 'factory'
2013-05-24 01:33:59.659 xxx[8153:637f] T restkit.object_mapping:RKMappingOperation.m:525 Did not find mappable attribute value keyPath 'gearnumber'
2013-05-24 01:33:59.659 xxx[8153:637f] T restkit.object_mapping:RKMappingOperation.m:525 Did not find mappable attribute value keyPath 'harbour'
2013-05-24 01:33:59.660 xxx[8153:637f] T restkit.object_mapping:RKMappingOperation.m:525 Did not find mappable attribute value keyPath 'enginemanufactory'
2013-05-24 01:33:59.661 xxx[8153:637f] T restkit.object_mapping:RKMappingOperation.m:525 Did not find mappable attribute value keyPath 'updated_at'
2013-05-24 01:33:59.662 xxx[8153:637f] T restkit.object_mapping:RKMappingOperation.m:525 Did not find mappable attribute value keyPath 'created_at'
2013-05-24 01:33:59.663 xxx[8153:637f] T restkit.object_mapping:RKMappingOperation.m:525 Did not find mappable attribute value keyPath 'docknumber'
2013-05-24 01:33:59.664 xxx[8153:637f] T restkit.object_mapping:RKMappingOperation.m:525 Did not find mappable attribute value keyPath 'insurancecompany'
2013-05-24 01:33:59.664 xxx[8153:637f] T restkit.object_mapping:RKMappingOperation.m:525 Did not find mappable attribute value keyPath 'model'
2013-05-24 01:33:59.665 xxx[8153:637f] T restkit.object_mapping:RKMappingOperation.m:525 Did not find mappable attribute value keyPath 'name'
2013-05-24 01:33:59.666 xxx[8153:637f] T restkit.object_mapping:RKMappingOperation.m:525 Did not find mappable attribute value keyPath 'enginemodel'
2013-05-24 01:33:59.667 xxx[8153:637f] T restkit.object_mapping:RKMappingOperation.m:525 Did not find mappable attribute value keyPath 'enginenumber'
2013-05-24 01:33:59.667 xxx[8153:637f] T restkit.object_mapping:RKMappingOperation.m:525 Did not find mappable attribute value keyPath 'engineyear'
2013-05-24 01:33:59.668 xxx[8153:637f] T restkit.object_mapping:RKMappingOperation.m:525 Did not find mappable attribute value keyPath 'geartype'
2013-05-24 01:33:59.669 xxx[8153:637f] D restkit.object_mapping:RKMappingOperation.m:926 Finished mapping operation successfully...
2013-05-24 01:33:59.670 xxx[8153:637f] D restkit.object_mapping:RKMapperOperation.m:414 Finished performing object mapping. Results: {
"<null>" =     {
    boatId = 2;
};

編集 2: 他の RKResponseDescriptors を削除すると、すべてが機能しました。したがって、問題は、マッピングが発生したときに、どういうわけか間違った RKResponseDescriptor が選択されることです...

4

0 に答える 0