Code Monkey home page Code Monkey logo

wpxmlrpc's Introduction

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 for easy dependency management.

Just add this to your Podfile and run pod install:

pod 'wpxmlrpc', '~> 0.1'

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.body];

Building a XML-RPC request using streaming

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]];
[request setHTTPBodyStream:encoder.bodyStream];
[request setValue:[encoder.contentLength stringValue] 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.

The original Cocoa XML-RPC Framework was developed by Eric Czarny and now lives at github.com/corristo/xmlrpc

wpxmlrpc's People

Contributors

eczarny avatar koke avatar maccheck avatar astralbodies avatar tcurdt avatar jiggak avatar chiefy avatar

Watchers

James Cloos avatar Isaac Paul avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.