Last active
August 29, 2015 14:05
-
-
Save ruairif/fecb63997d0dc0c8e60f to your computer and use it in GitHub Desktop.
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
#import <Foundation/Foundation.h> | |
#import <RestKit/RestKit.h> | |
#import "opcUtils.h" | |
@interface opcAPIRequests : NSObject | |
+ (NSMutableURLRequest*) sendRequestTo:(NSString*)relativeURL withMethod:(RKRequestMethod)reqMethod withUID:(NSString*)uid withKey:(NSString*)key; | |
+ (NSMutableURLRequest*) sendRequestTo:(NSString*)relativeURL withParams:(NSDictionary*)params withMethod:(RKRequestMethod)reqMethod withUID:(NSString*)uid withKey:(NSString*)key; | |
+ (NSMutableURLRequest*) sendRequestTo:(NSString*)relativeURL withParams:(NSDictionary*)params withMethod:(RKRequestMethod)reqMethod ; | |
@end |
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
#import "opcAPIRequests.h" | |
// uid refers to the uid that is returned with post to https://app.onpeagecrm.com/api/v3/login.json | |
// key refers to the base64 decoded key returned with the login request. | |
@implementation opcAPIRequests | |
+ (NSMutableURLRequest*) sendRequestTo:(NSString*)relativeURL withParams:(NSDictionary*)params withMethod:(RKRequestMethod)reqMethod { | |
RKObjectManager *objectManager = [RKObjectManager sharedManager]; | |
NSMutableURLRequest *request = [objectManager requestWithObject:nil method:reqMethod | |
path:relativeURL | |
parameters:params]; | |
[request addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; | |
return request; | |
} | |
+ (NSMutableURLRequest*) sendRequestTo:(NSString*)relativeURL withMethod:(RKRequestMethod)reqMethod withUID:(NSString*)uid withKey:(NSString*)key{ | |
RKObjectManager *objectManager = [RKObjectManager sharedManager]; | |
NSMutableURLRequest *request = [objectManager requestWithObject:nil method:reqMethod | |
path:relativeURL | |
parameters:nil]; | |
NSInteger timestamp = [[NSDate date] timeIntervalSince1970]; | |
[request addValue:uid forHTTPHeaderField:@"X-OnePageCRM-UID"]; | |
[request addValue:[NSString stringWithFormat:@"%d", timestamp ] forHTTPHeaderField:@"X-OnePageCRM-TS"]; | |
NSString* authSignature = [opcUtils returnAuthWithKey:key withUID:uid withTime:[NSString stringWithFormat:@"%d", timestamp ] withMethod:@"GET" withURL:[NSString stringWithFormat:@"%@%@",objectManager.baseURL,relativeURL]]; | |
[request addValue:authSignature forHTTPHeaderField:@"X-OnePageCRM-Auth"]; | |
return request; | |
} | |
+ (NSMutableURLRequest*) sendRequestTo:(NSString*)relativeURL withParams:(NSDictionary *)params withMethod:(RKRequestMethod)reqMethod withUID:(NSString*)uid withKey:(NSString*)key{ | |
RKObjectManager *objectManager = [RKObjectManager sharedManager]; | |
NSMutableURLRequest *request = [objectManager requestWithObject:nil method:reqMethod | |
path:relativeURL | |
parameters:params]; | |
NSInteger timestamp = [[NSDate date] timeIntervalSince1970]; | |
[request addValue:uid forHTTPHeaderField:@"X-OnePageCRM-UID"]; | |
[request addValue:[NSString stringWithFormat:@"%d", timestamp ] forHTTPHeaderField:@"X-OnePageCRM-TS"]; | |
NSString* authSignature = [opcUtils returnAuthWithKey:key withUID:uid withTime:[NSString stringWithFormat:@"%d", timestamp ] withMethod:@"GET" withURL:[NSString stringWithFormat:@"%@%@",objectManager.baseURL,relativeURL]]; | |
[request addValue:authSignature forHTTPHeaderField:@"X-OnePageCRM-Auth"]; | |
return request; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment