Chilkat Online Tools

UpdateWorkspace Objective-C Example

AWS Managed Grafana

#import <CkoRest.h>
#import <CkoAuthAws.h>
#import <CkoJsonObject.h>
#import <CkoStringBuilder.h>
#import <NSString.h>

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

CkoRest *rest = [[CkoRest alloc] init];
BOOL success;

CkoAuthAws *authAws = [[CkoAuthAws alloc] init];
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 = @"grafana";
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
[rest SetAuthAws: authAws];

// URL: https://grafana.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = [rest Connect: @"grafana.us-west-2.amazonaws.com" port: [NSNumber numberWithInt: 443] tls: YES autoReconnect: YES];
if (success != YES) {
    NSLog(@"%@%d",@"ConnectFailReason: ",[rest.ConnectFailReason intValue]);
    NSLog(@"%@",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

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"accountAccessType" value: @"string"];
[json UpdateString: @"organizationRoleName" value: @"string"];
[json UpdateString: @"permissionType" value: @"string"];
[json UpdateString: @"stackSetName" value: @"string"];
[json UpdateString: @"workspaceDataSources[0]" value: @"string"];
[json UpdateString: @"workspaceDescription" value: @"string"];
[json UpdateString: @"workspaceName" value: @"string"];
[json UpdateString: @"workspaceNotificationDestinations[0]" value: @"string"];
[json UpdateString: @"workspaceOrganizationalUnits[0]" value: @"string"];
[json UpdateString: @"workspaceRoleArn" value: @"string"];

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

// {
//   "accountAccessType": "string",
//   "organizationRoleName": "string",
//   "permissionType": "string",
//   "stackSetName": "string",
//   "workspaceDataSources": [
//     "string"
//   ],
//   "workspaceDescription": "string",
//   "workspaceName": "string",
//   "workspaceNotificationDestinations": [
//     "string"
//   ],
//   "workspaceOrganizationalUnits": [
//     "string"
//   ],
//   "workspaceRoleArn": "string"
// }

[rest AddHeader: @"Content-Type" value: @"application/x-amz-json-1.1"];
[rest AddHeader: @"X-Amz-Target" value: @"UpdateWorkspace"];

CkoStringBuilder *sbRequestBody = [[CkoStringBuilder alloc] init];
[json EmitSb: sbRequestBody];
CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestSb: @"PUT" uriPath: @"/workspaces/{workspaceId}" requestBody: sbRequestBody responseBody: sbResponseBody];
if (success != YES) {
    NSLog(@"%@",rest.LastErrorText);
    return;
}

int respStatusCode = [rest.ResponseStatusCode intValue];
NSLog(@"%@%d",@"response status code = ",respStatusCode);
if (respStatusCode != 200) {
    NSLog(@"%@",@"Response Header:");
    NSLog(@"%@",rest.ResponseHeader);
    NSLog(@"%@",@"Response Body:");
    NSLog(@"%@",[sbResponseBody GetAsString]);
    return;
}

CkoJsonObject *jResp = [[CkoJsonObject alloc] init];
[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

NSString *strVal = 0;

NSString *AccountAccessType = [jResp StringOf: @"workspace.accountAccessType"];
NSString *SamlConfigurationStatus = [jResp StringOf: @"workspace.authentication.samlConfigurationStatus"];
int Created = [[jResp IntOf: @"workspace.created"] intValue];
NSString *Description = [jResp StringOf: @"workspace.description"];
NSString *Endpoint = [jResp StringOf: @"workspace.endpoint"];
int FreeTrialConsumed = [[jResp IntOf: @"workspace.freeTrialConsumed"] intValue];
int FreeTrialExpiration = [[jResp IntOf: @"workspace.freeTrialExpiration"] intValue];
NSString *GrafanaVersion = [jResp StringOf: @"workspace.grafanaVersion"];
NSString *Id = [jResp StringOf: @"workspace.id"];
int LicenseExpiration = [[jResp IntOf: @"workspace.licenseExpiration"] intValue];
NSString *LicenseType = [jResp StringOf: @"workspace.licenseType"];
int Modified = [[jResp IntOf: @"workspace.modified"] intValue];
NSString *Name = [jResp StringOf: @"workspace.name"];
NSString *OrganizationRoleName = [jResp StringOf: @"workspace.organizationRoleName"];
NSString *PermissionType = [jResp StringOf: @"workspace.permissionType"];
NSString *StackSetName = [jResp StringOf: @"workspace.stackSetName"];
NSString *Status = [jResp StringOf: @"workspace.status"];
NSString *v_String = [jResp StringOf: @"workspace.tags.string"];
NSString *WorkspaceRoleArn = [jResp StringOf: @"workspace.workspaceRoleArn"];
int i = 0;
int count_i = [[jResp SizeOfArray: @"workspace.authentication.providers"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    strVal = [jResp StringOf: @"workspace.authentication.providers[i]"];
    i = i + 1;
}

i = 0;
count_i = [[jResp SizeOfArray: @"workspace.dataSources"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    strVal = [jResp StringOf: @"workspace.dataSources[i]"];
    i = i + 1;
}

i = 0;
count_i = [[jResp SizeOfArray: @"workspace.notificationDestinations"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    strVal = [jResp StringOf: @"workspace.notificationDestinations[i]"];
    i = i + 1;
}

i = 0;
count_i = [[jResp SizeOfArray: @"workspace.organizationalUnits"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    strVal = [jResp StringOf: @"workspace.organizationalUnits[i]"];
    i = i + 1;
}

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

// {
//   "workspace": {
//     "accountAccessType": "string",
//     "authentication": {
//       "providers": [
//         "string"
//       ],
//       "samlConfigurationStatus": "string"
//     },
//     "created": number,
//     "dataSources": [
//       "string"
//     ],
//     "description": "string",
//     "endpoint": "string",
//     "freeTrialConsumed": boolean,
//     "freeTrialExpiration": number,
//     "grafanaVersion": "string",
//     "id": "string",
//     "licenseExpiration": number,
//     "licenseType": "string",
//     "modified": number,
//     "name": "string",
//     "notificationDestinations": [
//       "string"
//     ],
//     "organizationalUnits": [
//       "string"
//     ],
//     "organizationRoleName": "string",
//     "permissionType": "string",
//     "stackSetName": "string",
//     "status": "string",
//     "tags": {
//       "string": "string"
//     },
//     "workspaceRoleArn": "string"
//   }
// }