Chilkat Online Tools

DescribeActivities Swift3 Example

Amazon WorkDocs

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 = "workdocs"
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.setAuthAws(authAws)

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

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

    let sbResponseBody = CkoStringBuilder()!
    success = rest.fullRequestNoBodySb("GET", uriPath: "/api/v1/activities", sb: 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 CommentId: String?
    var CommentStatus: String?
    var CreatedTimestamp: Int
    var EmailAddress: String?
    var GivenName: String?
    var Id: String?
    var Locale: String?
    var ModifiedTimestamp: Int
    var OrganizationId: String?
    var RecycleBinFolderId: String?
    var RootFolderId: String?
    var Status: String?
    var StorageAllocatedInBytes: Int
    var StorageType: String?
    var StorageUtilizedInBytes: Int
    var Surname: String?
    var TimeZoneId: String?
    var v_Type: String?
    var Username: String?
    var CommentMetadataCreatedTimestamp: Int
    var RecipientId: String?
    var InitiatorEmailAddress: String?
    var InitiatorGivenName: String?
    var InitiatorId: String?
    var InitiatorSurname: String?
    var InitiatorUsername: String?
    var IsIndirectActivity: Int
    var OriginalParentId: String?
    var Name: String?
    var OriginalName: String?
    var OwnerEmailAddress: String?
    var OwnerGivenName: String?
    var OwnerId: String?
    var OwnerSurname: String?
    var OwnerUsername: String?
    var ParentId: String?
    var OriginalParentType: String?
    var VersionId: String?
    var ResourceMetadataId: String?
    var ResourceMetadataName: String?
    var ResourceMetadataOriginalName: String?
    var ResourceMetadataParentId: String?
    var ResourceMetadataType: String?
    var ResourceMetadataVersionId: String?
    var TimeStamp: Int
    var j: Int
    var count_j: Int

    var Marker: String? = jResp.string(of: "Marker")
    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "UserActivities").intValue
    while i < count_i {
        jResp.i = i
        CommentId = jResp.string(of: "UserActivities[i].CommentMetadata.CommentId")
        CommentStatus = jResp.string(of: "UserActivities[i].CommentMetadata.CommentStatus")
        CreatedTimestamp = jResp.int(of: "UserActivities[i].CommentMetadata.Contributor.CreatedTimestamp").intValue
        EmailAddress = jResp.string(of: "UserActivities[i].CommentMetadata.Contributor.EmailAddress")
        GivenName = jResp.string(of: "UserActivities[i].CommentMetadata.Contributor.GivenName")
        Id = jResp.string(of: "UserActivities[i].CommentMetadata.Contributor.Id")
        Locale = jResp.string(of: "UserActivities[i].CommentMetadata.Contributor.Locale")
        ModifiedTimestamp = jResp.int(of: "UserActivities[i].CommentMetadata.Contributor.ModifiedTimestamp").intValue
        OrganizationId = jResp.string(of: "UserActivities[i].CommentMetadata.Contributor.OrganizationId")
        RecycleBinFolderId = jResp.string(of: "UserActivities[i].CommentMetadata.Contributor.RecycleBinFolderId")
        RootFolderId = jResp.string(of: "UserActivities[i].CommentMetadata.Contributor.RootFolderId")
        Status = jResp.string(of: "UserActivities[i].CommentMetadata.Contributor.Status")
        StorageAllocatedInBytes = jResp.int(of: "UserActivities[i].CommentMetadata.Contributor.Storage.StorageRule.StorageAllocatedInBytes").intValue
        StorageType = jResp.string(of: "UserActivities[i].CommentMetadata.Contributor.Storage.StorageRule.StorageType")
        StorageUtilizedInBytes = jResp.int(of: "UserActivities[i].CommentMetadata.Contributor.Storage.StorageUtilizedInBytes").intValue
        Surname = jResp.string(of: "UserActivities[i].CommentMetadata.Contributor.Surname")
        TimeZoneId = jResp.string(of: "UserActivities[i].CommentMetadata.Contributor.TimeZoneId")
        v_Type = jResp.string(of: "UserActivities[i].CommentMetadata.Contributor.Type")
        Username = jResp.string(of: "UserActivities[i].CommentMetadata.Contributor.Username")
        CommentMetadataCreatedTimestamp = jResp.int(of: "UserActivities[i].CommentMetadata.CreatedTimestamp").intValue
        RecipientId = jResp.string(of: "UserActivities[i].CommentMetadata.RecipientId")
        InitiatorEmailAddress = jResp.string(of: "UserActivities[i].Initiator.EmailAddress")
        InitiatorGivenName = jResp.string(of: "UserActivities[i].Initiator.GivenName")
        InitiatorId = jResp.string(of: "UserActivities[i].Initiator.Id")
        InitiatorSurname = jResp.string(of: "UserActivities[i].Initiator.Surname")
        InitiatorUsername = jResp.string(of: "UserActivities[i].Initiator.Username")
        IsIndirectActivity = jResp.int(of: "UserActivities[i].IsIndirectActivity").intValue
        OrganizationId = jResp.string(of: "UserActivities[i].OrganizationId")
        OriginalParentId = jResp.string(of: "UserActivities[i].OriginalParent.Id")
        Name = jResp.string(of: "UserActivities[i].OriginalParent.Name")
        OriginalName = jResp.string(of: "UserActivities[i].OriginalParent.OriginalName")
        OwnerEmailAddress = jResp.string(of: "UserActivities[i].OriginalParent.Owner.EmailAddress")
        OwnerGivenName = jResp.string(of: "UserActivities[i].OriginalParent.Owner.GivenName")
        OwnerId = jResp.string(of: "UserActivities[i].OriginalParent.Owner.Id")
        OwnerSurname = jResp.string(of: "UserActivities[i].OriginalParent.Owner.Surname")
        OwnerUsername = jResp.string(of: "UserActivities[i].OriginalParent.Owner.Username")
        ParentId = jResp.string(of: "UserActivities[i].OriginalParent.ParentId")
        OriginalParentType = jResp.string(of: "UserActivities[i].OriginalParent.Type")
        VersionId = jResp.string(of: "UserActivities[i].OriginalParent.VersionId")
        ResourceMetadataId = jResp.string(of: "UserActivities[i].ResourceMetadata.Id")
        ResourceMetadataName = jResp.string(of: "UserActivities[i].ResourceMetadata.Name")
        ResourceMetadataOriginalName = jResp.string(of: "UserActivities[i].ResourceMetadata.OriginalName")
        OwnerEmailAddress = jResp.string(of: "UserActivities[i].ResourceMetadata.Owner.EmailAddress")
        OwnerGivenName = jResp.string(of: "UserActivities[i].ResourceMetadata.Owner.GivenName")
        OwnerId = jResp.string(of: "UserActivities[i].ResourceMetadata.Owner.Id")
        OwnerSurname = jResp.string(of: "UserActivities[i].ResourceMetadata.Owner.Surname")
        OwnerUsername = jResp.string(of: "UserActivities[i].ResourceMetadata.Owner.Username")
        ResourceMetadataParentId = jResp.string(of: "UserActivities[i].ResourceMetadata.ParentId")
        ResourceMetadataType = jResp.string(of: "UserActivities[i].ResourceMetadata.Type")
        ResourceMetadataVersionId = jResp.string(of: "UserActivities[i].ResourceMetadata.VersionId")
        TimeStamp = jResp.int(of: "UserActivities[i].TimeStamp").intValue
        v_Type = jResp.string(of: "UserActivities[i].Type")
        j = 0
        count_j = jResp.size(ofArray: "UserActivities[i].Participants.Groups").intValue
        while j < count_j {
            jResp.j = j
            Id = jResp.string(of: "UserActivities[i].Participants.Groups[j].Id")
            Name = jResp.string(of: "UserActivities[i].Participants.Groups[j].Name")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "UserActivities[i].Participants.Users").intValue
        while j < count_j {
            jResp.j = j
            EmailAddress = jResp.string(of: "UserActivities[i].Participants.Users[j].EmailAddress")
            GivenName = jResp.string(of: "UserActivities[i].Participants.Users[j].GivenName")
            Id = jResp.string(of: "UserActivities[i].Participants.Users[j].Id")
            Surname = jResp.string(of: "UserActivities[i].Participants.Users[j].Surname")
            Username = jResp.string(of: "UserActivities[i].Participants.Users[j].Username")
            j = j + 1
        }

        i = i + 1
    }

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

    // {
    //   "Marker": "string",
    //   "UserActivities": [
    //     {
    //       "CommentMetadata": {
    //         "CommentId": "string",
    //         "CommentStatus": "string",
    //         "Contributor": {
    //           "CreatedTimestamp": number,
    //           "EmailAddress": "string",
    //           "GivenName": "string",
    //           "Id": "string",
    //           "Locale": "string",
    //           "ModifiedTimestamp": number,
    //           "OrganizationId": "string",
    //           "RecycleBinFolderId": "string",
    //           "RootFolderId": "string",
    //           "Status": "string",
    //           "Storage": {
    //             "StorageRule": {
    //               "StorageAllocatedInBytes": number,
    //               "StorageType": "string"
    //             },
    //             "StorageUtilizedInBytes": number
    //           },
    //           "Surname": "string",
    //           "TimeZoneId": "string",
    //           "Type": "string",
    //           "Username": "string"
    //         },
    //         "CreatedTimestamp": number,
    //         "RecipientId": "string"
    //       },
    //       "Initiator": {
    //         "EmailAddress": "string",
    //         "GivenName": "string",
    //         "Id": "string",
    //         "Surname": "string",
    //         "Username": "string"
    //       },
    //       "IsIndirectActivity": boolean,
    //       "OrganizationId": "string",
    //       "OriginalParent": {
    //         "Id": "string",
    //         "Name": "string",
    //         "OriginalName": "string",
    //         "Owner": {
    //           "EmailAddress": "string",
    //           "GivenName": "string",
    //           "Id": "string",
    //           "Surname": "string",
    //           "Username": "string"
    //         },
    //         "ParentId": "string",
    //         "Type": "string",
    //         "VersionId": "string"
    //       },
    //       "Participants": {
    //         "Groups": [
    //           {
    //             "Id": "string",
    //             "Name": "string"
    //           }
    //         ],
    //         "Users": [
    //           {
    //             "EmailAddress": "string",
    //             "GivenName": "string",
    //             "Id": "string",
    //             "Surname": "string",
    //             "Username": "string"
    //           }
    //         ]
    //       },
    //       "ResourceMetadata": {
    //         "Id": "string",
    //         "Name": "string",
    //         "OriginalName": "string",
    //         "Owner": {
    //           "EmailAddress": "string",
    //           "GivenName": "string",
    //           "Id": "string",
    //           "Surname": "string",
    //           "Username": "string"
    //         },
    //         "ParentId": "string",
    //         "Type": "string",
    //         "VersionId": "string"
    //       },
    //       "TimeStamp": number,
    //       "Type": "string"
    //     }
    //   ]
    // }

}