Permalink
Browse files

Support custom headers for client

  • Loading branch information...
1 parent ff249aa commit 39e84dd08d85b15c3fc9a2f5e6d6fe08195497a6 @sebreh sebreh committed Jan 27, 2014
Showing with 14 additions and 0 deletions.
  1. +2 −0 PodioKit/Core/PKTClient.h
  2. +4 −0 PodioKit/Core/PKTClient.m
  3. +8 −0 PodioKitTests/PKTClientTests.m
View
2 PodioKit/Core/PKTClient.h
@@ -19,6 +19,8 @@ typedef void(^PKTRequestCompletionBlock)(PKTResponse *response, NSError *error);
- (instancetype)initWithAPIKey:(NSString *)key secret:(NSString *)secret;
+- (void)setValue:(NSString *)value forHTTPHeader:(NSString *)header;
+
- (void)performRequest:(PKTRequest *)request completion:(PKTRequestCompletionBlock)completion;
@end
View
4 PodioKit/Core/PKTClient.m
@@ -45,6 +45,10 @@ - (instancetype)initWithAPIKey:(NSString *)key secret:(NSString *)secret {
#pragma mark - Public
+- (void)setValue:(NSString *)value forHTTPHeader:(NSString *)header {
+ [self.requestSerializer setValue:value forHTTPHeaderField:header];
+}
+
- (void)performRequest:(PKTRequest *)request completion:(PKTRequestCompletionBlock)completion {
NSURLSessionTask *task = [self taskWithRequest:request completion:completion];
[task resume];
View
8 PodioKitTests/PKTClientTests.m
@@ -112,4 +112,12 @@ - (void)testURLRequestForDELETERequest {
expect([[urlRequest allHTTPHeaderFields][@"X-Podio-Request-Id"] length]).to.beGreaterThan(0);
}
+- (void)testSetCustomHeader {
+ PKTRequest *request = [PKTRequest PUTRequestWithPath:@"/some/path" parameters:nil];
+
+ [self.testClient setValue:@"Header value" forHTTPHeader:@"X-Test-Header"];
+ NSURLRequest *urlRequest = [self.testClient URLRequestForRequest:request];
+ expect([urlRequest allHTTPHeaderFields][@"X-Test-Header"]).to.equal(@"Header value");
+}
+
@end

0 comments on commit 39e84dd

Please sign in to comment.