Inherits from NSObject
Declared in PCJSONRPC.h

Overview

PCJSONRPC is a client used to communicate with JSON-RPC 2.0 services.

Tasks

Other Methods

Extension Methods

Properties

trace

@property BOOL trace
Discussion

Trace communications. Defaults to NO.

Declared In

PCJSONRPC.h

url

@property (strong, readonly) NSURL *url
Discussion

The service URL.

Declared In

PCJSONRPC.h

Instance Methods

JSONObjectWithData:error:

- (id)JSONObjectWithData:(NSData *)data error:(NSError **)error
Discussion

Subclass can override this selector to implements it’s own JSON deserialization.

Parameters

data

The JSON serialized object as NSData.

error

A NSError output parameter.

Return Value

The deserialized object.

Declared In

PCJSONRPCSubclass.h

dataWithJSONObject:error:

- (NSData *)dataWithJSONObject:(id)object error:(NSError **)error
Discussion

Subclass can override this selector to implements it’s own JSON serialization.

Parameters

object

The object to serialize.

error

A NSError output parameter.

Return Value

The JSON serialized object as NSData.

Declared In

PCJSONRPCSubclass.h

initWithURL:

- (instancetype)initWithURL:(NSURL *)url
Discussion

Initializes a JSON-RPC client.

Parameters

url

The service URL.

Return Value

An initialized PCJSONRPC instance.

Declared In

PCJSONRPC.h

invokeMethod:withParameters:error:

- (id)invokeMethod:(NSString *)method withParameters:(id)parameters error:(NSError **)error
Discussion

Synchronously invoke a remote JSON-RPC method with parameters and optional error output.

Parameters

method

The remote method to invoke.

parameters

The parameters NSArray (for positional parameters) or NSDictionary (for named parameters) or nil.

error

If an error occurs, upon return contains an NSError object that describes the problem.

Return Value

The JSON-RPC method result value.

Declared In

PCJSONRPC.h

proxyForProtocol:

- (id)proxyForProtocol:(Protocol *)protocol
Discussion

Create a JSON-RPC proxy given a Protocol.

The proxy object intercepts all the Protocol methods.

When a message is sent to one of the Protocol selector:

It uses the first part of the NSInvocation selector as the JSON-RPC method name.

If the NSInvocation contains at least one parameter, the first parameter is used as the JSON-RPC method parameters.

If the NSInvocation contains at least two parameters, the second parameter is used as an error output (NSError **).

If the NSInvocation contains more than two parameters, the third and the subsequents are ignored.

Parameters

protocol

The Protocol that contains the methods to be proxied.

Return Value

The JSON-RPC proxy.

Declared In

PCJSONRPC.h

requestIdForPartialPayload:error:

- (NSString *)requestIdForPartialPayload:(NSDictionary *)payload error:(NSError **)error
Discussion

Subclass can override this selector to implements it’s own request ID generation.

Parameters

payload

The JSON-RPC request payload without an ID.

error

A NSError output parameter.

Return Value

The generated request ID.

Declared In

PCJSONRPCSubclass.h

requestPayloadForMethod:andParameters:error:

- (NSDictionary *)requestPayloadForMethod:(NSString *)method andParameters:(id)parameters error:(NSError **)error
Discussion

Subclass can override this selector to implements it’s own request payload creation.

Parameters

method

The JSON-RPC request method name.

parameters

The JSON-RPC request parameters object.

error

A NSError output parameter.

Return Value

The request payload.

Declared In

PCJSONRPCSubclass.h

requestWithURL:andPayloadData:error:

- (NSURLRequest *)requestWithURL:(NSURL *)url andPayloadData:(NSData *)payloadData error:(NSError **)error
Discussion

Subclass can override this selector to implements it’s own URL request creation.

Parameters

url

The service URL.

payloadData

The JSON serialized request payload as NSData.

error

A NSError output parameter.

Return Value

The URL request.

Declared In

PCJSONRPCSubclass.h

responsePayloadDataFromRequest:error:

- (NSData *)responsePayloadDataFromRequest:(NSURLRequest *)request error:(NSError **)error
Discussion

Subclass can override this selector to implements it’s own URL request execution.

Parameters

request

The URL request.

error

A NSError output parameter.

Return Value

The JSON serialized response payload as NSData.

Declared In

PCJSONRPCSubclass.h

resultFromResponsePayload:error:

- (id)resultFromResponsePayload:(NSDictionary *)payload error:(NSError **)error
Discussion

Subclass can override this selector to implements it’s own response payload result/error parsing.

Parameters

error

A NSError output parameter.

request

The response payload.

Return Value

The JSON-RPC result.

Declared In

PCJSONRPCSubclass.h