https://github.com/wordpress-mobile/wpxmlrpc
A lightweight XML-RPC encoder/decoder for iOS, OS X, and tvOS
https://github.com/wordpress-mobile/wpxmlrpc
Last synced: 11 months ago
JSON representation
A lightweight XML-RPC encoder/decoder for iOS, OS X, and tvOS
- Host: GitHub
- URL: https://github.com/wordpress-mobile/wpxmlrpc
- Owner: wordpress-mobile
- License: other
- Created: 2013-02-19T21:04:06.000Z (about 13 years ago)
- Default Branch: trunk
- Last Pushed: 2024-01-29T22:46:55.000Z (about 2 years ago)
- Last Synced: 2025-03-24T07:41:48.054Z (11 months ago)
- Language: Objective-C
- Homepage:
- Size: 1020 KB
- Stars: 87
- Watchers: 26
- Forks: 34
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
- Support: Support/Info-Tests.plist
Awesome Lists containing this project
README
# WordPress XML-RPC Framework
The WordPress XML-RPC library is a lightweight XML-RPC client for iOS
and OS X.
It's based on Eric Czarny's Cocoa XML-RPC Framework, but without all the
networking code, and a few additions of our own.
# Installation
WordPress XML-RPC uses [CocoaPods](http://cocoapods.org/) for easy
dependency management.
Just add this to your Podfile and run `pod install`:
pod 'wpxmlrpc'
Another option, if you don't use CocoaPods, is to copy the `WPXMLRPC`
folder to your project.
# Usage
WordPress XML-RPC only provides classes to encode and decode XML-RPC. You are free to use your favorite networking library.
## Building a XML-RPC request
NSURL *URL = [NSURL URLWithString:@"http://example.com/xmlrpc"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:URL];
[request setHTTPMethod:@"POST"];
WPXMLRPCEncoder *encoder = [[WPXMLRPCEncoder alloc] initWithMethod:@"demo.addTwoNumbers" andParameters:@[@1, @2]];
[request setHTTPBody:[encoder dataEncodedWithError:nil]];
## Building a XML-RPC request using streaming
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *directory = [paths objectAtIndex:0];
NSString *guid = [[NSProcessInfo processInfo] globallyUniqueString];
NSString *streamingCacheFilePath = [directory stringByAppendingPathComponent:guid];
NSURL *URL = [NSURL URLWithString:@"http://example.com/xmlrpc"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:URL];
[request setHTTPMethod:@"POST"];
NSInputStream *fileStream = [NSInputStream inputStreamWithFileAtPath:filePath];
WPXMLRPCEncoder *encoder = [[WPXMLRPCEncoder alloc] initWithMethod:@"test.uploadFile" andParameters:@[fileStream]];
[encoder encodeToFile:streamingCacheFilePath error:nil];
NSError *error = nil;
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:&error];
unsigned long contentLength = [[attributes objectForKey:NSFileSize] unsignedIntegerValue];
NSInputStream * inputStream = [NSInputStream inputStreamWithFileAtPath:filePath];
[request setHTTPBodyStream:inputStream];
[request setValue:[NSString stringWithFormat:@"%lu", contentLength] forHTTPHeaderField:@"Content-Length"];
## Parsing a XML-RPC response
NSData *responseData = …
WPXMLRPCDecoder *decoder = [[WPXMLRPCDecoder alloc] initWithData:responseData];
if ([decoder isFault]) {
NSLog(@"XML-RPC error %@: %@", [decoder faultCode], [decoder faultString]);
} else {
NSLog(@"XML-RPC response: %@", [decoder object]);
}
# Acknowledgments
The Base64 encoder/decoder found in NSData+Base64 is created by [Matt Gallagher](http://cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html).
The original Cocoa XML-RPC Framework was developed by [Eric Czarny](https://github.com/eczarny/xmlrpc) and now lives at [github.com/corristo/xmlrpc](https://github.com/corristo/xmlrpc)