Skip to content

Commit

Permalink
See #7. FindQuery is not working as the URL is invalid. Going to have…
Browse files Browse the repository at this point in the history
… to “fix” server to allow a valid URL.

See Glavin001/streamlyne-api-server#8 (comment)
  • Loading branch information
Glavin001 committed Jul 26, 2014
1 parent bf6e5af commit 3efb978
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 31 deletions.
50 changes: 29 additions & 21 deletions Common/SLAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,38 @@ - (PMKPromise *) performRequestWithMethod:(SLHTTPMethodType)theMethod
case SLHTTPMethodGET:
{
NSLog(@"GET %@", fullPathStr);
NSString *urlWithParams = [NSString stringWithFormat:@"%@?%@", fullPathStr, payload];
NSString *urlWithParams;
if (theParams != nil)
{
urlWithParams = [NSString stringWithFormat:@"%@?%@", fullPathStr, payload];
}
else{
urlWithParams = fullPathStr;
}

NSLog(@"urlWithParams %@", urlWithParams);
[requestManager GET:fullPathStr parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {

NSURL *getUrl = [NSURL URLWithString:urlWithParams];
NSLog(@"getURL: %@", getUrl);
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:getUrl
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
timeoutInterval:60.0];
[urlRequest setHTTPMethod:@"GET"];

NSURLRequest *r = [self.httpManager.requestSerializer requestBySerializingRequest:urlRequest withParameters:nil error:nil];

//[requestManager GET:urlWithParams parameters:nil
AFHTTPRequestOperation *operation = [requestManager HTTPRequestOperationWithRequest:r success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
NSLog(@"Success, JSON: %@", responseObject);
fulfiller(PMKManifold(responseObject, operation));
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
NSLog(@"Response: %@", operation.responseString);
rejecter(error);
}];

[requestManager.operationQueue addOperation:operation];

}
break;
case SLHTTPMethodPOST:
Expand Down Expand Up @@ -311,11 +333,12 @@ - (PMKPromise *) findAll:(Class)modelClass withStore:(SLStore *)store

- (PMKPromise *) findMany:(Class)modelClass withIds:(NSArray *)ids withStore:(SLStore *)store
{
NSLog(@"ids: %@", ids);
// Map IDs to ObjectId
NSMutableArray *nids = [NSMutableArray array];
for (NSDictionary *i in ids)
{
SLNid nid = [SLObjectIdTransform deserialize:i];
SLNid nid = [SLObjectIdTransform serialize:i];
[nids addObject:nid];
}

Expand All @@ -326,30 +349,15 @@ - (PMKPromise *) findMany:(Class)modelClass withIds:(NSArray *)ids withStore:(SL
}
};
// Send query
NSLog(@"Query: %@", query);
return [self findQuery:modelClass withQuery:query withStore:store];
}

- (PMKPromise *) findQuery:(Class)modelClass withQuery:(NSDictionary *)query withStore:(SLStore *)store
{
return [PMKPromise new:^(PMKPromiseFulfiller fulfiller, PMKPromiseRejecter rejecter) {

NSString *stringifiedQuery = nil;
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:query
options:(NSJSONWritingOptions) 0
error:&error];
if (!error && jsonData)
{
stringifiedQuery = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
} else {
stringifiedQuery = @"";
rejecter(error);
return;
}

NSString *path = [NSString stringWithFormat:@"%@?%@", [modelClass type], stringifiedQuery];

[self performRequestWithMethod:SLHTTPMethodGET withPath:path withParameters:nil]
NSString *path = [NSString stringWithFormat:@"%@/", [modelClass type]];
[self performRequestWithMethod:SLHTTPMethodGET withPath:path withParameters:query]
.then(fulfiller)
.catch(rejecter);

Expand Down
33 changes: 23 additions & 10 deletions Streamlyne-iOS-SDKTests/Streamlyne_iOS_SDKTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -358,19 +358,32 @@ - (void) testFindMany
{
StartBlock();

NSArray *ids = @[
@"538770b42fb05c514e6cb341",
@"53986c682fb05c52e0f5e686"
];
[SLAttribute findMany:ids]
.then(^(NSArray *attributes) {
NSLog(@"Attributes: %@", attributes);
EndBlock();
[self.client authenticateWithUserEmail:@"[email protected]"
withPassword:@"password"
withOrganization:@"test"]
.then(^(SLClient *client, SLUser *me) {

NSLog(@"Me: %@", me);

NSArray *ids = @[
@"538770b42fb05c514e6cb341",
@"53986c682fb05c52e0f5e686"
];
[SLAttribute findMany:ids]
.then(^(NSArray *attributes) {
EndBlock();
NSLog(@"Attributes: %@", attributes);
})
.catch(^(NSError *error) {
EndBlock();
NSLog(@"Error: %@", error);
XCTFail(@"%@", error);
});

})
.catch(^(NSError *error) {
NSLog(@"Error: %@", error);
XCTFail(@"%@", error);
EndBlock();
XCTFail(@"%@", error);
});

WaitUntilBlockCompletes();
Expand Down

0 comments on commit 3efb978

Please sign in to comment.