Client
open class Client: NSObject, URLSessionDataDelegate
A Client handles HTTP requests, cookie management, and logging in to Stack Exchange chat.
-
Undocumented
Declaration
Swift
open class Client: NSObject, URLSessionDataDelegate
-
Pretty self explanatory
Declaration
Swift
open var cookies = [HTTPCookie]()
-
Indicates whether the client is logged in or not.
Declaration
Swift
open var loggedIn = false
-
Errors which can happen while making a request
See moreDeclaration
Swift
public enum RequestError: Error
-
Indicates the duration of a timeout
Declaration
Swift
open var timeoutDuration: TimeInterval = 30
-
Adds cookies.
Declaration
Swift
open func addCookies(_ newCookies: [HTTPCookie], forHost host: String)
Parameters
newCookies
The cookies to add.
host
The host which set the cookies..
-
Checks whether a cookie matches a domain.
Declaration
Swift
open func cookieHost(_ host: String, matchesDomain domain: String) -> Bool
Parameters
host
The host of the cookie.
domain
The domain.
-
Returns the cookie headers for the specified URL.
Declaration
Swift
open func cookieHeaders(forURL url: URL) -> [String:String]
-
Undocumented
Declaration
Swift
open class Client: NSObject, URLSessionDataDelegate
-
Undocumented
Declaration
Swift
open class Client: NSObject, URLSessionDataDelegate
-
Undocumented
Declaration
Swift
open class Client: NSObject, URLSessionDataDelegate
-
Undocumented
Declaration
Swift
open class Client: NSObject, URLSessionDataDelegate
-
Performs an
URLRequest
.Declaration
Swift
open func performRequest(_ request: URLRequest) throws -> (Data, HTTPURLResponse)
Parameters
request
The request to perform.
Return Value
The
Data
andHTTPURLResponse
returned by the request. -
Performs a GET request.
- paramter url: The URL to make the request to.
Declaration
Swift
open func get(_ url: String) throws -> (Data, HTTPURLResponse)
Return Value
The
Data
andHTTPURLResponse
returned by the request. -
Performs a POST request.
Declaration
Swift
open func post(_ url: String, data: Data, contentType: String? = nil) throws -> (Data, HTTPURLResponse)
Parameters
url
The URL to make the request to.
data
The body of the POST request.
Return Value
The
Data
andHTTPURLResponse
returned by the request. -
Performs a POST request.
Declaration
Swift
open func post(_ url: String, _ data: [String:String]) throws -> (Data, HTTPURLResponse)
Parameters
url
The URL to make the request to.
data
The fields to include in the POST request.
Return Value
The
Data
andHTTPURLResponse
returned by the request. -
Performs an URLRequest.
Declaration
Swift
open func performRequest(_ request: URLRequest) throws -> String
Parameters
request
The request to perform.
Return Value
The UTF-8 string returned by the request.
-
Performs a GET request.
- paramter url: The URL to make the request to.
Declaration
Swift
open func get(_ url: String) throws -> String
Return Value
The UTF-8 string returned by the request.
-
Performs a POST request.
Declaration
Swift
open func post(_ url: String, _ fields: [String:String]) throws -> String
Parameters
url
The URL to make the request to.
data
The fields to include in the POST request.
Return Value
The UTF-8 string returned by the request.
-
Performs a POST request.
Declaration
Swift
open func post(_ url: String, data: Data, contentType: String? = nil) throws -> String
Parameters
url
The URL to make the request to.
data
The body of the POST request.
Return Value
The UTF-8 string returned by the request.
-
Parses a JSON string.
Declaration
Swift
open func parseJSON(_ json: String) throws -> Any
-
Initializes a Client.
Declaration
Swift
override public init()
Parameters
host
The chat host to log in to.
-
Errors which can occur while logging in.
See moreDeclaration
Swift
public enum LoginError: Error
-
Logs in to Stack Exchange.
Declaration
Swift
open func login(email: String, password: String) throws