void TwitchREST::UpdateChannel()

in Gems/Twitch/Code/Source/TwitchREST.cpp [471:538]


    void TwitchREST::UpdateChannel(const ReceiptID& receipt, const ChannelUpdateInfo& channelUpdateInfo)
    {
        /*
        ** sanity check here, at least once of these must be set to update.
        */

        if( ( !channelUpdateInfo.ChannelFeedEnabled.ToBeUpdated() ) &&
            ( !channelUpdateInfo.Delay.ToBeUpdated()) &&
            ( !channelUpdateInfo.GameName.ToBeUpdated()) &&
            ( !channelUpdateInfo.Status.ToBeUpdated()))
        {
            TwitchNotifyBus::QueueBroadcast(&TwitchNotifyBus::Events::UpdateChannel, ChannelInfoValue(ChannelInfo(), receipt, ResultCode::TwitchChannelNoUpdatesToMake));
        }

        // we need to get the twitch channel this user is on, and that call requires its own receipt
        ReceiptID gcReceipt;
        
        InternalGetChannel(gcReceipt, [receipt, channelUpdateInfo, this](const ChannelInfo& channelInfo, const ReceiptID&, ResultCode)
        {
            AZStd::string url(BuildKrakenURL("channels") + "/" + channelInfo.Id);

            HttpRequestor::Headers headers(GetDefaultHeaders());                  
            AddToHeader(headers, "Content-Type", "application/json");

            Aws::Utils::Json::JsonValue jsonChannel;

            if (channelUpdateInfo.Status.ToBeUpdated())
            {
                jsonChannel.WithString("status", channelUpdateInfo.Status.GetValue().c_str());
            }

            if (channelUpdateInfo.GameName.ToBeUpdated())
            {
                jsonChannel.WithString("game", channelUpdateInfo.GameName.GetValue().c_str());
            }
        
            if (channelUpdateInfo.Delay.ToBeUpdated())
            {
                jsonChannel.WithString("delay", AZStd::to_string(channelUpdateInfo.Delay.GetValue()).c_str());
            }
            
            if (channelUpdateInfo.ChannelFeedEnabled.ToBeUpdated())
            {
                jsonChannel.WithBool("channel_feed_enabled", channelUpdateInfo.ChannelFeedEnabled.GetValue());
            }
            
            Aws::Utils::Json::JsonValue jsonBody;

            jsonBody.WithObject("channel", AZStd::move(jsonChannel));

            Aws::String body(jsonBody.View().WriteCompact());

            AddHTTPRequest(url, Aws::Http::HttpMethod::HTTP_PUT, headers, body.c_str(), [receipt, this](const Aws::Utils::Json::JsonView& jsonDoc, Aws::Http::HttpResponseCode httpCode)
            {
                ResultCode rc(ResultCode::TwitchRESTError);
                ChannelInfo retChannelInfo;

                if (httpCode == Aws::Http::HttpResponseCode::OK)
                {
                    rc = ResultCode::Success;

                    retChannelInfo.NumItemsRecieved = SafeGetChannelInfo(retChannelInfo, jsonDoc);
                }

                TwitchNotifyBus::QueueBroadcast(&TwitchNotifyBus::Events::UpdateChannel, ChannelInfoValue(retChannelInfo, receipt, rc));
            });
        });
    }