Mikhail Kuznetsov avatar Mikhail Kuznetsov committed 9efe9ed

url generation fixed;

Comments (0)

Files changed (5)

MyShows.xcodeproj/project.pbxproj

 		186608FF144B150A0050B8E1 /* ASIInputStream.m in Sources */ = {isa = PBXBuildFile; fileRef = 186608F1144B150A0050B8E1 /* ASIInputStream.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
 		18660900144B150A0050B8E1 /* ASINetworkQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = 186608F3144B150A0050B8E1 /* ASINetworkQueue.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
 		18660901144B150A0050B8E1 /* Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 186608F8144B150A0050B8E1 /* Reachability.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
+		18EE6BAC1452D55F00A4D065 /* NSString+Hash.m in Sources */ = {isa = PBXBuildFile; fileRef = 18EE6BAB1452D55F00A4D065 /* NSString+Hash.m */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
 		186608F4144B150A0050B8E1 /* ASIProgressDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASIProgressDelegate.h; sourceTree = "<group>"; };
 		186608F7144B150A0050B8E1 /* Reachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Reachability.h; sourceTree = "<group>"; };
 		186608F8144B150A0050B8E1 /* Reachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Reachability.m; sourceTree = "<group>"; };
+		18EE6BAA1452D55F00A4D065 /* NSString+Hash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSString+Hash.h"; path = "Categories/NSString+Hash.h"; sourceTree = "<group>"; };
+		18EE6BAB1452D55F00A4D065 /* NSString+Hash.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSString+Hash.m"; path = "Categories/NSString+Hash.m"; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
 		18660850144AEC120050B8E1 /* MyShows */ = {
 			isa = PBXGroup;
 			children = (
+				18EE6BA81452D4EE00A4D065 /* Categories */,
 				186608DF144B14D10050B8E1 /* Classes */,
 				18660887144AF4D10050B8E1 /* Libraries */,
 				18660859144AEC120050B8E1 /* AppDelegate.h */,
 			path = Reachability;
 			sourceTree = "<group>";
 		};
+		18EE6BA81452D4EE00A4D065 /* Categories */ = {
+			isa = PBXGroup;
+			children = (
+				18EE6BAA1452D55F00A4D065 /* NSString+Hash.h */,
+				18EE6BAB1452D55F00A4D065 /* NSString+Hash.m */,
+			);
+			name = Categories;
+			sourceTree = "<group>";
+		};
 /* End PBXGroup section */
 
 /* Begin PBXNativeTarget section */
 				186608FF144B150A0050B8E1 /* ASIInputStream.m in Sources */,
 				18660900144B150A0050B8E1 /* ASINetworkQueue.m in Sources */,
 				18660901144B150A0050B8E1 /* Reachability.m in Sources */,
+				18EE6BAC1452D55F00A4D065 /* NSString+Hash.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
 				1866087B144AEC120050B8E1 /* Release */,
 			);
 			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Release;
 		};
 		1866087C144AEC120050B8E1 /* Build configuration list for PBXNativeTarget "MyShowsTests" */ = {
 			isa = XCConfigurationList;
 				1866087E144AEC120050B8E1 /* Release */,
 			);
 			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Release;
 		};
 /* End XCConfigurationList section */
 	};

MyShows/Categories/NSString+Hash.h

+//
+//  NSString+Hash.h
+//  MyShows
+//
+//  Created by Mikhail Kuznetsov on 22.10.11.
+//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <CommonCrypto/CommonDigest.h>
+
+@interface NSString (Hash)
+
++ (NSString *) Md5Hash:(NSString *) string;
+
+@end

MyShows/Categories/NSString+Hash.m

+//
+//  NSString+Hash.m
+//  MyShows
+//
+//  Created by Mikhail Kuznetsov on 22.10.11.
+//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import "NSString+Hash.h"
+
+@implementation NSString (Hash)
+
++ (NSString *) Md5Hash:(NSString *)string {
+    const char *str = [string UTF8String];
+    unsigned char result[CC_MD5_DIGEST_LENGTH];
+    CC_MD5(str, strlen(str), result);
+    return [NSString stringWithFormat:
+            @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
+            result[0], result[1], result[2], result[3], 
+            result[4], result[5], result[6], result[7],
+            result[8], result[9], result[10], result[11],
+            result[12], result[13], result[14], result[15]
+            ]; 
+}
+
+@end

MyShows/Classes/MyShowsApi.m

 
 - (void) initUrlsMap {
     urlsMap = [[NSDictionary alloc] initWithObjectsAndKeys:
-               @"login", @"profile/login/",
-               @"shows", @"profile/shows/",
+               @"profile/login", @"login",
+               @"profile/shows", @"shows",
                nil];
 }
 
     while (key = [enumerator nextObject]) {
         result = [result stringByAppendingFormat:@"%@=%@&", key, [params objectForKey:key]];
     }
-    result = [result substringToIndex:[result length] - 2];
+    result = [result substringToIndex:[result length] - 1];
     return [result stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
 }
 
 - (void) sendRequest:(NSString *)resource queryParams: (NSDictionary *) queryParams {
-    NSLog(@"Sending %@ request...", resource);
+    NSLog(@"Sending %@ request with params %@", resource, queryParams);
     
     NSURL *url = [NSURL URLWithString:[[NSString alloc] initWithFormat:@"%@%@?%@",
                                        baseUrl, 
                                        [self dictToQueryString:queryParams]
                                        ]
                   ];
+    NSLog(@"Requesting url is %@", url);
     SEL requestSelector = NSSelectorFromString([[NSString alloc] initWithFormat:@"request%@Finished", [resource uppercaseString]]);
     
     ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];

MyShows/ViewController.m

 //
 
 #import "ViewController.h"
+#import "NSString+Hash.h"
 
 @implementation ViewController
 @synthesize login, password;
     
     if (login.text != nil && password.text != nil){
         NSDictionary *params = [[NSDictionary alloc] initWithObjectsAndKeys:
-                                @"login", login.text,
-                                @"password", password.text, 
+                                login.text, @"login",
+                                [NSString Md5Hash:password.text], @"password", 
                                 nil];
         
         [api sendRequest:@"login" queryParams:params];
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.