Connection
Connection module will be used as a connector to connect to the kintone Rest API
Constructor
Parameter
Name | Type | Required | Description |
---|---|---|---|
domain | String | yes | The Domain name or FQDN |
auth | Auth | yes | The authentication object |
guestSpaceID | Integer | (optional) | The guest space id. Use this parameter to connect to kintone guest space. |
Sample code
Init Connection module
Source code// Define Authentication object // Init Authentication let loginName = 'your_user_login_name' let loginPassword = 'your_password' let domain = 'your_kintone_domain' // Init authenticationAuth let auth = Auth() auth.setPasswordAuth(username, password) // Init connection let connection = Connection(domain, auth) // Define the connection that included guest space // Init Authentication let loginName = 'your_user_login_name' let loginPassword = 'your_password' let domain = 'your_kintone_domain' // Init authenticationAuth let auth = Auth() auth.setPasswordAuth(username, password) // Init Guest space let guestSpaceID = 3 // Init connection let connection = Connection(domain, auth, guestSpaceID)
Methods
setHeader
Set new header of the Connection
Declaration
func setHeader(_ key: String, _ value: String) -> Connection
Parameter
Name | Type | Required | Description |
---|---|---|---|
key | String | yes | The header's key name |
value | String | yes | The header's value of key |
Return
Sample code
Set header of the Connection
Source code// Define Authentication object // Init Authentication let loginName = 'your_user_name' let loginPassword = 'your_password' let domain = 'your_kintone_domain' let key = "X-HTTP-Method-Override" let value = "GET" // Init authenticationAuth let auth = Auth() auth.setPasswordAuth(username, password) // Init connection let connection = Connection(domain, auth) connection.setHeader(key, value)
setProxy
Set the proxy of the request
Declaration
func setProxy(_ host: String,_ port: Int,_ username: String? = nil,_ password: String? = nil)
Parameter
Name | Description |
---|---|
host | The proxy host name |
port | The proxy port number |
username | User name of the proxy |
password | Password of the proxy |
Return
(none)
Sample code
Set the proxy of the request
Source codelet proxyHost = "{YOUR_PROXY_HOST}" let proxyPort = {YOUR_PROXY_PORT} // Set proxy with auth let proxyUsername = "{YOUR_PROXY_USERNAME}" let proxyPassword = "{YOUR_PROXY_PASSWORD}" let username = "{YOUR_USERNAME}" let password = "{YOUR_PASSWORD}" let domain = "{YOUR_DOMAIN}" // Init authenticationAuth let auth = Auth() auth.setPasswordAuth(username, password) // Init connection let connection = Connection(domain, auth) // Set proxy without auth connection.setProxy(proxyHost, proxyPort) // Set proxy with auth connection.setProxy(proxyHost, proxyPort, proxyUsername, proxyPassword)