Skip to content

Commit

Permalink
Moved magic strings to recreatable URL model:
Browse files Browse the repository at this point in the history
  • Loading branch information
onedayitwillmake committed May 20, 2012
1 parent 21aa105 commit b15ec7a
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 11 deletions.
6 changes: 6 additions & 0 deletions bLock_iOS/bLock.xcodeproj/project.pbxproj
Expand Up @@ -104,6 +104,7 @@
ED88EE8A15530D0F00D932B1 /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ED88EE8915530D0F00D932B1 /* MobileCoreServices.framework */; };
ED88EE8C15530D1A00D932B1 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ED88EE8B15530D1A00D932B1 /* SystemConfiguration.framework */; };
ED88EE9115530F1F00D932B1 /* BLKUnlockMapViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = ED88EE9015530F1E00D932B1 /* BLKUnlockMapViewController.m */; };
EDEF9E2E1569B63400C1D181 /* BLKUrlModel.m in Sources */ = {isa = PBXBuildFile; fileRef = EDEF9E2D1569B63400C1D181 /* BLKUrlModel.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -247,6 +248,8 @@
ED88EE8B15530D1A00D932B1 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
ED88EE8F15530F1E00D932B1 /* BLKUnlockMapViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BLKUnlockMapViewController.h; path = src/BLKUnlockMapViewController.h; sourceTree = "<group>"; };
ED88EE9015530F1E00D932B1 /* BLKUnlockMapViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BLKUnlockMapViewController.m; path = src/BLKUnlockMapViewController.m; sourceTree = "<group>"; };
EDEF9E2C1569B63400C1D181 /* BLKUrlModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BLKUrlModel.h; path = src/BLKUrlModel.h; sourceTree = "<group>"; };
EDEF9E2D1569B63400C1D181 /* BLKUrlModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BLKUrlModel.m; path = src/BLKUrlModel.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -523,6 +526,8 @@
isa = PBXGroup;
children = (
ED3F3544155333950036E096 /* Constants.h */,
EDEF9E2C1569B63400C1D181 /* BLKUrlModel.h */,
EDEF9E2D1569B63400C1D181 /* BLKUrlModel.m */,
);
name = model;
sourceTree = "<group>";
Expand Down Expand Up @@ -695,6 +700,7 @@
ED0FC91A1553D1DE00E6DF2D /* SBJsonBase.m in Sources */,
ED0FC91B1553D1DE00E6DF2D /* SBJsonParser.m in Sources */,
ED0FC91C1553D1DE00E6DF2D /* SBJsonWriter.m in Sources */,
EDEF9E2E1569B63400C1D181 /* BLKUrlModel.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 0 additions & 2 deletions bLock_iOS/bLock/BLKAppDelegate.h
Expand Up @@ -9,7 +9,5 @@
#import <UIKit/UIKit.h>

@interface BLKAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end
4 changes: 4 additions & 0 deletions bLock_iOS/bLock/BLKAppDelegate.m
Expand Up @@ -7,6 +7,7 @@
//

#import "BLKAppDelegate.h"
#import "BLKUrlModel.h"

@implementation BLKAppDelegate

Expand All @@ -15,6 +16,7 @@ @implementation BLKAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
NSLog(@"%@", [[BLKUrlModel sharedInstance] getURLForPath:@"ABC"]);
return YES;
}

Expand Down Expand Up @@ -58,4 +60,6 @@ - (void)applicationWillTerminate:(UIApplication *)application
*/
}



@end
1 change: 0 additions & 1 deletion bLock_iOS/bLock/FAFeedViewMapController.m
Expand Up @@ -8,7 +8,6 @@

#import "FAFeedViewMapController.h"
#import <QuartzCore/QuartzCore.h>
#import "Constants.h"

@implementation FAFeedViewMapController
@synthesize mapView=_mapView;
Expand Down
8 changes: 6 additions & 2 deletions bLock_iOS/bLock/src/BLKTimeLeftViewController.m
Expand Up @@ -7,6 +7,7 @@
//

#import "BLKTimeLeftViewController.h"
#import "BLKUrlModel.h"

