Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 171 lines (146 sloc) 4.211 kb
01ce025 @jdg Add in extensions by Alberto Hierro (http://fi.am/)
jdg authored
1 //
2 // OACall.m
3 // OAuthConsumer
4 //
5 // Created by Alberto García Hierro on 04/09/08.
6 // Copyright 2008 Alberto García Hierro. All rights reserved.
7 // bynotes.com
8
9 #import "OAConsumer.h"
10 #import "OAToken.h"
11 #import "OAProblem.h"
12 #import "OADataFetcher.h"
13 #import "OAServiceTicket.h"
14 #import "OAMutableURLRequest.h"
15 #import "OACall.h"
16
17 @interface OACall (Private)
18
19 - (void)callFinished:(OAServiceTicket *)ticket withData:(NSData *)data;
20 - (void)callFailed:(OAServiceTicket *)ticket withError:(NSError *)error;
21
22 @end
23
24 @implementation OACall
25
26 @synthesize url, method, parameters, files, ticket;
27
28 - (id)init {
29 return [self initWithURL:nil
30 method:nil
31 parameters:nil
32 files:nil];
33 }
34
35 - (id)initWithURL:(NSURL *)aURL {
36 return [self initWithURL:aURL
37 method:nil
38 parameters:nil
39 files:nil];
40 }
41
42 - (id)initWithURL:(NSURL *)aURL method:(NSString *)aMethod {
43 return [self initWithURL:aURL
44 method:aMethod
45 parameters:nil
46 files:nil];
47 }
48
49 - (id)initWithURL:(NSURL *)aURL parameters:(NSArray *)theParameters {
50 return [self initWithURL:aURL
51 method:nil
52 parameters:theParameters];
53 }
54
55 - (id)initWithURL:(NSURL *)aURL method:(NSString *)aMethod parameters:(NSArray *)theParameters {
56 return [self initWithURL:aURL
57 method:aMethod
58 parameters:theParameters
59 files:nil];
60 }
61
62 - (id)initWithURL:(NSURL *)aURL parameters:(NSArray *)theParameters files:(NSDictionary*)theFiles {
63 return [self initWithURL:aURL
64 method:@"POST"
65 parameters:theParameters
66 files:theFiles];
67 }
68
69 - (id)initWithURL:(NSURL *)aURL
70 method:(NSString *)aMethod
71 parameters:(NSArray *)theParameters
72 files:(NSDictionary*)theFiles {
9b1db6c @adamjernst Fix a number of terrifying memory management errors.
adamjernst authored
73 if ((self = [super init])) {
74 url = [aURL retain];
75 method = [aMethod retain];
76 parameters = [theParameters retain];
77 files = [theFiles retain];
78 fetcher = nil;
79 request = nil;
80 }
01ce025 @jdg Add in extensions by Alberto Hierro (http://fi.am/)
jdg authored
81
82 return self;
83 }
84
85 - (void)dealloc {
86 [url release];
87 [method release];
88 [parameters release];
89 [files release];
90 [fetcher release];
91 [request release];
92 [ticket release];
93 [super dealloc];
94 }
95
96 - (void)callFailed:(OAServiceTicket *)aTicket withError:(NSError *)error {
97 NSLog(@"error body: %@", aTicket.body);
98 self.ticket = aTicket;
99 [aTicket release];
100 OAProblem *problem = [OAProblem problemWithResponseBody:ticket.body];
101 if (problem) {
102 [delegate call:self failedWithProblem:problem];
103 } else {
104 [delegate call:self failedWithError:error];
105 }
106 }
107
108 - (void)callFinished:(OAServiceTicket *)aTicket withData:(NSData *)data {
109 self.ticket = aTicket;
110 [aTicket release];
111 if (ticket.didSucceed) {
112 // NSLog(@"Call body: %@", ticket.body);
113 [delegate performSelector:finishedSelector withObject:self withObject:ticket.body];
114 } else {
115 // NSLog(@"Failed call body: %@", ticket.body);
116 [self callFailed:[ticket retain] withError:nil];
117 }
118 }
119
120 - (void)perform:(OAConsumer *)consumer
121 token:(OAToken *)token
122 realm:(NSString *)realm
123 delegate:(NSObject <OACallDelegate> *)aDelegate
124 didFinish:(SEL)finished
125
126 {
127 delegate = aDelegate;
128 finishedSelector = finished;
129
130 request = [[OAMutableURLRequest alloc] initWithURL:url
131 consumer:consumer
132 token:token
133 realm:realm
134 signatureProvider:nil];
135 if(method) {
136 [request setHTTPMethod:method];
137 }
138
139 if (self.parameters) {
140 [request setParameters:self.parameters];
141 }
00b116d @adamcohenrose Renamed Crytpo directory; Fixed LLVM warnings in OACall and OAToken
adamcohenrose authored
142 // if (self.files) {
143 // for (NSString *key in self.files) {
144 // [request attachFileWithName:@"file" filename:NSLocalizedString(@"Photo.jpg", @"") data:[self.files objectForKey:key]];
145 // }
146 // }
01ce025 @jdg Add in extensions by Alberto Hierro (http://fi.am/)
jdg authored
147 fetcher = [[OADataFetcher alloc] init];
148 [fetcher fetchDataWithRequest:request
149 delegate:self
150 didFinishSelector:@selector(callFinished:withData:)
151 didFailSelector:@selector(callFailed:withError:)];
152 }
153
154 /*- (BOOL)isEqual:(id)object {
155 if ([object isKindOfClass:[self class]]) {
156 return [self isEqualToCall:(OACall *)object];
157 }
158 return NO;
159 }
160
161 - (BOOL)isEqualToCall:(OACall *)aCall {
162 return (delegate == aCall->delegate
163 && finishedSelector == aCall->finishedSelector
164 && [url isEqualTo:aCall.url]
165 && [method isEqualToString:aCall.method]
166 && [parameters isEqualToArray:aCall.parameters]
167 && [files isEqualToDictionary:aCall.files]);
168 }*/
169
170 @end
Something went wrong with that request. Please try again.