This repository has been archived by the owner on Jan 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feature/#6
- Loading branch information
Showing
19 changed files
with
770 additions
and
57 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// | ||
// PhillyBikeSharePrefixHeader.pch | ||
// Philly Bike Share | ||
// | ||
// Created by Morgis, Matthew on 5/24/15. | ||
// Copyright (c) 2015 Rappid Development. All rights reserved. | ||
// | ||
|
||
#ifndef Philly_Bike_Share_PhillyBikeSharePrefixHeader_pch | ||
#define Philly_Bike_Share_PhillyBikeSharePrefixHeader_pch | ||
|
||
#ifdef DEBUG | ||
#define DLog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__]) | ||
#define ALog(...) [[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString stringWithCString:__PRETTY_FUNCTION__ encoding:NSUTF8StringEncoding] file:[NSString stringWithCString:__FILE__ encoding:NSUTF8StringEncoding] lineNumber:__LINE__ description:__VA_ARGS__] | ||
#else | ||
#define DLog(...) do { } while (0) | ||
#define ALog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__]) | ||
|
||
#ifndef NS_BLOCK_ASSERTIONS | ||
#define NS_BLOCK_ASSERTIONS | ||
#endif | ||
#endif | ||
|
||
// printing out frame, bounds, and point | ||
#define printFrame(uiview) DLog(@"%@", [NSString stringWithFormat:@"frame: origin_x: %f, origin_y: %f size_width: %f, size_height: %f", uiview.frame.origin.x, uiview.frame.origin.y, uiview.frame.size.width, uiview.frame.size.height]) | ||
|
||
#define printRect(cgrect) DLog(@"%@", [NSString stringWithFormat:@"rect: origin_x: %f, origin_y: %f size_width: %f, size_height: %f", cgrect.origin.x, cgrect.origin.y, cgrect.size.width, cgrect.size.height]) | ||
|
||
#define printBounds(uiview) DLog(@"%@", [NSString stringWithFormat:@"frame: origin_x: %f, origin_y: %f size_width: %f, size_height: %f", uiview.bounds.origin.x, uiview.bounds.origin.y, uiview.bounds.size.width, uiview.bounds.size.height]) | ||
#define printPoint(cgpoint) DLog(@"%@", [NSString stringWithFormat:@"point: origin_x: %f, origin_y: %f", cgpoint.x, cgpoint.y]) | ||
|
||
#define alertFeatureNotYetImplemented() [[[UIAlertView alloc ] initWithTitle:@"Feature Not Implemented" message:@"This feature is not implemented yet." delegate:self cancelButtonTitle:@"Okay"otherButtonTitles:nil] show]; | ||
|
||
#define IS_IOS_ABOVE_7 (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1) | ||
|
||
// when termining the platform type, use these helpers | ||
#define PlatformType UI_USER_INTERFACE_IDIOM() | ||
#define iPad UIUserInterfaceIdiomPad | ||
#define iPhone UIUserInterfaceIdiomPhone | ||
|
||
// Object defines | ||
#define ApplicationDelegate ((AppDelegate *)[[UIApplication sharedApplication] delegate]) | ||
#define UserDefaults [NSUserDefaults standardUserDefaults] | ||
#define NotificationCenter [NSNotificationCenter defaultCenter] | ||
#define SharedApplication [UIApplication sharedApplication] | ||
#define Bundle [NSBundle mainBundle] | ||
#define MainScreen [UIScreen mainScreen] | ||
#define ShowNetworkActivityIndicator() [UIApplication sharedApplication].networkActivityIndicatorVisible = YES | ||
#define HideNetworkActivityIndicator() [UIApplication sharedApplication].networkActivityIndicatorVisible = NO | ||
#define NetworkActivityIndicatorVisible(x) [UIApplication sharedApplication].networkActivityIndicatorVisible = x | ||
#define NavBar self.navigationController.navigationBar | ||
#define TabBar self.tabBarController.tabBar | ||
#define NavBarHeight self.navigationController.navigationBar.bounds.size.height | ||
#define TabBarHeight self.tabBarController.tabBar.bounds.size.height | ||
#define ScreenWidth [[UIScreen mainScreen] bounds].size.width | ||
#define ScreenHeight [[UIScreen mainScreen] bounds].size.height | ||
#define TouchHeightDefault 44 | ||
#define TouchHeightSmall 32 | ||
|
||
// View getter functions | ||
#define ViewWidth(v) v.frame.size.width | ||
#define ViewHeight(v) v.frame.size.height | ||
#define ViewX(v) v.frame.origin.x | ||
#define ViewY(v) v.frame.origin.y | ||
#define SelfViewWidth self.view.bounds.size.width | ||
#define SelfViewHeight self.view.bounds.size.height | ||
|
||
// Frame getter functions | ||
#define RectX(f) f.origin.x | ||
#define RectY(f) f.origin.y | ||
#define RectWidth(f) f.size.width | ||
#define RectHeight(f) f.size.height | ||
|
||
// Frame settings functions | ||
#define RectSetWidth(f, w) CGRectMake(RectX(f), RectY(f), w, RectHeight(f)) | ||
#define RectSetHeight(f, h) CGRectMake(RectX(f), RectY(f), RectWidth(f), h) | ||
#define RectShiftXBy(f, deltaX) CGRectMake(RectX(f)+deltaX, RectY(f), RectWidth(f), RectHeight(f)) | ||
#define RectShiftYBy(f, deltaY) CGRectMake(RectX(f), RectY(f)+deltaY, RectWidth(f), RectHeight(f)) | ||
#define RectSetX(f, x) CGRectMake(x, RectY(f), RectWidth(f), RectHeight(f)) | ||
#define RectSetY(f, y) CGRectMake(RectX(f), y, RectWidth(f), RectHeight(f)) | ||
#define RectSetSize(f, w, h) CGRectMake(RectX(f), RectY(f), w, h) | ||
#define RectSetOrigin(f, x, y) CGRectMake(x, y, RectWidth(f), RectHeight(f)) | ||
|
||
// Date functions | ||
#define DATE_COMPONENTS NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit | ||
#define TIME_COMPONENTS NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit | ||
#define FlushPool(p) [p drain]; p = [[NSAutoreleasePool alloc] init] | ||
|
||
// Color functions | ||
#define RGB(r, g, b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0] | ||
#define RGBA(r, g, b, a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a] | ||
#define HEXCOLOR(c) [UIColor colorWithRed:((c>>16)&0xFF)/255.0 green:((c>>8)&0xFF)/255.0 blue:(c&0xFF)/255.0 alpha:1.0]; | ||
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] | ||
|
||
#endif |
17 changes: 17 additions & 0 deletions
17
Philly Bike Share/Managers & Helpers/Networking/Commands/PhillyBikeShareGetAllDataCommand.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// PhillyBikeShareGetAllDataCommand.h | ||
// Philly Bike Share | ||
// | ||
// Created by Morgis, Matthew on 5/24/15. | ||
// Copyright (c) 2015 Rappid Development. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "PhillyBikeShareNetworkCommandProtocol.h" | ||
|
||
@interface PhillyBikeShareGetAllDataCommand : NSObject <PhillyBikeShareNetworkCommandProtocol> | ||
|
||
- (instancetype)initWithSuccessBlock:(AFHTTPRequestOperationSuccessBlock)success | ||
andFailureBlock:(AFHTTPRequestOperationFailureBlock)failure; | ||
|
||
@end |
50 changes: 50 additions & 0 deletions
50
Philly Bike Share/Managers & Helpers/Networking/Commands/PhillyBikeShareGetAllDataCommand.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// PhillyBikeShareGetAllDataCommand.m | ||
// Philly Bike Share | ||
// | ||
// Created by Morgis, Matthew on 5/24/15. | ||
// Copyright (c) 2015 Rappid Development. All rights reserved. | ||
// | ||
|
||
#import "PhillyBikeShareGetAllDataCommand.h" | ||
#import "PhillyBikeShareNetworkCommand.h" | ||
|
||
@interface PhillyBikeShareGetAllDataCommand() | ||
|
||
@property (nonatomic, copy) AFHTTPRequestOperationSuccessBlock successHandler; | ||
@property (nonatomic, copy) AFHTTPRequestOperationFailureBlock failureHandler; | ||
|
||
@end | ||
|
||
@implementation PhillyBikeShareGetAllDataCommand | ||
|
||
- (instancetype)initWithSuccessBlock:(AFHTTPRequestOperationSuccessBlock)success andFailureBlock:(AFHTTPRequestOperationFailureBlock)failure { | ||
|
||
self = [super init]; | ||
|
||
if (!self) { | ||
return nil; | ||
} | ||
|
||
self.successHandler = [success copy]; | ||
self.failureHandler = [failure copy]; | ||
|
||
return self; | ||
} | ||
|
||
- (void)execute { | ||
|
||
NSString *url = @"https://api.phila.gov/bike-share-stations/v1"; | ||
NSString *method = @"GET"; | ||
|
||
PhillyBikeShareNetworkCommand *command = [[PhillyBikeShareNetworkCommand alloc] initWithUrl:url andMethod:method andJsonRequest:YES andParameters:nil andSuccessBlock:^(AFHTTPRequestOperation *operation, id responseObject) { | ||
|
||
self.successHandler(operation, responseObject); | ||
} andFailureBlock:^(AFHTTPRequestOperation *operation, NSError *error) { | ||
self.failureHandler(operation, error); | ||
}]; | ||
|
||
[command execute]; | ||
} | ||
|
||
@end |
26 changes: 26 additions & 0 deletions
26
Philly Bike Share/Managers & Helpers/Networking/PhillyBikeShareNetworkCommand.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// PhillyBikeShareNetworkCommand.h | ||
// Philly Bike Share | ||
// | ||
// Created by Morgis, Matthew on 5/24/15. | ||
// Copyright (c) 2015 Rappid Development. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "PhillyBikeShareNetworkCommandProtocol.h" | ||
|
||
@interface PhillyBikeShareNetworkCommand : NSObject <PhillyBikeShareNetworkCommandProtocol> | ||
|
||
- (instancetype)initWithUrl:(NSString *)url | ||
andParameters:(NSDictionary *)parameters | ||
andSuccessBlock:(AFHTTPRequestOperationSuccessBlock)success | ||
andFailureBlock:(AFHTTPRequestOperationFailureBlock)failure; | ||
|
||
- (instancetype)initWithUrl:(NSString *)url | ||
andMethod:(NSString *)method | ||
andJsonRequest:(BOOL)jsonRequest | ||
andParameters:(NSDictionary *)parameters | ||
andSuccessBlock:(AFHTTPRequestOperationSuccessBlock)success | ||
andFailureBlock:(AFHTTPRequestOperationFailureBlock)failure; | ||
|
||
@end |
105 changes: 105 additions & 0 deletions
105
Philly Bike Share/Managers & Helpers/Networking/PhillyBikeShareNetworkCommand.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// | ||
// PhillyBikeShareNetworkCommand.m | ||
// Philly Bike Share | ||
// | ||
// Created by Morgis, Matthew on 5/24/15. | ||
// Copyright (c) 2015 Rappid Development. All rights reserved. | ||
// | ||
|
||
#import "PhillyBikeShareNetworkCommand.h" | ||
#import <AFNetworking.h> | ||
#import <AFNetworking/AFHTTPRequestOperation.h> | ||
|
||
@interface PhillyBikeShareNetworkCommand() | ||
|
||
@property (nonatomic, copy) AFHTTPRequestOperationSuccessBlock successHandler; | ||
@property (nonatomic, copy) AFHTTPRequestOperationFailureBlock failureHandler; | ||
@property (nonatomic, strong) NSString *url; | ||
@property (nonatomic, strong) NSDictionary *parameters; | ||
@property (nonatomic, strong) NSString *method; | ||
@property (nonatomic, assign) BOOL jsonRequest; | ||
|
||
@end | ||
|
||
@implementation PhillyBikeShareNetworkCommand | ||
|
||
- (instancetype)initWithUrl:(NSString *)url | ||
andParameters:(NSDictionary *)parameters | ||
andSuccessBlock:(AFHTTPRequestOperationSuccessBlock)success | ||
andFailureBlock:(AFHTTPRequestOperationFailureBlock)failure { | ||
self = [super init]; | ||
|
||
if (!self) { | ||
return nil; | ||
} | ||
|
||
self.successHandler = [success copy]; | ||
self.failureHandler = [failure copy]; | ||
self.parameters = parameters; | ||
self.url = url; | ||
|
||
if (!self.method) { | ||
self.method = @"POST"; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (instancetype)initWithUrl:(NSString *)url | ||
andMethod:(NSString *)method | ||
andJsonRequest:(BOOL)jsonRequest | ||
andParameters:(NSDictionary *)parameters | ||
andSuccessBlock:(AFHTTPRequestOperationSuccessBlock)success | ||
andFailureBlock:(AFHTTPRequestOperationFailureBlock)failure { | ||
|
||
self.method = method; | ||
self.jsonRequest = jsonRequest; | ||
|
||
return [self initWithUrl:url andParameters:parameters andSuccessBlock:success andFailureBlock:failure]; | ||
} | ||
|
||
- (void)execute { | ||
|
||
// setup the manager | ||
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; | ||
|
||
if (self.jsonRequest) { | ||
AFJSONRequestSerializer *requestSerializer = [AFJSONRequestSerializer serializer]; | ||
[requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"]; | ||
[manager setRequestSerializer:requestSerializer]; | ||
manager.responseSerializer = [AFJSONResponseSerializer serializer]; | ||
//Needed because the API doesn't technically return JSON data. | ||
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"]; | ||
} else { | ||
AFJSONRequestSerializer *requestSerializer = [AFJSONRequestSerializer serializer]; | ||
[requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; | ||
[manager setRequestSerializer:requestSerializer]; | ||
} | ||
|
||
SEL methodSelector = NSSelectorFromString([[NSString alloc] | ||
initWithFormat:@"%@:%@", self.method,@"parameters:success:failure:"]); | ||
|
||
NSMethodSignature *signature = [manager methodSignatureForSelector:methodSelector]; | ||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature ]; | ||
[invocation setSelector:methodSelector]; | ||
[invocation setArgument:&_url atIndex:2]; | ||
[invocation setArgument:&_parameters atIndex:3]; | ||
|
||
// define the success and failure blocks to pass to the manager | ||
void (^successBlock)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) { | ||
self.successHandler(operation, responseObject); | ||
}; | ||
|
||
void (^failureBlock)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) { | ||
self.failureHandler(operation, error); | ||
}; | ||
successBlock = [successBlock copy]; | ||
failureBlock = [failureBlock copy]; | ||
[invocation setArgument:&successBlock atIndex:4]; | ||
[invocation setArgument:&failureBlock atIndex:5]; | ||
|
||
// Invoke the method | ||
[invocation invokeWithTarget:manager]; | ||
} | ||
|
||
@end |
22 changes: 22 additions & 0 deletions
22
Philly Bike Share/Managers & Helpers/Networking/PhillyBikeShareNetworkCommandProtocol.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// PhillyBikeShareNetworkCommandProtocol.h | ||
// Philly Bike Share | ||
// | ||
// Created by Morgis, Matthew on 5/24/15. | ||
// Copyright (c) 2015 Rappid Development. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <AFNetworking/AFHTTPRequestOperation.h> | ||
|
||
/** | ||
* Block definitions | ||
*/ | ||
typedef void (^AFHTTPRequestOperationSuccessBlock) (AFHTTPRequestOperation *operation, id responseObject); | ||
typedef void (^AFHTTPRequestOperationFailureBlock) (AFHTTPRequestOperation *operation, NSError *error); | ||
|
||
@protocol PhillyBikeShareNetworkCommandProtocol <NSObject> | ||
|
||
- (void)execute; | ||
|
||
@end |
23 changes: 23 additions & 0 deletions
23
Philly Bike Share/Managers & Helpers/PhillyBikeShareLocationManager.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// PhillyBikeShareLocationManager.h | ||
// Philly Bike Share | ||
// | ||
// Created by Morgis, Matthew on 5/24/15. | ||
// Copyright (c) 2015 Rappid Development. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
typedef void (^PhillyBikeShareSuccessBlock) (NSArray *locations); | ||
typedef void (^PhillyBikeShareFailureBlock) (NSError *error); | ||
|
||
@interface PhillyBikeShareLocationManager : NSObject | ||
|
||
+ (instancetype)sharedInstance; | ||
|
||
- (void)fetchAllLocationsWithSuccessBlock:(PhillyBikeShareSuccessBlock)successBlock | ||
andFailureBlock:(PhillyBikeShareFailureBlock)failureBlock; | ||
|
||
- (id)getPhillyBikeShareLocationById:(NSInteger)phillyBikeShareLocationId; | ||
|
||
@end |
Oops, something went wrong.