From 019332301c0903959899e5cfa689166e3d7c9aec Mon Sep 17 00:00:00 2001 From: Linus Gasser Date: Thu, 8 Jul 2021 11:30:21 +0200 Subject: [PATCH] Adding README and adding dict_dir to the parameters --- README.md | 44 ++++++++++++++++++++++++++++++++- Sources/arti-ios/arti_ios.swift | 26 +++++++++++++------ 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4cb93b5..42e1b1f 100644 --- a/README.md +++ b/README.md @@ -21,4 +21,46 @@ This version comes with a mandatory cache of the tor directory data. This means that the app itself will have to download this data and make it available in a directory to the library. -For more information, see [Directory Cache](https://github.com/c4dt/arti-rest/blob/directory_scripts/tools/README.md) \ No newline at end of file +For more information, see [Directory Cache](https://github.com/c4dt/arti-rest/blob/directory_scripts/tools/README.md) + +There is a daily tor-directory update here: +[arti-directory](https://github.com/c4dt/arti-directory) + +# API + +The `arti-ios` library exposes one call: + +``` +/** + Makes a synchronous call to the arti library to fetch the given url with the indicated method. + The arti backend will + set up a new circuit over tor and send the request over this circuit. + In case of an error in the arti library, an ArtiError is thrown. + REST errors are returned through the 'status' field of the ReturnStruct. + + - Parameters: + - method: one of the ARtiMethods + - url: the destination of the request + - headers: of the request + - body: data to be sent along + + - Returns: a ReturnStruct with the result + + - Throws: `ArtiError` in case something within the arti-library produced an error + */ +public func callArti(method: ArtiMethods, url: String, + headers: [String: [String]] = [:], + body: Data = Data([])) throws -> ReturnStruct +``` + +The `ReturnStruct` has the following definition: + +``` +public struct ReturnStruct { + public var status: UInt16 + public var headers: [String: [String]] + public var body: Data +} +``` + +Any REST-request error returns successfully, but the `status` field will be set to an error-code. \ No newline at end of file diff --git a/Sources/arti-ios/arti_ios.swift b/Sources/arti-ios/arti_ios.swift index 0a96282..d12e1f3 100644 --- a/Sources/arti-ios/arti_ios.swift +++ b/Sources/arti-ios/arti_ios.swift @@ -45,17 +45,29 @@ public enum ArtiMethods { } /** - * Makes a synchronous call to the arti library to fetch the given url with the indicated method. The arti backend will - * set up a new circuit over tor and send the request over this circuit. - * In case of an error in the arti library, an ArtiError is thrown. - * REST errors are returned through the 'status' field of the ReturnStruct. + Makes a synchronous call to the arti library to fetch the given url with the indicated method. + The arti backend will + set up a new circuit over tor and send the request over this circuit. + In case of an error in the arti library, an ArtiError is thrown. + REST errors are returned through the 'status' field of the ReturnStruct. + + - Parameters: + - dict_dir: + - method: one of the ARtiMethods + - url: the destination of the request + - headers: of the request + - body: data to be sent along + + - Returns: a ReturnStruct with the result + + - Throws: `ArtiError` in case something within the arti-library produced an error */ -public func callArti(method: ArtiMethods, url: String, +public func callArti(dict_dir: String, + method: ArtiMethods, url: String, headers: [String: [String]] = [:], body: Data = Data([])) throws -> ReturnStruct { - let resourcePath = Bundle.main.resourcePath! let ar = ArtiRequest(method: "\(method)", url: url, headers: headers, - body: [UInt8](body), dict_dir: resourcePath + "/directory"); + body: [UInt8](body), dict_dir: dict_dir); let ar_str = String(data: try JSONEncoder().encode(ar), encoding: .utf8); let ret_json = call_arti(ar_str).takeRetainedValue() as NSString as String;