This repository has been archived by the owner on Jan 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathLRRestyResource.m
82 lines (68 loc) · 1.86 KB
/
LRRestyResource.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//
// LRRestyResource.m
// LRResty
//
// Created by Luke Redpath on 06/08/2010.
// Copyright 2010 LJR Software Limited. All rights reserved.
//
#import "LRRestyResource.h"
@interface LRRestyResource ()
- (void)becomeClientDelegate;
@end
@implementation LRRestyResource
@synthesize delegate;
- (id)initWithRestClient:(LRRestyClient *)theClient URL:(NSURL *)aURL;{
if (self = [super init]) {
restClient = [theClient retain];
restClient.delegate = self;
URL = [aURL copy];
}
return self;
}
- (id)initWithRestClient:(LRRestyClient *)theClient URL:(NSURL *)aURL parent:(LRRestyResource *)parent;
{
if (self = [self initWithRestClient:theClient URL:aURL]) {
parentResource = [parent retain];
delegate = parentResource.delegate;
}
return self;
}
- (void)dealloc
{
[parentResource becomeClientDelegate];
[parentResource release];
[URL release];
[restClient release];
[super dealloc];
}
- (void)becomeClientDelegate
{
restClient.delegate = self;
}
- (NSString *)description
{
return [NSString stringWithFormat:@"%@ <LRRestyResource>", [URL absoluteString]];
}
- (void)restyClientWillPerformRequest:(LRRestyClient *)client
{
if ([self.delegate respondsToSelector:@selector(resourceWillPerformRequest:)]) {
[self.delegate resourceWillPerformRequest:self];
}
}
- (void)restyClientDidPerformRequest:(LRRestyClient *)client
{
if ([self.delegate respondsToSelector:@selector(resourceDidPerformRequest:)]) {
[self.delegate resourceDidPerformRequest:self];
}
}
- (LRRestyResource *)at:(NSString *)path;
{
return [[[LRRestyResource alloc] initWithRestClient:restClient URL:[URL URLByAppendingPathComponent:path] parent:self] autorelease];
}
- (void)get:(LRRestyResourceResponseBlock)responseBlock;
{
[restClient getURL:URL parameters:nil headers:nil withBlock:^(LRRestyResponse *response){
responseBlock(response, self);
}];
}
@end