Menu
Lumberyard
Developer Guide (Version 1.11)

Generated Game Client Code Example

The following client code was generated by the swagger.json file for the Message of the Day Gem that is included with Lumberyard. The swagger file for the gem defines many operations. For brevity, the example shows client code for only the following GET and PUT operations:

  • GET /admin/messages?index={index}&count={count}&filter={filter}

  • PUT /admin/messages/{msg_id}

For comments, see the Examining the Generated Game Client Code section that follows the example.

Copy
// Example Generated Game Client 1 #pragma once 2 #include <AzCore/Component/Component.h> 3 #include <AzCore/Component/Entity.h> 4 #include <AzCore/Component/ComponentBus.h> 5 #include <AzCore/EBus/EBus.h> 6 #include <AzCore/Memory/SystemAllocator.h> 7 #include <AzCore/Rtti/BehaviorContext.h> 8 #include <AzCore/Serialization/EditContext.h> 9 #include <AzCore/Serialization/SerializeContext.h> 10 #include <AzCore/std/smart_ptr/scoped_ptr.h> 11 #include <AzCore/std/string/conversions.h> 12 13 #if defined (PLATFORM_SUPPORTS_AWS_NATIVE_SDK) 14 #include <aws/core/http/HttpRequest.h> 15 #include <aws/core/http/HttpResponse.h> 16 #endif // (PLATFORM_SUPPORTS_AWS_NATIVE_SDK) 17 18 #include <LmbrAWS/ILmbrAWS.h> 19 20 #include <CloudGemFramework/ServiceRequestJob.h> 21 22 #include "StdAfx.h" 23 24 namespace CloudGemMessageOfTheDay { 25 namespace ServiceAPI { 26 27 const char* LmbrAWS_CodeGen_PutAdminMessagesReturnType_UUID= "{ec889bb0-c329-11e6-b753-80a589a02a3d}"; 28 const char* LmbrAWS_CodeGen_Component_UUID= "{ec8874a1-c329-11e6-accd-80a589a02a3d}"; 29 const char* LmbrAWS_CodeGen_ResponseHandler_UUID= "{ec8874a4-c329-11e6-a067-80a589a02a3d}"; 30 const char* LmbrAWS_CodeGen_NotificationBus1_UUID= "{ec8874a2-c329-11e6-a661-80a589a02a3d}"; 31 const char* LmbrAWS_CodeGen_RequestBus1_UUID= "{ec8874a3-c329-11e6-a1e9-80a589a02a3d}"; 32 const char* LmbrAWS_CodeGen_DeleteAdminMessagesReturnType_UUID= "{ec889bb1-c329-11e6-aa94-80a589a02a3d}"; 33 const char* LmbrAWS_CodeGen_DetailedMessageList_UUID= "{ec889bb4-c329-11e6-8650-80a589a02a3d}"; 34 const char* LmbrAWS_CodeGen_ServiceStatus_UUID= "{45baaccf-c88b-11e6-b813-80a589a02a3d}"; 35 const char* LmbrAWS_CodeGen_DetailedMessageData_UUID= "{ec889bb3-c329-11e6-bf48-80a589a02a3d}"; 36 37 38 // redefs 39 40 41 bool WriteJson(CloudGemFramework::JsonWriter& writer, const int& item) 42 { 43 return writer.Int(item); 44 } 45 46 bool WriteJson(CloudGemFramework::JsonWriter& writer, const AZStd::string& item) 47 { 48 return writer.String(item); 49 } 50 51 bool WriteJson(CloudGemFramework::JsonWriter& writer, const float& item) 52 { 53 return writer.Double(static_cast<double>(item)); 54 } 55 56 struct PutAdminMessagesReturnType 57 { 58 59 AZ_TYPE_INFO(PutAdminMessagesReturnType, LmbrAWS_CodeGen_PutAdminMessagesReturnType_UUID) 60 AZ_CLASS_ALLOCATOR(PutAdminMessagesReturnType, AZ::SystemAllocator, 0) 61 62 bool OnJsonKey(const char* key, CloudGemFramework::JsonReader& reader); 63 static void Reflect(AZ::ReflectContext* reflection); 64 65 }; 66 67 bool WriteJson(CloudGemFramework::JsonWriter& writer, const PutAdminMessagesReturnType& item) 68 { 69 bool ok = true; 70 ok = ok && writer.StartObject(); 71 ok = ok && writer.EndObject(); 72 return ok; 73 } 74 75 struct DetailedMessageData 76 { 77 78 AZ_TYPE_INFO(DetailedMessageData, LmbrAWS_CodeGen_DetailedMessageData_UUID) 79 AZ_CLASS_ALLOCATOR(DetailedMessageData, AZ::SystemAllocator, 0) 80 81 int priority; 82 AZStd::string message; 83 AZStd::string endTime; 84 AZStd::string UniqueMsgID; 85 AZStd::string startTime; 86 87 bool OnJsonKey(const char* key, CloudGemFramework::JsonReader& reader); 88 static void Reflect(AZ::ReflectContext* reflection); 89 90 }; 91 92 bool WriteJson(CloudGemFramework::JsonWriter& writer, const DetailedMessageData& item) 93 { 94 bool ok = true; 95 ok = ok && writer.StartObject(); 96 ok = ok && writer.Key("priority"); 97 ok = ok && WriteJson(writer, item.priority); 98 ok = ok && writer.Key("message"); 99 ok = ok && WriteJson(writer, item.message); 100 ok = ok && writer.Key("endTime"); 101 ok = ok && WriteJson(writer, item.endTime); 102 ok = ok && writer.Key("UniqueMsgID"); 103 ok = ok && WriteJson(writer, item.UniqueMsgID); 104 ok = ok && writer.Key("startTime"); 105 ok = ok && WriteJson(writer, item.startTime); 106 ok = ok && writer.EndObject(); 107 return ok; 108 } 109 110 using DetailedMessageListPropertyList = AZStd::vector<DetailedMessageData>; 111 112 bool WriteJson(CloudGemFramework::JsonWriter& writer, const DetailedMessageListPropertyList& list) 113 { 114 bool ok = true; 115 ok = ok && writer.StartArray(); 116 for (auto item : list) 117 { 118 ok = ok && WriteJson(writer, item); 119 } 120 ok = ok && writer.EndArray(); 121 return ok; 122 } 123 124 struct DetailedMessageList 125 { 126 127 AZ_TYPE_INFO(DetailedMessageList, LmbrAWS_CodeGen_DetailedMessageList_UUID) 128 AZ_CLASS_ALLOCATOR(DetailedMessageList, AZ::SystemAllocator, 0) 129 130 DetailedMessageListPropertyList list; 131 132 bool OnJsonKey(const char* key, CloudGemFramework::JsonReader& reader); 133 static void Reflect(AZ::ReflectContext* reflection); 134 135 }; 136 137 bool WriteJson(CloudGemFramework::JsonWriter& writer, const DetailedMessageList& item) 138 { 139 bool ok = true; 140 ok = ok && writer.StartObject(); 141 142 ok = ok && writer.Key("list"); 143 ok = ok && WriteJson(writer, item.list); 144 145 ok = ok && writer.EndObject(); 146 return ok; 147 } 148 149 // Service RequestJobs 150 CLOUD_GEM_SERVICE(CloudGemMessageOfTheDay); 151 152 void Configure() 153 { 154 // Insert any necessary CloudGemFramework configuration here 155 } 156 157 class PutAdminMessagesRequest 158 : public CloudGemFramework::ServiceRequest 159 { 160 public: 161 SERVICE_REQUEST(CloudGemMessageOfTheDay, HttpMethod::HTTP_PUT, "/admin/messages/{msg_id}"); 162 163 struct Parameters 164 { 165 166 AZStd::string msg_id; 167 168 MessageData msg; 169 170 171 bool BuildRequest(CloudGemFramework::RequestBuilder& request) 172 { 173 bool ok = true; 174 175 ok = ok && request.SetPathParameter("{""msg_id""}", msg_id); 176 177 178 ok = ok && request.WriteJsonBodyParameter(*this); 179 return ok; 180 } 181 182 bool WriteJson(CloudGemFramework::JsonWriter& writer) const 183 { 184 bool ok = true; 185 186 ok = ok && CloudGemMessageOfTheDay::ServiceAPI::WriteJson(writer, msg); 187 188 return ok; 189 } 190 }; 191 192 193 PutAdminMessagesReturnType result; 194 195 196 Parameters parameters; 197 }; 198 199 200 using PutAdminMessagesRequestJob = CloudGemFramework::ServiceRequestJob<PutAdminMessagesRequest>; 201 202 class GetAdminMessagesRequest 203 : public CloudGemFramework::ServiceRequest 204 { 205 206 public: 207 208 SERVICE_REQUEST(CloudGemMessageOfTheDay, HttpMethod::HTTP_GET, "/admin/messages"); 209 210 struct Parameters 211 { 212 213 int index; 214 int count; 215 AZStd::string filter; 216 217 bool BuildRequest(CloudGemFramework::RequestBuilder& request) 218 { 219 bool ok = true; 220 ok = ok && request.AddQueryParameter("index", index); 221 ok = ok && request.AddQueryParameter("count", count); 222 ok = ok && request.AddQueryParameter("filter", filter); 223 ok = ok && request.WriteJsonBodyParameter(*this); 224 return ok; 225 } 226 227 bool WriteJson(CloudGemFramework::JsonWriter& writer) const 228 { 229 bool ok = true; 230 return ok; 231 } 232 233 }; 234 235 DetailedMessageList result; 236 Parameters parameters; 237 238 }; 239 240 using GetAdminMessagesRequestJob = CloudGemFramework::ServiceRequestJob<GetAdminMessagesRequest>; 241 242 // Notification bus for this component 243 class CloudGemMessageOfTheDayNotifications 244 : public AZ::ComponentBus 245 { 246 public: 247 248 /** 249 * Sent when the request is a success 250 * 251 * Params: 252 * jsonOutput: The output receieved from the Lambda call 253 * request: The AWS Lambda request object 254 */ 255 virtual void OnPutAdminMessagesRequestSuccess(const PutAdminMessagesReturnType response) { } 256 257 /** 258 * Sent when the request fails 259 * 260 * Params: 261 * error: The output receieved from the Lambda call; 262 * could be function error or an issue with the request 263 * request: The AWS Lambda request object 264 */ 265 virtual void OnPutAdminMessagesRequestError(const CloudGemFramework::Error error) { } 266 267 /** 268 * Sent when the request is a success 269 * 270 * Params: 271 * jsonOutput: The output receieved from the Lambda call 272 * request: The AWS Lambda request object 273 */ 274 275 virtual void OnGetAdminMessagesRequestSuccess(const DetailedMessageList response) { } 276 277 /** 278 * Sent when the request fails 279 * 280 * Params: 281 * error: The output receieved from the Lambda call; 282 * could be function error or an issue with the request 283 * request: The AWS Lambda request object 284 */ 285 virtual void OnGetAdminMessagesRequestError(const CloudGemFramework::Error error) { } 286 287 }; 288 289 using CloudGemMessageOfTheDayNotificationBus = AZ::EBus<CloudGemMessageOfTheDayNotifications>; 290 291 class BehaviorCloudGemMessageOfTheDayNotificationBusHandler 292 : public CloudGemMessageOfTheDayNotificationBus::Handler, public AZ::BehaviorEBusHandler 293 { 294 public: 295 AZ_EBUS_BEHAVIOR_BINDER(BehaviorCloudGemMessageOfTheDayNotificationBusHandler, LmbrAWS_CodeGen_NotificationBus1_UUID, AZ::SystemAllocator 296 , OnPutAdminMessagesRequestSuccess 297 , OnPutAdminMessagesRequestError 298 , OnGetAdminMessagesRequestSuccess 299 , OnGetAdminMessagesRequestError 300 ); 301 302 void OnPutAdminMessagesRequestSuccess(const PutAdminMessagesReturnType response) override 303 { 304 Call(FN_OnPutAdminMessagesRequestSuccess, response); 305 } 306 307 void OnPutAdminMessagesRequestError(const CloudGemFramework::Error error) override 308 { 309 Call(FN_OnPutAdminMessagesRequestError, error); 310 } 311 312 void OnPostAdminMessagesRequestSuccess(const DetailedMessageData response) override 313 { 314 Call(FN_OnPostAdminMessagesRequestSuccess, response); 315 } 316 317 void OnPostAdminMessagesRequestError(const CloudGemFramework::Error error) override 318 { 319 Call(FN_OnPostAdminMessagesRequestError, error); 320 } 321 322 }; 323 324 class CloudGemMessageOfTheDayResponseHandler; 325 326 // Request bus for this component 327 class CloudGemMessageOfTheDayRequests 328 : public AZ::ComponentBus 329 { 330 331 public: 332 333 virtual ~CloudGemMessageOfTheDayRequests() {} 334 335 virtual void PutAdminMessages(const AZStd::string& msg_id, const MessageData& msg, CloudGemMessageOfTheDayResponseHandler* responseHandler) { } 336 virtual void GetAdminMessages(const int& index, const int& count, const AZStd::string& filter, CloudGemMessageOfTheDayResponseHandler* responseHandler) { } 337 338 }; 339 340 using CloudGemMessageOfTheDayRequestBus = AZ::EBus<CloudGemMessageOfTheDayRequests>; 341 342 // This class is used as a parameter for all requests and throws the response on the CloudGemMessageOfTheDayNotificationBus 343 // Inherit from this to define custom behavior. 344 class CloudGemMessageOfTheDayResponseHandler 345 { 346 public: 347 AZ_TYPE_INFO(CloudGemMessageOfTheDayResponseHandler, LmbrAWS_CodeGen_ResponseHandler_UUID) 348 AZ_CLASS_ALLOCATOR(CloudGemMessageOfTheDayResponseHandler, AZ::SystemAllocator, 0) 349 350 virtual ~CloudGemMessageOfTheDayResponseHandler() {} 351 352 virtual void HandlePutAdminMessagesSuccess(PutAdminMessagesRequestJob* job, AZ::Entity* entity) 353 { 354 EBUS_EVENT_ID(entity->GetId(), CloudGemMessageOfTheDayNotificationBus, OnPutAdminMessagesRequestSuccess, job->result); 355 } 356 357 virtual void HandlePutAdminMessagesError(PutAdminMessagesRequestJob* job, AZ::Entity* entity) 358 { 359 EBUS_EVENT_ID(entity->GetId(), CloudGemMessageOfTheDayNotificationBus, OnPutAdminMessagesRequestError, job->error); 360 } 361 362 virtual void HandleGetAdminMessagesSuccess(GetAdminMessagesRequestJob* job, AZ::Entity* entity) 363 { 364 EBUS_EVENT_ID(entity->GetId(), CloudGemMessageOfTheDayNotificationBus, OnGetAdminMessagesRequestSuccess, job->result); 365 } 366 367 virtual void HandleGetAdminMessagesError(GetAdminMessagesRequestJob* job, AZ::Entity* entity) 368 { 369 EBUS_EVENT_ID(entity->GetId(), CloudGemMessageOfTheDayNotificationBus, OnGetAdminMessagesRequestError, job->error); 370 } 371 372 }; 373 374 class CloudGemMessageOfTheDayClientComponent 375 : public AZ::Component 376 , public CloudGemMessageOfTheDayRequestBus::Handler 377 { 378 public: 379 AZ_COMPONENT(CloudGemMessageOfTheDayClientComponent, LmbrAWS_CodeGen_Component_UUID); 380 virtual ~CloudGemMessageOfTheDayClientComponent() = default; 381 382 AZStd::scoped_ptr<CloudGemMessageOfTheDayResponseHandler> m_defaultResponseHandler; 383 384 void Init() override 385 { 386 m_defaultResponseHandler.reset(new CloudGemMessageOfTheDayResponseHandler()); 387 CloudGemMessageOfTheDay::ServiceAPI::Configure(); 388 } 389 390 void Activate() override 391 { 392 CloudGemMessageOfTheDayRequestBus::Handler::BusConnect(m_entity->GetId()); 393 } 394 395 void Deactivate() override 396 { 397 CloudGemMessageOfTheDayRequestBus::Handler::BusDisconnect(); 398 } 399 400 static void Reflect(AZ::ReflectContext* reflection) 401 { 402 MessageData::Reflect(reflection); 403 PutAdminMessagesReturnType::Reflect(reflection); 404 DetailedMessageData::Reflect(reflection); 405 DetailedMessageList::Reflect(reflection); 406 MessageList::Reflect(reflection); 407 408 AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection); 409 if (serializeContext) 410 { 411 // we must include any fields we want to expose to the editor or lua in the serialize context 412 serializeContext->Class<CloudGemMessageOfTheDayClientComponent>() 413 ->Version(1); 414 415 AZ::EditContext* editContext = serializeContext->GetEditContext(); 416 if (editContext) 417 { 418 editContext->Class<CloudGemMessageOfTheDayClientComponent>("CloudGemMessageOfTheDayClientComponent", "CloudGemMessageOfTheDay Component") 419 ->ClassElement(AZ::Edit::ClassElements::EditorData, "") 420 ->Attribute(AZ::Edit::Attributes::Category, "Cloud Canvas Gems") 421 ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game")); 422 } 423 } 424 425 AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(reflection); 426 if (behaviorContext) 427 { 428 behaviorContext->EBus<CloudGemMessageOfTheDayRequestBus>("CloudGemMessageOfTheDayRequestBus") 429 // one of these for each function 430 ->Event("PutAdminMessages", &CloudGemMessageOfTheDayRequestBus::Events::PutAdminMessages) 431 ->Event("GetAdminMessages", &CloudGemMessageOfTheDayRequestBus::Events::GetAdminMessages) 432 ; 433 behaviorContext->EBus<CloudGemMessageOfTheDayNotificationBus>("CloudGemMessageOfTheDayNotificationBus") 434 ->Handler<BehaviorCloudGemMessageOfTheDayNotificationBusHandler>() 435 ; 436 } 437 } 438 439 // Functions from the swagger definitions 440 441 442 void PutAdminMessages(const AZStd::string& msg_id, const MessageData& msg, CloudGemMessageOfTheDayResponseHandler* responseHandler) override 443 { 444 445 446 if (responseHandler == nullptr) 447 { 448 responseHandler = AZStd::get_pointer(m_defaultResponseHandler); 449 } 450 451 // create job 452 PutAdminMessagesRequestJob* job = PutAdminMessagesRequestJob::Create( 453 [responseHandler, this](PutAdminMessagesRequestJob* job) 454 { 455 // handle success 456 responseHandler->HandlePutAdminMessagesSuccess(job, m_entity); 457 }, 458 [responseHandler, this](PutAdminMessagesRequestJob* job) 459 { 460 // handle error 461 responseHandler->HandlePutAdminMessagesError(job, m_entity); 462 } 463 ); 464 465 job->parameters.msg = msg; 466 job->parameters.msg_id = msg_id; 467 468 job->Start(); 469 470 } 471 472 void GetAdminMessages(const int& index, const int& count, const AZStd::string& filter, CloudGemMessageOfTheDayResponseHandler* responseHandler) override 473 { 474 475 if (responseHandler == nullptr) 476 { 477 responseHandler = AZStd::get_pointer(m_defaultResponseHandler); 478 } 479 480 // create job 481 GetAdminMessagesRequestJob* job = GetAdminMessagesRequestJob::Create( 482 [responseHandler, this](GetAdminMessagesRequestJob* job) 483 { 484 // handle success 485 responseHandler->HandleGetAdminMessagesSuccess(job, m_entity); 486 }, 487 [responseHandler, this](GetAdminMessagesRequestJob* job) 488 { 489 // handle error 490 responseHandler->HandleGetAdminMessagesError(job, m_entity); 491 } 492 ); 493 494 job->parameters.index = index; 495 job->parameters.count = count; 496 job->parameters.filter = filter; 497 498 job->Start(); 499 500 } 501 502 }; 503 504 bool MessageData::OnJsonKey(const char* key, CloudGemFramework::JsonReader& reader) 505 { 506 507 if (strcmp(key, "priority") == 0) return reader.Accept(priority); 508 509 if (strcmp(key, "message") == 0) return reader.Accept(message); 510 511 if (strcmp(key, "endTime") == 0) return reader.Accept(endTime); 512 513 if (strcmp(key, "startTime") == 0) return reader.Accept(startTime); 514 515 return reader.Ignore(); 516 } 517 518 void MessageData::Reflect(AZ::ReflectContext* reflection) 519 { 520 AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection); 521 522 if (serializeContext) 523 { 524 serializeContext->Class<MessageData>() 525 ->Version(1); 526 } 527 528 AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(reflection); 529 if (behaviorContext) 530 { 531 behaviorContext->Class<MessageData>("CloudGemMessageOfTheDay_MessageData") 532 ->Attribute(AZ::Script::Attributes::Storage, AZ::Script::Attributes::StorageType::Value) 533 534 ->Property("priority", BehaviorValueProperty(&MessageData::priority)) 535 536 ->Property("message", BehaviorValueProperty(&MessageData::message)) 537 538 ->Property("endTime", BehaviorValueProperty(&MessageData::endTime)) 539 540 ->Property("startTime", BehaviorValueProperty(&MessageData::startTime)) 541 542 ; 543 } 544 } 545 546 bool PutAdminMessagesReturnType::OnJsonKey(const char* key, CloudGemFramework::JsonReader& reader) 547 { 548 return reader.Ignore(); 549 } 550 551 void PutAdminMessagesReturnType::Reflect(AZ::ReflectContext* reflection) 552 { 553 AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection); 554 555 if (serializeContext) 556 { 557 serializeContext->Class<PutAdminMessagesReturnType>() 558 ->Version(1); 559 } 560 561 AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(reflection); 562 if (behaviorContext) 563 { 564 behaviorContext->Class<PutAdminMessagesReturnType>("CloudGemMessageOfTheDay_PutAdminMessagesReturnType") 565 ->Attribute(AZ::Script::Attributes::Storage, AZ::Script::Attributes::StorageType::Value) 566 567 ; 568 } 569 } 570 571 bool DetailedMessageData::OnJsonKey(const char* key, CloudGemFramework::JsonReader& reader) 572 { 573 if (strcmp(key, "priority") == 0) return reader.Accept(priority); 574 if (strcmp(key, "message") == 0) return reader.Accept(message); 575 if (strcmp(key, "endTime") == 0) return reader.Accept(endTime); 576 if (strcmp(key, "UniqueMsgID") == 0) return reader.Accept(UniqueMsgID); 577 if (strcmp(key, "startTime") == 0) return reader.Accept(startTime); 578 return reader.Ignore(); 579 } 580 581 void DetailedMessageData::Reflect(AZ::ReflectContext* reflection) 582 { 583 584 AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection); 585 586 if (serializeContext) 587 { 588 serializeContext->Class<DetailedMessageData>()->Version(1); 589 } 590 591 AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(reflection); 592 if (behaviorContext) 593 { 594 behaviorContext->Class<DetailedMessageData>("CloudGemMessageOfTheDay_DetailedMessageData") 595 ->Attribute(AZ::Script::Attributes::Storage, AZ::Script::Attributes::StorageType::Value) 596 ->Property("priority", BehaviorValueProperty(&DetailedMessageData::priority)) 597 ->Property("message", BehaviorValueProperty(&DetailedMessageData::message)) 598 ->Property("endTime", BehaviorValueProperty(&DetailedMessageData::endTime)) 599 ->Property("UniqueMsgID", BehaviorValueProperty(&DetailedMessageData::UniqueMsgID)) 600 ->Property("startTime", BehaviorValueProperty(&DetailedMessageData::startTime)) 601 ; 602 } 603 604 } 605 606 bool DetailedMessageList::OnJsonKey(const char* key, CloudGemFramework::JsonReader& reader) 607 { 608 if (strcmp(key, "list") == 0) return reader.Accept(list); 609 return reader.Ignore(); 610 } 611 612 void DetailedMessageList::Reflect(AZ::ReflectContext* reflection) 613 { 614 615 AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection); 616 617 if (serializeContext) 618 { 619 serializeContext->Class<DetailedMessageList>()->Version(1); 620 } 621 622 AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(reflection); 623 if (behaviorContext) 624 { 625 behaviorContext->Class<DetailedMessageList>("CloudGemMessageOfTheDay_DetailedMessageList") 626 ->Attribute(AZ::Script::Attributes::Storage, AZ::Script::Attributes::StorageType::Value) 627 ->Property("list", BehaviorValueProperty(&DetailedMessageList::list)) 628 ; 629 } 630 631 } 632 633 } // ServiceAPI 634 } // CloudGemMessageOfTheDay