@interface BLKTimeLeftViewController ()
@end
Expand Down Expand Up @@ -52,8 +53,11 @@ - (IBAction)onWantsToLockupBike:(id)sender {

// Toggle
NSString* urlString = NULL;
if ( isLocked ) urlString = @"http://192.168.43.144:8666/rider/lock-value/set/1/true";
else urlString = @"http://192.168.43.144:8666/rider/lock-value/set/1/false";



if ( isLocked ) urlString = [[BLKUrlModel sharedInstance] getURLForPath:@"rider/lock-value/set/1/true"];
else urlString = [[BLKUrlModel sharedInstance] getURLForPath:@"rider/lock-value/set/1/false"];

[self setAsiHttpRequest: [ASIFormDataRequest requestWithURL:[NSURL URLWithString: urlString ]]];
[asiHttpRequest setUseKeychainPersistence: YES];
Expand Down
8 changes: 3 additions & 5 deletions bLock_iOS/bLock/src/BLKUnlockMapViewController.m
Expand Up @@ -7,9 +7,7 @@
//

#import "BLKUnlockMapViewController.h"



#import "BLKUrlModel.h"

@implementation BLKUnlockMapViewController
@synthesize unlockButton;
Expand Down Expand Up @@ -47,7 +45,7 @@ - (void)loadView
- (void)viewDidLoad {
[super viewDidLoad];

NSString* urlString = @"http://192.168.43.144:8666/rider/0/get-active-bike";
NSString* urlString = [[BLKUrlModel sharedInstance] getURLForPath:@"rider/0/get-active-bike"];
ASIFormDataRequest* asiHttpRequest = [ASIFormDataRequest requestWithURL:[NSURL URLWithString: urlString ]];
[asiHttpRequest setUseKeychainPersistence: YES];
[asiHttpRequest setDelegate:self];
Expand All @@ -56,7 +54,7 @@ - (void)viewDidLoad {
[asiHttpRequest setDidFinishSelector:@selector(requestFinished:)];
[asiHttpRequest setDidFailSelector:@selector(requestFailed:)];
[asiHttpRequest setUseCookiePersistence:YES];
[asiHttpRequest startAsynchronous];
// [asiHttpRequest startAsynchronous];

self.navigationController.navigationBar.hidden = YES;
[self setupMap];
Expand Down
15 changes: 15 additions & 0 deletions bLock_iOS/bLock/src/BLKUrlModel.h
@@ -0,0 +1,15 @@
//
// BLKUrlModel.h
// bLock
//
// Created by Mario Gonzalez on 5/20/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
@interface BLKUrlModel : NSObject {
}

+(BLKUrlModel*) sharedInstance;;
-(NSString*)getURLForPath:(NSString*)aPath;
@end
40 changes: 40 additions & 0 deletions bLock_iOS/bLock/src/BLKUrlModel.m
@@ -0,0 +1,40 @@
//
// BLKUrlModel.m
// bLock
//
// Created by Mario Gonzalez on 5/20/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "BLKUrlModel.h"
#import "Constants.h"

@implementation BLKUrlModel

-(NSString*) getURLForPath:(NSString*)aPath {

NSString* returnString = [NSString stringWithFormat:@"%@://%@%@:%@/%@", kURLPrefixServerProtocol, kURLPrefixServerSubdomain, kURLPrefixServerDomain, kURLPrefixServerPort, aPath];
NSLog( @"BLKUrlModel::getURLForPath - %@", returnString );
return returnString;
}


#pragma mark Singleton Implementation
static BLKUrlModel* __instance = nil;
+(BLKUrlModel*) sharedInstance {
if(__instance) return __instance;
@synchronized( [BLKUrlModel class] ) {
if(!__instance) {
__instance = [[self alloc] init];
}
return __instance;
}

NSLog(@"Error creating CoreDataController singleton!");
return nil;
}

+(void)end {
__instance = nil;
};
@end
12 changes: 11 additions & 1 deletion bLock_iOS/bLock/src/Constants.h
Expand Up @@ -6,13 +6,23 @@
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//



#ifndef __B_LOCK_CONSTANTS_H_
#define __B_LOCK_CONSTANTS_H_

#define ARC4RANDOM_MAX 0x100000000

// Core data model
static NSString *const kCoreDataModelNameBikes = @"Bikes";
static NSString* const kCoreDataModelNameBikes = @"Bikes";
static NSString* const kURLPrefixServerProtocol = @"http";
static NSString* const kURLPrefixServerSubdomain = @"";
static NSString* const kURLPrefixServerDomain = @"localhost";
static NSString* const kURLPrefixServerPort = @"8666";


// http://localhost:8666/rider/lock-value/set/0/false
// http://localhost:8666/rider/lock-value/set/0/true
// http://localhost:8666/rider/lock-value/get/0

#endif

0 comments on commit b15ec7a

Please sign in to comment.