Chilkat Online Tools

DescribeApps Swift3 Example

AWS OpsWorks

func chilkatTest() {
    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    let rest = CkoRest()!
    var success: Bool

    let authAws = CkoAuthAws()!
    authAws.accessKey = "AWS_ACCESS_KEY"
    authAws.secretKey = "AWS_SECRET_KEY"

    // Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
    authAws.region = "us-west-2"
    authAws.serviceName = "opsworks"
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.setAuthAws(authAws)

    // URL: https://opsworks.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.connect("opsworks.us-west-2.amazonaws.com", port: 443, tls: true, autoReconnect: true)
    if success != true {
        print("ConnectFailReason: \(rest.connectFailReason.intValue)")
        print("\(rest.lastErrorText!)")
        return
    }

    // The following code creates the JSON request body.
    // The JSON created by this code is shown below.

    // Use this online tool to generate code from sample JSON:
    // Generate Code to Create JSON

    let json = CkoJsonObject()!
    json.update("AppIds[0]", value: "string")
    json.update("StackId", value: "string")

    // The JSON request body created by the above code:

    // {
    //   "AppIds": [
    //     "string"
    //   ],
    //   "StackId": "string"
    // }

    rest.addHeader("Content-Type", value: "application/x-amz-json-1.1")
    rest.addHeader("X-Amz-Target", value: "OpsWorks_20130218.DescribeApps")

    let sbRequestBody = CkoStringBuilder()!
    json.emitSb(sbRequestBody)
    let sbResponseBody = CkoStringBuilder()!
    success = rest.fullRequestSb("POST", uriPath: "/", requestBody: sbRequestBody, responseBody: sbResponseBody)
    if success != true {
        print("\(rest.lastErrorText!)")
        return
    }

    var respStatusCode: Int = rest.responseStatusCode.intValue
    print("response status code = \(respStatusCode)")
    if respStatusCode != 200 {
        print("Response Header:")
        print("\(rest.responseHeader!)")
        print("Response Body:")
        print("\(sbResponseBody.getAsString()!)")
        return
    }

    let jResp = CkoJsonObject()!
    jResp.loadSb(sbResponseBody)

    // The following code parses the JSON response.
    // A sample JSON response is shown below the sample code.

    // Use this online tool to generate parsing code from sample JSON:
    // Generate Parsing Code from JSON

    var AppId: String?
    var Password: String?
    var Revision: String?
    var v_SshKey: String?
    var v_Type: String?
    var v_Url: String?
    var Username: String?
    var v_String: String?
    var CreatedAt: String?
    var Description: String?
    var EnableSsl: Int
    var Name: String?
    var Shortname: String?
    var Certificate: String?
    var Chain: String?
    var v_PrivateKey: String?
    var StackId: String?
    var j: Int
    var count_j: Int
    var Arn: String?
    var DatabaseName: String?
    var strVal: String?
    var Key: String?
    var Secure: Int
    var Value: String?

    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "Apps").intValue
    while i < count_i {
        jResp.i = i
        AppId = jResp.string(of: "Apps[i].AppId")
        Password = jResp.string(of: "Apps[i].AppSource.Password")
        Revision = jResp.string(of: "Apps[i].AppSource.Revision")
        v_SshKey = jResp.string(of: "Apps[i].AppSource.SshKey")
        v_Type = jResp.string(of: "Apps[i].AppSource.Type")
        v_Url = jResp.string(of: "Apps[i].AppSource.Url")
        Username = jResp.string(of: "Apps[i].AppSource.Username")
        v_String = jResp.string(of: "Apps[i].Attributes.string")
        CreatedAt = jResp.string(of: "Apps[i].CreatedAt")
        Description = jResp.string(of: "Apps[i].Description")
        EnableSsl = jResp.int(of: "Apps[i].EnableSsl").intValue
        Name = jResp.string(of: "Apps[i].Name")
        Shortname = jResp.string(of: "Apps[i].Shortname")
        Certificate = jResp.string(of: "Apps[i].SslConfiguration.Certificate")
        Chain = jResp.string(of: "Apps[i].SslConfiguration.Chain")
        v_PrivateKey = jResp.string(of: "Apps[i].SslConfiguration.PrivateKey")
        StackId = jResp.string(of: "Apps[i].StackId")
        v_Type = jResp.string(of: "Apps[i].Type")
        j = 0
        count_j = jResp.size(ofArray: "Apps[i].DataSources").intValue
        while j < count_j {
            jResp.j = j
            Arn = jResp.string(of: "Apps[i].DataSources[j].Arn")
            DatabaseName = jResp.string(of: "Apps[i].DataSources[j].DatabaseName")
            v_Type = jResp.string(of: "Apps[i].DataSources[j].Type")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "Apps[i].Domains").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "Apps[i].Domains[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "Apps[i].Environment").intValue
        while j < count_j {
            jResp.j = j
            Key = jResp.string(of: "Apps[i].Environment[j].Key")
            Secure = jResp.int(of: "Apps[i].Environment[j].Secure").intValue
            Value = jResp.string(of: "Apps[i].Environment[j].Value")
            j = j + 1
        }

        i = i + 1
    }

    // A sample JSON response body parsed by the above code:

    // {
    //   "Apps": [
    //     {
    //       "AppId": "string",
    //       "AppSource": {
    //         "Password": "string",
    //         "Revision": "string",
    //         "SshKey": "string",
    //         "Type": "string",
    //         "Url": "string",
    //         "Username": "string"
    //       },
    //       "Attributes": {
    //         "string": "string"
    //       },
    //       "CreatedAt": "string",
    //       "DataSources": [
    //         {
    //           "Arn": "string",
    //           "DatabaseName": "string",
    //           "Type": "string"
    //         }
    //       ],
    //       "Description": "string",
    //       "Domains": [
    //         "string"
    //       ],
    //       "EnableSsl": boolean,
    //       "Environment": [
    //         {
    //           "Key": "string",
    //           "Secure": boolean,
    //           "Value": "string"
    //         }
    //       ],
    //       "Name": "string",
    //       "Shortname": "string",
    //       "SslConfiguration": {
    //         "Certificate": "string",
    //         "Chain": "string",
    //         "PrivateKey": "string"
    //       },
    //       "StackId": "string",
    //       "Type": "string"
    //     }
    //   ]
    // }

}