//
//  LRRestyClient+PATCH.m
//  Assist Software
//
//  Created by Ovidiu on 6/19/13.
//  Copyright (c) 2013 LoopMe. All rights reserved.
//

#import "LRRestyClient+PATCH.h"
#import "LRRestyClientBlockDelegate.h"
#import "LRRestyClientProxyDelegate.h"
#import "NSObject+SynchronousProxy.h"

@implementation LRRestyClient (PATCH)

#pragma mark -
#pragma mark Delegate API

- (LRRestyRequest *)patch:(NSString *)urlString payload:(id)payload delegate:(id<LRRestyClientResponseDelegate>)delegate;
{
    return [self patch:urlString payload:payload headers:nil delegate:delegate];
}

- (LRRestyRequest *)patch:(NSString *)urlString payload:(id)payload headers:(NSDictionary *)headers delegate:(id<LRRestyClientResponseDelegate>)delegate;
{
    return [HTTPClient PATCH:[NSURL URLWithString:urlString] payload:payload headers:headers delegate:[LRRestyClientProxyDelegate proxyForClient:self responseDelegate:delegate]];
}

#pragma mark -
#pragma mark Blocks API

- (LRRestyRequest *)patch:(NSString *)urlString payload:(id)payload withBlock:(LRRestyResponseBlock)block;
{
    return [self patch:urlString payload:payload headers:nil withBlock:block];
}

- (LRRestyRequest *)patch:(NSString *)urlString payload:(id)payload headers:(NSDictionary *)headers withBlock:(LRRestyResponseBlock)block;
{
    return [HTTPClient PATCH:[NSURL URLWithString:urlString] payload:payload headers:headers delegate:[LRRestyClientBlockDelegate delegateWithBlock:block]];
}

#pragma mark -
#pragma mark Synchronous API

- (LRRestyResponse *)patch:(NSString *)urlString payload:(id)payload;
{
    return [self performAsynchronousBlockAndReturnResultWhenReady:^(__strong id *result)
            {
                [self patch:urlString payload:payload withBlock:^(LRRestyResponse *response) {
                    *result = response;
                }];
            }];
}

- (LRRestyResponse *)patch:(NSString *)urlString payload:(id)payload headers:(NSDictionary *)headers;
{
    return [self performAsynchronousBlockAndReturnResultWhenReady:^(__strong id *result)
            {
                [self patch:urlString payload:payload headers:headers withBlock:^(LRRestyResponse *response) {
                    *result = response;
                }];
            }];
}

@end
