VONetworkManagerProtocol

@protocol VONetworkManagerProtocol

VONetworkManagerProtocol is the interface for Vouchr’s VONetworkManager. The VONetworkManager is responsible for all client -> server communication with the Vouchr Server.

To replace the VONetworkManager, implement this protocol with the replacement VONetworkManager.

  • Creates an NSURL with the Vouchr server’s v3 endpoint with the given path.

    Declaration

    Objective-C

    - (NSURL *)v3UrlWithPath:(NSString *)path;

    Swift

    func v3Url(withPath path: Any!) -> Any!

    Parameters

    path

    - the path of the url.

    Return Value

    an NSURL with the form {baseurl}/api/v3/{path}.

  • Creates an NSURL with the Vouchr server’s v2 endpoint with the given path.

    Declaration

    Objective-C

    - (NSURL *)v2UrlWithPath:(NSString *)path;

    Swift

    func v2Url(withPath path: Any!) -> Any!

    Parameters

    path

    - the path of the url.

    Return Value

    an NSURL with the form {baseurl}/api/v2/{path}.

  • Creates an NSURL with the Vouchr server’s v3 endpoint with the given path and query paramters.

    Declaration

    Objective-C

    - (NSURL *)v2UrlWithPath:(NSString *)path
              withQueryItems:(NSArray<NSURLQueryItem *> *)queryItems;

    Swift

    func v2Url(withPath path: Any!, withQueryItems queryItems: Any!) -> Any!

    Parameters

    path

    - the path of the url.

    queryItems

    - the query parameters of the url.

    Return Value

    an NSURL with the form {baseurl}/api/v3/{path}?{queryItem=…&queryItem2=…}.

  • Creates an NSURL with the Vouchr server’s v2 endpoint with the given path and query paramters.

    Declaration

    Objective-C

    - (NSURL *)v3UrlWithPath:(NSString *)path
              withQueryItems:(NSArray<NSURLQueryItem *> *)queryItems;

    Swift

    func v3Url(withPath path: Any!, withQueryItems queryItems: Any!) -> Any!

    Parameters

    path

    - the path of the url.

    queryItems

    - the query parameters of the url.

    Return Value

    an NSURL with the form {baseurl}/api/v2/{path}?{queryItem=…&queryItem2=…}.

  • Sends a GET request to the url and responds asynchronously.

    Declaration

    Objective-C

    - (void)requestWithUrl:(NSURL *)url
                 onSuccess:(void (^)(id))onSuccess
                   onError:(void (^)(NSError *))onError;

    Swift

    func request(withUrl url: Any!, onSuccess: ((Any?) -> Void)!, onError: ((UnsafeMutablePointer<Int32>?) -> Void)!)

    Parameters

    url

    - the url that is being requested.

    onSuccess

    - success block when the request completes.

    onError

    - error block if the request completes with an error.

  • Sends a network request to the url with the provided method and responds asynchronously.

    Declaration

    Objective-C

    - (void)requestWithUrl:(NSURL *)url
                   httpMethod:(NSString *)method
                         data:(id)data
                   isTypeJson:(BOOL)isJsonData
        requiresAuthorization:(BOOL)requiresAuthorization
                 headerParams:(NSDictionary *)additionalHeaderParams
                   onProgress:(void (^)(NSProgress *))uploadProgress
                    onSuccess:(void (^)(id))onSuccess
                      onError:(void (^)(NSError *))onError;

    Swift

    func request(withUrl url: Any!, httpMethod method: Any!, data: Any!, isTypeJson isJsonData: Any!, requiresAuthorization: Any!, headerParams additionalHeaderParams: Any!, onProgress uploadProgress: ((UnsafeMutablePointer<Int32>?) -> Void)!, onSuccess: ((Any?) -> Void)!, onError: ((UnsafeMutablePointer<Int32>?) -> Void)!)

    Parameters

    url

    - the url that is being requested.

    method

    - the HTTP method. Should be one of [GET, POST, PUT, DELETE].

    data

    - the data that is sent as part of the request.

    isJsonData

    - is the provided data of type JSON.

    requiresAuthorization

    - The VONetworkManager will add headers / query params to the request if authorization is required. This should only be true when sending requests to the Vouchr Server.

    additionalHeaderParams

    - Any additional header params that need to be sent as part of the request.

    onSuccess

    - success block when the request completes.

    onError

    - error block if the request completes with an error.

  • Creates and uses NSURLSessionDataTask to upload data.

    Declaration

    Objective-C

    - (void)uploadWithUrlRequest:(NSURLRequest *)urlRequest
                       onSuccess:(void (^)(id))onSuccess
                         onError:(void (^)(NSError *))onFail;

    Swift

    func upload(withUrlRequest urlRequest: Any!, onSuccess: ((Any?) -> Void)!, onError onFail: ((UnsafeMutablePointer<Int32>?) -> Void)!)

    Parameters

    urlRequest

    - the object containing the upload url and the data to be uploaded.

    onSuccess

    - success block when the request completes.

    onFail

    - error block if the request completes with an error.