Syncano.Net.Api.ApiKeySyncanoClient.StartSession C# (CSharp) Method

StartSession() public method

Logs in the API client and returns session_id for session id or cookie-based authentication. Session is valid for 2 hours and is automatically renewed whenever it is used. User API key usage permitted.
public StartSession ( TimeZoneInfo timeZone = null ) : Task
timeZone System.TimeZoneInfo Sets default timezone for all subsequent requests using returned session_id.
return Task
        public async Task<string> StartSession(TimeZoneInfo timeZone = null)
        {
            var sessionId = await _syncanoClient.PostAsync<string>("apikey.start_session", new {timezone = _timeZoneConverter.GetString(timeZone)}, "session_id");
            _syncanoClient.SetSessionContext(sessionId);
            return sessionId;
        }

Usage Example

コード例 #1
0
        public async Task StartSession_WithAllTimeZones(ApiKeySyncanoClient client)
        {
            //given
            var timeZones = TimeZoneInfo.GetSystemTimeZones();
            var sessionIds = new List<string>();

            //when
            foreach (var timeZoneInfo in timeZones)
            {
                try
                {
                    sessionIds.Add(await client.StartSession(timeZoneInfo));
                    client.ClearSession();
                    
                }
                catch(ArgumentException)
                { }

            }

            //then
            foreach (var sessionId in sessionIds)
            {
                sessionId.ShouldNotBeNull();
            }
        }
All Usage Examples Of Syncano.Net.Api.ApiKeySyncanoClient::StartSession