Examining the Generated Game Client Code

The following table provides additional information for the generated game client code example in the previous section. The line numbers indicate the location in the code that the comments refer to.

Line Number Description
24, 25 The C++ namespace for the API. This is always <resource-group-name>::ServiceApi.
56, 75, 110, 124 The PutAdminMessageReturnType struct contains the PUT operation's return data as defined by the swagger file. In this case, it is an empty object and has no properties.
67, 92, 112, 137 The WriteJson method is generated to handle the serialization of PutAdminMessageReturnType objects to JSON text format. JSON format is required for the data to be sent to the service. A similar function is generated for each of the type definitions in the swagger.json file.
150 The CLOUD_GEM_SERVICE macro defines a class that provides information that is common to all of the service's requests.
152

The Configure function is called when the generated component is initialized. You can add code to this function to change the default configuration for the service. For example, the following code increases the timeout for GetServiceStatus requests.

Copy
void Configure() { GetServiceStatusRequestJob::GetDefaultConfig()->requestTimeoutMs = 20000; }

Note

If you regenerate the client, your changes to the Configure method are lost.

157, 202 A Request class such as PutAdminMessagesRequest is generated for each of the operations defined in the swagger.json file. This class encapsulates the HTTP method and path that are used to make the request. The Parameters struct in the class defines the fields for each of the request's parameters that are specified by the swagger file.
200, 240 The Lumberyard job system executes API requests asynchronously. This work is performed by the CloudGemFramework::ServiceRequestJob class and specialized by the PutAdminMessagesRequest class declared previously. The C++ using statement creates an alias for that type.
243 Defines the CloudGemMessageOfTheDayNotifications EBus that signals when a request has completed. Both a success and an error notification method are defined for each operation specified in the swagger.json file.
291 Defines a handler (BehaviorCloudGemMessageOfTheDayNotificationBusHandler) for the notification EBus that forwards notifications to Lua code.
340 Defines an EBus (CloudGemMessageOfTheDayRequestBus) that initiates requests.
344 Defines a class (CloudGemMessageOfTheDayResponseHandler) that handles responses. By default, responses are dispatched to the notification EBus previously defined.
374 Defines a client component (CloudGemMessageOfTheDayClientComponent) that uses the using the request job classes PutAdminMessagesRequest (line 157) and GetAdminMessagesRequest (line 202) to implement the request EBus handler BehaviorCloudGemMessageOfTheDayNotificationBusHandler (line 291).