Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

OCTClient Methods

iRare Media edited this page Sep 22, 2013 · 4 revisions

Init

This is the designated initializer for the OCTClient class. Initializes the receiver to make requests to the given GitHub server.

- (id)initWithServer:(OCTServer *)server;

When using this initializer, the user property will not be set. +authenticatedClientWithUser:token: or +unauthenticatedClientWithUser: should typically be used instead.

Parameters

  • server - The GitHub server to connect to. This argument must not be nil.

Client with User and Token

Creates a client which will attempt to authenticate as the given user, using the given authorization token.

+ (instancetype)authenticatedClientWithUser:(OCTUser *)user token:(NSString *)token;

Note that this method does not actually perform a login or make a request to the server – it only sets an authorization header for future requests.

Parameters

  • user - The user to authenticate as. The user property of the returned client will be set to this object. This argument must not be nil.
  • token - The authorization token for the given user.

Return Value
A new client.


Client with User

Creates a client which can access any endpoints that don't require authentication.

+ (instancetype)unauthenticatedClientWithUser:(OCTUser *)user;

Parameters

  • user The active user. The user property of the returned client will be set to this object. This argument must not be nil.

Return Value
A new client.


Create Request

Creates a mutable URL request, which when sent will conditionally fetch the latest data from the server. If the latest data matches etag, nothing is downloaded and the call does not count toward the API rate limit.

- (NSMutableURLRequest *)requestWithMethod:(NSString *)method path:(NSString *)path parameters:(NSDictionary *)parameters notMatchingEtag:(NSString *)etag;

Parameters

  • method - The HTTP method to use in the request (e.g., "GET" or "POST").
  • path - The path to request, relative to the base API endpoint. This path should not begin with a forward slash.
  • parameters - HTTP parameters to encode and send with the request.
  • notMatchingEtag - An ETag to compare the server data against, previously retrieved from an instance of OCTResponse. If the content has not changed since, no new data will be fetched when this request is sent. This argument may be nil to always fetch the latest data.

Return Value
An NSMutableURLRequest that you can enqueue using -enqueueRequest:resultClass:.


Enqueue Request

Enqueues a request to be sent to the server.

- (RACSignal *)enqueueRequest:(NSURLRequest *)request resultClass:(Class)resultClass;

This will automatically fetch all pages of the given endpoint. Each object from each page will be sent independently on the returned signal, so subscribers don't have to know or care about this pagination behavior.

Parameters

  • request - The previously constructed URL request for the endpoint.
  • resultClass - A subclass of OCTObject that the response data should be returned as, and will be accessible from the parsedResult property on each OCTResponse. If this is nil, NSDictionary will be used for each object in the JSON received.

Return Value
A signal which will send an instance of OCTResponse for each parsed JSON object, then complete. If an error occurs at any point, the returned signal will send it immediately, then terminate.

Clone this wiki locally