/// <summary> /// Connects a service to SoundByte. This will allow accessing /// user content. The ServiceConnected event is fired. /// </summary> /// <param name="type">The service to connect.</param> /// <param name="token">The required token</param> public void ConnectService(int type, LoginToken token) { if (_isLoaded == false) { throw new SoundByteNotLoadedException(); } var service = Services.FirstOrDefault(x => x.Service == type); if (service == null) { throw new ServiceNotExistException(type); } // Set the token service.UserToken = token; if (service.UserToken != null) { try { switch (service.Service) { case ServiceTypes.SoundCloud: case ServiceTypes.SoundCloudV2: service.CurrentUser = AsyncHelper.RunSync(async() => await GetAsync <SoundCloudUser>(ServiceTypes.SoundCloud, "/me").ConfigureAwait(false)).Response.ToBaseUser(); break; case ServiceTypes.SoundByte: service.CurrentUser = AsyncHelper.RunSync(async() => await GetAsync <BaseUser>(ServiceTypes.SoundByte, "/me").ConfigureAwait(false)).Response; break; case ServiceTypes.YouTube: service.CurrentUser = AsyncHelper.RunSync(async() => await GetAsync <YouTubeChannelHolder>(ServiceTypes.YouTube, "/channels", new Dictionary <string, string> { { "mine", "true" }, { "part", "snippet" } }).ConfigureAwait(false)).Response.Channels.FirstOrDefault()?.ToBaseUser(); break; } } catch { // Todo: There are many reasons why this could fail. // For now we just delete the user token service.UserToken = null; } } // Fire the event OnServiceConnected?.Invoke(type, token); }
/// <summary> /// Connects a service to SoundByte. This will allow accessing /// user content. The ServiceConnected event is fired. /// </summary> /// <param name="type">The service to connect.</param> /// <param name="token">The required token</param> public void ConnectService(ServiceType type, LoginToken token) { if (_isLoaded == false) { throw new SoundByteNotLoadedException(); } var service = Services.FirstOrDefault(x => x.Service == type); if (service == null) { throw new ServiceNotExistException(type); } // Set the token service.UserToken = token; if (service.UserToken != null) { try { switch (service.Service) { case ServiceType.Fanburst: service.CurrentUser = AsyncHelper.RunSync(async() => await GetAsync <FanburstUser>(ServiceType.Fanburst, "/me").ConfigureAwait(false)).Response.ToBaseUser(); break; case ServiceType.SoundCloud: case ServiceType.SoundCloudV2: service.CurrentUser = AsyncHelper.RunSync(async() => await GetAsync <SoundCloudUser>(ServiceType.SoundCloud, "/me").ConfigureAwait(false)).Response.ToBaseUser(); break; case ServiceType.YouTube: // Do this later break; } } catch { // Todo: There are many reasons why this could fail. // For now we just delete the user token service.UserToken = null; } } // Fire the event OnServiceConnected?.Invoke(type, token); }