Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tag: 2.2
Fetching contributors…

Cannot retrieve contributors at this time

149 lines (113 sloc) 4.021 kB
//
// Copyright (c) 2009 Eric Czarny <eczarny@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
//
// Cocoa XML-RPC Framework
// XMLRPCRequest.m
//
// Created by Eric Czarny on Wednesday, January 14, 2004.
// Copyright (c) 2009 Divisible by Zero.
//
#import "XMLRPCRequest.h"
#import "XMLRPCEncoder.h"
@implementation XMLRPCRequest
- (id)initWithURL: (NSURL *)URL {
if (self = [super init]) {
if (URL) {
myRequest = [[NSMutableURLRequest alloc] initWithURL: URL];
} else {
myRequest = [[NSMutableURLRequest alloc] init];
}
myXMLEncoder = [[XMLRPCEncoder alloc] init];
}
return self;
}
#pragma mark -
- (void)setURL: (NSURL *)URL {
[myRequest setURL: URL];
}
- (NSURL *)URL {
return [myRequest URL];
}
#pragma mark -
- (void)setUserAgent: (NSString *)userAgent {
if (![self userAgent]) {
[myRequest addValue: userAgent forHTTPHeaderField: @"User-Agent"];
} else {
[myRequest setValue: userAgent forHTTPHeaderField: @"User-Agent"];
}
}
- (NSString *)userAgent {
return [myRequest valueForHTTPHeaderField: @"User-Agent"];
}
#pragma mark -
- (void)setMethod: (NSString *)method {
[myXMLEncoder setMethod: method withParameters: nil];
}
- (void)setMethod: (NSString *)method withParameter: (id)parameter {
NSArray *parameters = nil;
if (parameter) {
parameters = [NSArray arrayWithObject: parameter];
}
[myXMLEncoder setMethod: method withParameters: parameters];
}
- (void)setMethod: (NSString *)method withParameters: (NSArray *)parameters {
[myXMLEncoder setMethod: method withParameters: parameters];
}
#pragma mark -
- (NSString *)method {
return [myXMLEncoder method];
}
- (NSArray *)parameters {
return [myXMLEncoder parameters];
}
#pragma mark -
- (NSString *)body {
return [myXMLEncoder encode];
}
#pragma mark -
- (NSURLRequest *)request {
NSData *content = [[self body] dataUsingEncoding: NSUTF8StringEncoding];
NSNumber *contentLength = [NSNumber numberWithInt: [content length]];
if (!myRequest) {
return nil;
}
[myRequest setHTTPMethod: @"POST"];
if (![myRequest valueForHTTPHeaderField: @"Content-Type"]) {
[myRequest addValue: @"text/xml" forHTTPHeaderField: @"Content-Type"];
} else {
[myRequest setValue: @"text/xml" forHTTPHeaderField: @"Content-Type"];
}
if (![myRequest valueForHTTPHeaderField: @"Content-Length"]) {
[myRequest addValue: [contentLength stringValue] forHTTPHeaderField: @"Content-Length"];
} else {
[myRequest setValue: [contentLength stringValue] forHTTPHeaderField: @"Content-Length"];
}
[myRequest setHTTPBody: content];
return (NSURLRequest *)myRequest;
}
#pragma mark -
- (void)dealloc {
[myRequest release];
[myXMLEncoder release];
[super dealloc];
}
@end
Jump to Line
Something went wrong with that request. Please try again.