Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
73 lines (58 sloc) 2.15 KB
// TravisHTTPClient.m
// Travis CI
// Created by Henrik Hodne on 11/10/12.
// Copyright (c) 2012 Travis CI GmbH. All rights reserved.
#import "TravisHTTPClient.h"
#import <AFNetworking/AFNetworking.h>
#import <ReactiveCocoa/ReactiveCocoa.h>
NSString * const kTravisBaseURL = @"";
@interface TravisHTTPClient ()
@property (nonatomic, strong) AFHTTPClient *HTTPClient;
@implementation TravisHTTPClient
+ (TravisHTTPClient *)standardHTTPClient {
return [[self alloc] initWithBaseURL:[NSURL URLWithString:kTravisBaseURL]];
- (id)initWithBaseURL:(NSURL *)baseURL {
self = [super init];
if (self == nil) return nil;
[self setupHTTPClientWithBaseURL:baseURL];
return self;
- (void)setupHTTPClientWithBaseURL:(NSURL *)baseURL {
[self setHTTPClient:[[AFHTTPClient alloc] initWithBaseURL:baseURL]];
[[self HTTPClient] registerHTTPOperationClass:[AFJSONRequestOperation class]];
[[self HTTPClient] setDefaultHeader:@"Accept" value:@"application/json"];
- (RACSignal *)requestWithMethod:(TravisHTTPClientMethod)method path:(NSString *)path parameters:(NSDictionary *)parameters {
RACReplaySubject *subject = [RACReplaySubject subject];
NSURLRequest *request = [[self HTTPClient] requestWithMethod:[self methodStringForMethod:method] path:path parameters:parameters];
AFHTTPRequestOperation *operation = [[self HTTPClient] HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
[subject sendNext:responseObject];
[subject sendCompleted];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[subject sendError:error];
[[self HTTPClient] enqueueHTTPRequestOperation:operation];
return subject;
- (NSString *)methodStringForMethod:(TravisHTTPClientMethod)method {
switch (method) {
case TravisHTTPClientMethodDELETE:
return @"DELETE";
case TravisHTTPClientMethodGET:
return @"GET";
case TravisHTTPClientMethodHEAD:
return @"HEAD";
case TravisHTTPClientMethodPATCH:
return @"PATCH";
case TravisHTTPClientMethodPOST:
return @"POST";
case TravisHTTPClientMethodPUT:
return @"PUT";
Jump to Line
Something went wrong with that request. Please try again.