private void WithHadesClient(Action <Hades.Client> whenReady, Action <GetSocialError> onError = null, bool requireInitialization = true) { if (requireInitialization && !IsInitialized) { GetSocialLogs.W("Failed to call GetSocial before it is initialized."); onError.SafeCall(new GetSocialError(ErrorCodes.IllegalState, "Failed to call GetSocial before it is initialized")); return; } HadesClientFactory.Create(client => { Action <GetSocialError> handleError = getSocialError => { Ui(() => { GetSocialLogs.W("Error: " + getSocialError); _stateController.OnError.SafeCall(getSocialError); onError.SafeCall(getSocialError); }); }; try { whenReady(client); } catch (THErrors error) { var first = error.Errors.First(); handleError(new GetSocialError((int)first.ErrorCode, first.ErrorMsg)); } catch (Exception exception) { handleError(new GetSocialError(exception.Message)); } }); }
public UserCredentials LoadUserCredentials(string appId) { // check app id if (!appId.Equals(LoadSavedAppId())) { GetSocialLogs.W("Stored AppId [ " + LoadSavedAppId() + " ] is different than current one [" + appId + "]. New user will be created."); ClearUser(); return(new UserCredentials()); } // check userId and password var userId = _localStorage.GetString(LocalStorageKeys.UserId); string password = _localStorage.GetString(LocalStorageKeys.UserPassword); if (userId == null || password == null) { GetSocialLogs.W("Invalid user credentials, userId = [" + userId + "], password = [ " + password + " ]. New user will be created."); ClearUser(); return(new UserCredentials()); } return(new UserCredentials { Id = userId, Password = password }); }
private static void LogResponse(string method, object parameters) { try { GetSocialLogs.D(string.Format("[Response] {0}: {1}", method, parameters)); } catch { // Just to be sure we won't crash in logs } }
private void Init(THSdkAuthRequest request) { LogRequest("authenticateSdk", request); WithHadesClient(client => { THSdkAuthResponseAllInOne response = null; while (response == null) { try { try { response = client.authenticateSdkAllInOne(new THSdkAuthRequestAllInOne { SdkAuthRequest = request, ProcessAppOpenRequest = new THProcessAppOpenRequest { } }); } catch (THErrors errors) { GetSocialLogs.W(errors.Errors.First().ErrorMsg); throw errors; // if GetSocial exception - rethrow } } catch (Exception exception) { // if system exception - try again Ui(() => GetSocialLogs.W("Failed to init GetSocial, retry in 1 second, exception: " + exception)); // wait for 1 sec Thread.Sleep(1000); // unity doesn't stop background threads, so we have to check a state of app if (!EngineUtils.IsApplicationRunning()) { return; } } } Ui(() => { LogResponse("authenticateSdk", response); _stateController.Initialized(response, request.AppId); #if !UNITY_EDITOR TrackAnalyticsEvent(new AnalyticsEvent { Name = AnalyticsEventDetails.AppSessionStart, CreatedAt = ApplicationStateListener.Instance.AppStartTime }); #endif }); }, requireInitialization: false); }
private static void LogRequest(string method, object parameters = null) { try { var log = parameters == null ? string.Format("[Request] {0}", method) : string.Format("[Request] {0}, body: {1}", method, parameters); GetSocialLogs.D(log); } catch { // Just to be sure we won't crash in logs } }
public void SetUserDetails(UserUpdate userUpdate, Action onSuccess, Action <GetSocialError> onFailure) { if (userUpdate._avatar != null) { GetSocialLogs.W("Uploading Texture2D as avatar is not supported in Editor yet"); } UpdateUser(new THPrivateUser { DisplayName = userUpdate._displayName, AvatarUrl = userUpdate._avatarUrl, PublicProperties = userUpdate._publicProperties, PrivateProperties = userUpdate._privateProperties, InternalPublicProperties = userUpdate._publicInternalProperties, InternalPrivateProperties = userUpdate._privateInternalProperties }, onSuccess, onFailure); }
public static THActivityPostContent ToRpcModel(this ActivityPostContent content) { var media = content._mediaAttachment; if (!media.IsSupported()) { GetSocialLogs.W("Uploading Texture2D or video is not supported in Editor yet"); } return(new THActivityPostContent { Text = content._text, ButtonTitle = content._buttonTitle, ButtonAction = content._buttonAction, Language = GetSocial.GetLanguage(), ImageUrl = media.GetImageUrl(), VideoUrl = media.GetVideoUrl(), Action = content._action.ToRpcModel() }); }
public void Init(string appId) { if (_initCalled) { GetSocialLogs.I("GetSocial.Init has been already invoked."); return; } _initCalled = true; appId = appId ?? _stateController.LoadAppIdFromMetaData(); var credentials = _stateController.LoadUserCredentials(appId); Init(new THSdkAuthRequest { AppId = appId, UserId = credentials.Id, Password = credentials.Password, SessionProperties = _stateController.SuperProperties }); }
public static THCustomNotification ToRpcModel(this NotificationContent content) { var media = content._mediaAttachment; if (!media.IsSupported()) { GetSocialLogs.W("Uploading Texture2D or video is not supported in Editor yet"); } return(new THCustomNotification { Title = content._title, Text = content._text, TemplateName = content._templateName, TemplateData = content._templatePlaceholders, NewAction = content._action.ToRpcModel(), Image = media.GetImageUrl(), Video = media.GetVideoUrl(), ActionButtons = content._actionButtons.ConvertAll(button => button.ToRpcModel()), Badge = content._badge.ToRpcModel() }); }
public bool IsInviteChannelAvailable(string channelId) { GetSocialLogs.W("IsInviteChannelAvailable is not supported in Editor yet"); return(false); }
public void SetAvatar(Texture2D avatar, Action onComplete, Action <GetSocialError> onFailure) { GetSocialLogs.W("Uploading Texture2D as avatar is not supported in Editor yet"); onFailure(new GetSocialError("Uploading Texture2D as avatar is not supported in Editor yet")); }
public void SetPushTokenListener(PushTokenListener listener) { GetSocialLogs.W("SetPushTokenListener is not supported in Editor yet"); }
public void SetNotificationListener(Func <Notification, bool, bool> listener) { GetSocialLogs.W("SetNotificationListener is not supported in Editor yet"); }
public void RegisterForPushNotifications() { GetSocialLogs.W("RegisterForPushNotifications is not supported in Editor yet"); }
public void GetReferralData(Action <ReferralData> onSuccess, Action <GetSocialError> onFailure) { GetSocialLogs.W("GetReferralData is not supported in Editor yet"); onFailure(new GetSocialError("GetReferralData doesn't work in Unity Editor yet")); }
public bool RegisterInviteChannelPlugin(string channelId, InviteChannelPlugin inviteChannelPlugin) { GetSocialLogs.W("RegisterInviteChannelPlugin is not supported in Editor yet"); return(false); }
public void SetNotificationListener(NotificationListener listener) { GetSocialLogs.W("SetNotificationListener is not supported in Editor yet"); }
public bool TrackPurchaseEvent(PurchaseData purchaseData) { GetSocialLogs.W("TrackPurchaseEvent is not supported in Editor yet"); return(false); }
public void ProcessAction(GetSocialAction notificationAction) { GetSocialLogs.W("ProcessAction is not supported in Editor yet"); }
public void HandleOnStartUnityEvent() { GetSocialLogs.D("Not needed in OSX implementation"); }
public void SendInvite(string channelId, InviteContent customInviteContent, LinkParams linkParams, Action onComplete, Action onCancel, Action <GetSocialError> onFailure) { GetSocialLogs.W("SendInvite is not supported in Editor yet"); onFailure(new GetSocialError("SendInvite doesn't work in Unity Editor yet")); }
public void ClearReferralData() { GetSocialLogs.W("ClearReferralData is not supported in Editor yet"); }