Permalink
Browse files

Adds oAuth 1.0a to DIOS.

  • Loading branch information...
1 parent e17f5f0 commit 63f2f8aea516387d2e2eb5b28d12f16610617121 @kylebrowning committed Oct 10, 2012
Showing with 803 additions and 140 deletions.
  1. +75 −18 DIOSComment.m
  2. +27 −9 DIOSFile.m
  3. +5 −5 DIOSNode.h
  4. +78 −34 DIOSNode.m
  5. +31 −0 DIOSSession.h
  6. +312 −6 DIOSSession.m
  7. +45 −13 DIOSTaxonomy.m
  8. +130 −36 DIOSUser.m
  9. +2 −1 DIOSView.h
  10. +17 −2 DIOSView.m
  11. +80 −15 README.md
  12. +1 −1 Settings.h
View
@@ -46,37 +46,84 @@ + (void)commentGet:(NSDictionary *)comment
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject)) success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure {
- [[DIOSSession sharedSession] getPath:[NSString stringWithFormat:@"%@/%@/%@", kDiosEndpoint, kDiosBaseComment, [comment objectForKey:@"cid"]]
- parameters:nil
- success:success
- failure:failure];
+ NSString *path = [NSString stringWithFormat:@"%@/%@/%@", kDiosEndpoint, kDiosBaseComment, [comment objectForKey:@"cid"]];
+
+ if ([[DIOSSession sharedSession] signRequests]) {
+ [[DIOSSession sharedSession] sendSignedRequestWithPath:path
+ method:@"GET"
+ params:comment
+ success:success
+ failure:failure];
+ } else {
+ [[DIOSSession sharedSession] getPath:path
+ parameters:nil
+ success:success
+ failure:failure];
+ }
}
#pragma mark commentSave
+ (void)commentSave:(NSDictionary *)comment
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject)) success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure {
- [[DIOSSession sharedSession] postPath:[NSString stringWithFormat:@"%@/%@", kDiosEndpoint, kDiosBaseComment]
- parameters:comment
- success:success
- failure:failure];
+
+ NSString *path = [NSString stringWithFormat:@"%@/%@", kDiosEndpoint, kDiosBaseComment];
+
+ if ([[DIOSSession sharedSession] signRequests]) {
+ [[DIOSSession sharedSession] sendSignedRequestWithPath:path
+ method:@"POST"
+ params:comment
+ success:success
+ failure:failure];
+ } else {
+ [[DIOSSession sharedSession] postPath:path
+ parameters:comment
+ success:success
+ failure:failure];
+ }
}
#pragma mark commentUpdate
+ (void)commentUpdate:(NSDictionary *)comment
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject)) success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure {
- [[DIOSSession sharedSession] putPath:[NSString stringWithFormat:@"%@/%@/%@", kDiosEndpoint, kDiosBaseComment, [comment objectForKey:@"cid"]]
- parameters:comment
- success:success
- failure:failure];
+
+ NSString *path = [NSString stringWithFormat:@"%@/%@/%@", kDiosEndpoint, kDiosBaseComment, [comment objectForKey:@"cid"]];
+
+ if ([[DIOSSession sharedSession] signRequests]) {
+ [[DIOSSession sharedSession] sendSignedRequestWithPath:path
+ method:@"PUT"
+ params:comment
+ success:success
+ failure:failure];
+ } else {
+ [[DIOSSession sharedSession] putPath:path
+ parameters:comment
+ success:success
+ failure:failure];
+ }
+
}
#pragma mark CommentDelete
+ (void)commentDelete:(NSDictionary *)comment
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject)) success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure; {
- [[DIOSSession sharedSession] deletePath:[NSString stringWithFormat:@"%@/%@/%@", kDiosEndpoint, kDiosBaseComment, [comment objectForKey:@"cid"]] parameters:comment success:success failure:failure];
+
+ NSString *path = [NSString stringWithFormat:@"%@/%@/%@", kDiosEndpoint, kDiosBaseComment, [comment objectForKey:@"cid"]];
+
+ if ([[DIOSSession sharedSession] signRequests]) {
+ [[DIOSSession sharedSession] sendSignedRequestWithPath:path
+ method:@"DELETE"
+ params:comment
+ success:success
+ failure:failure];
+ } else {
+ [[DIOSSession sharedSession] deletePath:path
+ parameters:comment
+ success:success
+ failure:failure];
+ }
}
#pragma mark commentIndex
@@ -100,10 +147,20 @@ + (void)commentIndexWithPage:(NSString *)page
+ (void)commentIndex:(NSDictionary *)params
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject)) success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure; {
-
- [[DIOSSession sharedSession] getPath:[NSString stringWithFormat:@"%@/%@", kDiosEndpoint, kDiosBaseComment]
- parameters:params
- success:success
- failure:failure];
+
+ NSString *path = [NSString stringWithFormat:@"%@/%@", kDiosEndpoint, kDiosBaseComment];
+
+ if ([[DIOSSession sharedSession] signRequests]) {
+ [[DIOSSession sharedSession] sendSignedRequestWithPath:path
+ method:@"GET"
+ params:params
+ success:success
+ failure:failure];
+ } else {
+ [[DIOSSession sharedSession] getPath:path
+ parameters:params
+ success:success
+ failure:failure];
+ }
}
@end
View
@@ -44,20 +44,38 @@ + (void) fileGet:(NSDictionary *)params
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject)) success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure {
- [[DIOSSession sharedSession] getPath:[NSString stringWithFormat:@"%@/%@/%@", kDiosEndpoint, kDiosBaseFile, [params objectForKey:@"fid"]]
- parameters:params
- success:success
- failure:failure];
+ NSString *path = [NSString stringWithFormat:@"%@/%@/%@", kDiosEndpoint, kDiosBaseFile, [params objectForKey:@"fid"]];
+ if ([[DIOSSession sharedSession] signRequests]) {
+ [[DIOSSession sharedSession] sendSignedRequestWithPath:path
+ method:@"GET"
+ params:params
+ success:success
+ failure:failure];
+ } else {
+ [[DIOSSession sharedSession] getPath:path
+ parameters:params
+ success:success
+ failure:failure];
+ }
+
}
+ (void)fileSave:(NSDictionary *)file
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject)) success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure {
-
- [[DIOSSession sharedSession] postPath:[NSString stringWithFormat:@"%@/%@", kDiosEndpoint, kDiosBaseFile]
- parameters:file
- success:success
- failure:failure];
+ NSString *path = [NSString stringWithFormat:@"%@/%@", kDiosEndpoint, kDiosBaseFile];
+ if ([[DIOSSession sharedSession] signRequests]) {
+ [[DIOSSession sharedSession] sendSignedRequestWithPath:path
+ method:@"POST"
+ params:file
+ success:success
+ failure:failure];
+ } else {
+ [[DIOSSession sharedSession] postPath:path
+ parameters:file
+ success:success
+ failure:failure];
+ }
}
+ (UIImageView *) getImageViewForFileImage:(NSDictionary *) file; {
NSURL *url = [NSURL URLWithString:[file objectForKey:@"uri_full"]];
View
@@ -55,15 +55,15 @@
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject)) success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure;
-+ (void)nodeIndexWithPage:(NSString *)page fields:(NSString *)fields parameters:(NSArray *)parameteres pageSize:(NSString *)pageSize
++ (void)nodeIndexWithPage:(NSString *)page
+ fields:(NSString *)fields
+ parameters:(NSArray *)parameteres
+ pageSize:(NSString *)pageSize
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject)) success
- failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure;
+ failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure ;
+ (void)nodeIndex:(NSDictionary *)params
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject)) success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure;
-+ (void)nodeAttachFile:(NSDictionary *)params
- success:(void (^)(AFHTTPRequestOperation *operation, id responseObject)) success
- failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure;
@end
View
@@ -43,47 +43,94 @@ @implementation DIOSNode
+ (void)nodeGet:(NSDictionary *)node
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject)) success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure {
+
+ NSString *path = [NSString stringWithFormat:@"%@/%@/%@", kDiosEndpoint, kDiosBaseNode, [node objectForKey:@"nid"]];
- [[DIOSSession sharedSession] getPath:[NSString stringWithFormat:@"%@/%@/%@", kDiosEndpoint, kDiosBaseNode, [node objectForKey:@"nid"]]
- parameters:nil
- success:success
- failure:failure];
+ if ([[DIOSSession sharedSession] signRequests]) {
+ [[DIOSSession sharedSession] sendSignedRequestWithPath:path
+ method:@"GET"
+ params:node
+ success:success
+ failure:failure];
+ } else {
+ [[DIOSSession sharedSession] getPath:path
+ parameters:nil
+ success:success
+ failure:failure];
+ }
}
#pragma mark nodeSave
+ (void)nodeSave:(NSDictionary *)node
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject)) success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure {
- [[DIOSSession sharedSession] postPath:[NSString stringWithFormat:@"%@/%@", kDiosEndpoint, kDiosBaseNode]
- parameters:node
- success:success
- failure:failure];
+ NSString *path = [NSString stringWithFormat:@"%@/%@", kDiosEndpoint, kDiosBaseNode];
+
+ if ([[DIOSSession sharedSession] signRequests]) {
+ [[DIOSSession sharedSession] sendSignedRequestWithPath:path
+ method:@"POST"
+ params:node
+ success:success
+ failure:failure];
+ }
+ else {
+ [[DIOSSession sharedSession] postPath:path
+ parameters:node
+ success:success
+ failure:failure];
+ }
}
#pragma mark nodeUpdate
+ (void)nodeUpdate:(NSDictionary *)node
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject)) success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure {
- [[DIOSSession sharedSession] putPath:[NSString stringWithFormat:@"%@/%@/%@", kDiosEndpoint, kDiosBaseNode, [node objectForKey:@"nid"]]
- parameters:node
- success:success
- failure:failure];
+ NSString *path = [NSString stringWithFormat:@"%@/%@/%@", kDiosEndpoint, kDiosBaseNode, [node objectForKey:@"nid"]];
+
+ if ([[DIOSSession sharedSession] signRequests]) {
+ [[DIOSSession sharedSession] sendSignedRequestWithPath:path
+ method:@"PUT"
+ params:node
+ success:success
+ failure:failure];
+ }
+ else {
+ [[DIOSSession sharedSession] putPath:path
+ parameters:node
+ success:success
+ failure:failure];
+ }
+
}
#pragma mark nodeDelete
+ (void)nodeDelete:(NSDictionary *)node
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject)) success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure {
- [[DIOSSession sharedSession] deletePath:[NSString stringWithFormat:@"%@/%@/%@", kDiosEndpoint, kDiosBaseNode, [node objectForKey:@"nid"]]
- parameters:node
- success:success
- failure:failure];
+
+ NSString *path = [NSString stringWithFormat:@"%@/%@/%@", kDiosEndpoint, kDiosBaseNode, [node objectForKey:@"nid"]];
+
+ if ([[DIOSSession sharedSession] signRequests]) {
+ [[DIOSSession sharedSession] sendSignedRequestWithPath:path
+ method:@"DELETE"
+ params:node
+ success:success
+ failure:failure];
+ } else {
+ [[DIOSSession sharedSession] deletePath:path
+ parameters:node
+ success:success
+ failure:failure];
+ }
}
#pragma mark nodeIndex
//Simpler method if you didnt want to build the params :)
-+ (void)nodeIndexWithPage:(NSString *)page fields:(NSString *)fields parameters:(NSArray *)parameteres pageSize:(NSString *)pageSize
++ (void)nodeIndexWithPage:(NSString *)page
+ fields:(NSString *)fields
+ parameters:(NSArray *)parameteres
+ pageSize:(NSString *)pageSize
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject)) success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure {
NSMutableDictionary *nodeIndexDict = [NSMutableDictionary new];
@@ -98,24 +145,21 @@ + (void)nodeIndexWithPage:(NSString *)page fields:(NSString *)fields parameters:
+ (void)nodeIndex:(NSDictionary *)params
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject)) success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure {
-
- [[DIOSSession sharedSession] getPath:[NSString stringWithFormat:@"%@/%@", kDiosEndpoint, kDiosBaseNode] parameters:params success:success failure:failure];
-}
-#pragma mark nodeAttachFile
-+ (void)nodeAttachFile:(NSDictionary *)params
- success:(void (^)(AFHTTPRequestOperation *operation, id responseObject)) success
- failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure {
- NSMutableURLRequest *request = [[DIOSSession sharedSession] multipartFormRequestWithMethod:@"POST" path:[NSString stringWithFormat:@"%@/%@/%@/attach_file?field_name=%@", kDiosEndpoint, kDiosBaseNode, [params objectForKey:@"nid"], [params objectForKey:@"field_name"]] parameters:params constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
- [formData appendPartWithFileData:[params objectForKey:@"fileData"] name:[params objectForKey:@"name"] fileName:[params objectForKey:@"fileName"] mimeType:[params objectForKey:@"mimetype"]];
- }];
+ NSString *path = [NSString stringWithFormat:@"%@/%@", kDiosEndpoint, kDiosBaseNode];
- AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
-// [operation setUploadProgressBlock:^(NSInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
-// NSLog(@"Sent %qi of %qi bytes", totalBytesWritten, totalBytesExpectedToWrite);
-// }];
- [operation setCompletionBlockWithSuccess:success failure:failure];
- [operation start];
- [operation release];
+ if ([[DIOSSession sharedSession] signRequests]) {
+ [[DIOSSession sharedSession] sendSignedRequestWithPath:path
+ method:@"DELETE"
+ params:params
+ success:success
+ failure:failure];
+ } else {
+ [[DIOSSession sharedSession] getPath:path
+ parameters:params
+ success:success
+ failure:failure];
+ }
}
+
@end
Oops, something went wrong.

0 comments on commit 63f2f8a

Please sign in to comment.