Example #1
0
        /// <summary>
        /// Handles an <c>onUserRatingEvent</c> event
        /// </summary>
        public void onUserRatingEvent()
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onUserRatingEvent");

            ProfileEvents.OnUserRatingEvent();
            //ProfileEvents.OnUserRatingEvent (new UserRatingEvent());
        }
        /// <summary>
        /// Retrieves a list of the user's feed entries from the supplied provider.
        /// Upon a successful retrieval of feed entries the user will be granted the supplied reward.
        ///
        /// NOTE: This operation requires a successful login.
        /// </summary>
        /// <param name="provider">The <c>Provider</c> on which to retrieve a list of feed entries.</param>
        /// <param name="fromStart">Should we reset pagination or request the next page.</param>
        /// <param name="payload">A string to receive when the function returns.</param>
        /// <param name="reward">The reward which will be granted to the user upon a successful retrieval of feed.</param>
        public static void GetFeed(Provider provider, bool fromStart = false, string payload = "", Reward reward = null)
        {
            SocialProvider targetProvider = GetSocialProvider(provider);
            string         userPayload    = (payload == null) ? "" : payload;

            if (targetProvider == null)
            {
                return;
            }

            if (targetProvider.IsNativelyImplemented())
            {
                string rewardId = reward != null ? reward.ID: "";
                //fallback to native
                instance._getFeed(provider, fromStart, ProfilePayload.ToJSONObj(userPayload, rewardId).ToString());
            }
            else
            {
                ProfileEvents.OnGetFeedStarted(provider);
                targetProvider.GetFeed(fromStart,
                                       /* success */
                                       (SocialPageData <String> feeds) => {
                    if (reward != null)
                    {
                        reward.Give();
                    }
                    ProfileEvents.OnGetFeedFinished(provider, feeds);
                },
                                       /* fail */
                                       (string message) => {
                    ProfileEvents.OnGetFeedFailed(provider, message);
                });
            }
        }
        /// <summary>
        /// Fetches UserProfiles of contacts of the current user.
        /// Supported platforms: Facebook, Twitter, Google+.
        /// Missing contact information for Twitter: email, gender, birthday.
        /// Missing contact information for Google+: username, email, gender, bithday
        ///
        /// NOTE: This operation requires a successful login.
        /// </summary>
        /// <param name="provider">The <c>Provider</c> to fetch contacts from.</param>
        /// <param name="fromStart">Should we reset pagination or request the next page.</param>
        /// <param name="payload">A string to receive when the function returns.</param>
        public static void GetContacts(Provider provider, bool fromStart = false, string payload = "")
        {
            SocialProvider targetProvider = GetSocialProvider(provider);
            string         userPayload    = (payload == null) ? "" : payload;

            if (targetProvider == null)
            {
                return;
            }

            if (targetProvider.IsNativelyImplemented())
            {
                //fallback to native
                instance._getContacts(provider, fromStart, ProfilePayload.ToJSONObj(userPayload).ToString());
            }

            else
            {
                ProfileEvents.OnGetContactsStarted(provider, fromStart, userPayload);
                targetProvider.GetContacts(fromStart,
                                           /* success */ (SocialPageData <UserProfile> contactsData) => {
                    ProfileEvents.OnGetContactsFinished(provider, contactsData, userPayload);
                },
                                           /* fail */ (string message) => { ProfileEvents.OnGetContactsFailed(provider, message, fromStart, userPayload); }
                                           );
            }
        }
        /// <summary>
        /// Posts a full story to the user's social page on the given Provider with confirmation dialog.
        /// A story contains a title, description, image and more.
        /// Supported platforms: Facebook (full support),
        /// Twitter and Google+ (partial support - message and link only)
        ///
        /// NOTE: This operation requires a successful login.
        /// </summary>
        /// <param name="provider">The <c>Provider</c> the given story should be posted to.</param>
        /// <param name="message">A message that will be shown along with the story.</param>
        /// <param name="name">The name (title) of the story.</param>
        /// <param name="caption">A caption.</param>
        /// <param name="description">A description.</param>
        /// <param name="link">A link to a web page.</param>
        /// <param name="pictureUrl">A link to an image on the web.</param>
        /// <param name="payload">A string to receive when the function returns.</param>
        /// <param name="reward">A <c>Reward</c> to give the user after a successful post.</param>
        /// <param name="customMessage">The message to show in the dialog</param>
        public static void UpdateStoryWithConfirmation(Provider provider, string message, string name,
                                                       string caption, string description, string link, string pictureUrl,
                                                       string payload       = "", Reward reward = null,
                                                       string customMessage = null)
        {
            SocialProvider targetProvider = GetSocialProvider(provider);
            string         userPayload    = (payload == null) ? "" : payload;

            if (targetProvider == null)
            {
                return;
            }


            // TODO: Support showConfirmation
            ProfileEvents.OnSocialActionStarted(provider, SocialActionType.UPDATE_STORY, userPayload);
            targetProvider.UpdateStory(message, name, caption, link, pictureUrl,
                                       /* success */ () => {
                if (reward != null)
                {
                    reward.Give();
                }
                ProfileEvents.OnSocialActionFinished(provider, SocialActionType.UPDATE_STORY, userPayload);
            },
                                       /* fail */ (string error) => { ProfileEvents.OnSocialActionFailed(provider, SocialActionType.UPDATE_STORY, error, userPayload); },
                                       /* cancel */ () => { ProfileEvents.OnSocialActionCancelled(provider, SocialActionType.UPDATE_STORY, userPayload); }
                                       );
        }
Example #5
0
        /// <summary>
        /// Logs the user out of the given provider.
        /// Supported platforms: Facebook, Twitter, Google+
        ///
        /// NOTE: This operation requires a successful login.
        /// </summary>
        /// <param name="provider">The provider to log out from.</param>
        public static void Logout(Provider provider)
        {
            SocialProvider targetProvider = GetSocialProvider(provider);

            if (targetProvider == null)
            {
                return;
            }

            if (targetProvider.IsNativelyImplemented())
            {
                //fallback to native
                instance._logout(provider);
            }

            else
            {
                ProfileEvents.OnLogoutStarted(provider);
                targetProvider.Logout(
                    /* success */ () => {
                    UserProfile userProfile = GetStoredUserProfile(provider);
                    if (userProfile != null)
                    {
                        RemoveUserProfile(userProfile);
                    }
                    ProfileEvents.OnLogoutFinished(provider);
                },
                    /* fail */ (string message) => { ProfileEvents.OnLogoutFailed(provider, message); }
                    );
            }
        }
Example #6
0
        /// <summary>
        /// Updates the user's status on the given provider.
        /// Supported platforms: Facebook, Twitter, Google+
        ///
        /// NOTE: This operation requires a successful login.
        /// </summary>
        /// <param name="provider">The <c>Provider</c> the given status should be posted to.</param>
        /// <param name="status">The actual status text.</param>
        /// <param name="payload">A string to receive when the function returns.</param>
        /// <param name="reward">A <c>Reward</c> to give the user after a successful post.</param>
        public static void UpdateStatus(Provider provider, string status, string payload = "", Reward reward = null)
        {
            SocialProvider targetProvider = GetSocialProvider(provider);
            string         userPayload    = (payload == null) ? "" : payload;

            if (targetProvider == null)
            {
                return;
            }

            if (targetProvider.IsNativelyImplemented())
            {
                //fallback to native
                string rewardId = reward != null ? reward.ID : "";
                instance._updateStatus(provider, status, ProfilePayload.ToJSONObj(userPayload, rewardId).ToString());
            }

            else
            {
                ProfileEvents.OnSocialActionStarted(provider, SocialActionType.UPDATE_STATUS, userPayload);
                targetProvider.UpdateStatus(status,
                                            /* success */ () => {
                    if (reward != null)
                    {
                        reward.Give();
                    }
                    ProfileEvents.OnSocialActionFinished(provider, SocialActionType.UPDATE_STATUS, userPayload);
                },
                                            /* fail */ (string error) => { ProfileEvents.OnSocialActionFailed(provider, SocialActionType.UPDATE_STATUS, error, userPayload); }
                                            );
            }
        }
Example #7
0
        private static void login(Provider provider, bool autoLogin, string payload = "", Reward reward = null)
        {
            SoomlaUtils.LogDebug(TAG, "Trying to login with provider " + provider.ToString());
            SocialProvider targetProvider = GetSocialProvider(provider);
            string         userPayload    = (payload == null) ? "" : payload;

            if (targetProvider == null)
            {
                SoomlaUtils.LogError(TAG, "Provider not supported or not set as active: " + provider.ToString());
                return;
            }


            setLoggedInForProvider(provider, false);
            ProfileEvents.OnLoginStarted(provider, autoLogin, userPayload);
            targetProvider.Login(
                /* success */ () => {
                targetProvider.GetUserProfile((UserProfile userProfile) => {
                    StoreUserProfile(userProfile);
                    setLoggedInForProvider(provider, true);
                    ProfileEvents.OnLoginFinished(userProfile, autoLogin, userPayload);
                    if (reward != null)
                    {
                        reward.Give();
                    }
                }, (string message) => {
                    ProfileEvents.OnLoginFailed(provider, message, autoLogin, userPayload);
                });
            },
                /* fail */ (string message) => { ProfileEvents.OnLoginFailed(provider, message, autoLogin, userPayload); },
                /* cancel */ () => { ProfileEvents.OnLoginCancelled(provider, autoLogin, userPayload); }
                );
        }
Example #8
0
        /// <summary>
        /// Handles an <c>onGetFeedFinished</c> event
        /// </summary>
        /// <param name="message">
        /// Will contain a numeric representation of <c>Provider</c>,
        /// json array of feeds</param>
        public void onGetFeedFinished(String message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onGetFeedFinished");

            JSONObject    eventJson = new JSONObject(message);
            Provider      provider  = Provider.fromInt((int)eventJson["provider"].n);
            JSONObject    feedsJson = eventJson ["feeds"];
            List <String> feeds     = new List <String>();

            foreach (JSONObject feedVal in feedsJson.list)
            {
                //iterate "feed" keys
                feeds.Add(feedVal.str);
            }

            bool hasMore = eventJson["hasMore"].b;

            JSONObject payloadJSON         = new JSONObject(eventJson ["payload"].str);
            SocialPageData <String> result = new SocialPageData <String>();

            result.PageData   = feeds;
            result.PageNumber = 0;
            result.HasMore    = hasMore;
            ProfileEvents.OnGetFeedFinished(provider, result);
        }
Example #9
0
        /// <summary>
        /// Handles an <c>onInviteFinished</c> event
        /// </summary>
        /// <param name="message">
        /// Will contain a numeric representation of <c>Provider</c>
        /// numeric representation of <c>SocialActionType</c>
        /// id of given request, list of invite recipients
        /// and payload</param>
        public void onInviteFinished(String message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onInviteFinished");

            JSONObject eventJson = new JSONObject(message);

            Provider provider = Provider.fromInt((int)eventJson["provider"].n);

            String        requestId      = eventJson["requestId"].str;
            JSONObject    recipientsJson = eventJson ["invitedIds"];
            List <String> recipients     = new List <String>();

            foreach (JSONObject recipientVal in recipientsJson.list)
            {
                //iterate "feed" keys
                recipients.Add(recipientVal.str);
            }

            JSONObject payloadJSON = new JSONObject(eventJson ["payload"].str);

            //give a reward
            Reward reward = Reward.GetReward(ProfilePayload.GetRewardId(payloadJSON));

            if (reward != null)
            {
                reward.Give();
            }

            ProfileEvents.OnInviteFinished(provider, requestId, recipients, ProfilePayload.GetUserPayload(payloadJSON));
        }
 internal static void TryFireProfileInitialized()
 {
     if (AllProvidersInitialized())
     {
         ProfileEvents.OnSoomlaProfileInitialized();
     }
 }
Example #11
0
        /// <summary>
        /// Handles an <c>onGetContactsFinished</c> event
        /// </summary>
        /// <param name="message">
        /// Will contain a numeric representation of <c>Provider</c>,
        /// JSON array of <c>UserProfile</c>s and payload</param>
        public void onGetContactsFinished(String message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onGetContactsFinished");

            JSONObject eventJson = new JSONObject(message);

            Provider provider = Provider.fromInt((int)eventJson["provider"].n);

            bool hasMore = eventJson["hasMore"].b;

            JSONObject payloadJSON = new JSONObject(eventJson ["payload"].str);

            JSONObject         userProfilesArray = eventJson ["contacts"];
            List <UserProfile> userProfiles      = new List <UserProfile>();

            foreach (JSONObject userProfileJson in userProfilesArray.list)
            {
                userProfiles.Add(new UserProfile(userProfileJson));
            }

            SocialPageData <UserProfile> data = new SocialPageData <UserProfile>();

            data.PageData   = userProfiles;
            data.PageNumber = 0;
            data.HasMore    = hasMore;

            ProfileEvents.OnGetContactsFinished(provider, data, ProfilePayload.GetUserPayload(payloadJSON));
        }
Example #12
0
        /// <summary>
        /// Uploads an image to the user's social page on the given Provider.
        /// Supported platforms: Facebook, Twitter, Google+
        ///
        /// NOTE: This operation requires a successful login.
        /// </summary>
        /// <param name="provider">The <c>Provider</c> the given image should be uploaded to.</param>
        /// <param name="message">Message to post with the image.</param>
        /// <param name="fileName">Name of image file with extension (jpeg/pgn).</param>
        /// <param name="imageBytes">Image bytes.</param>
        /// <param name="jpegQuality">Image quality, number from 0 to 100. 0 meaning compress for small size, 100 meaning compress for max quality.
        /// Some formats, like PNG which is lossless, will ignore the quality setting
        /// <param name="payload">A string to receive when the function returns.</param>
        /// <param name="reward">A <c>Reward</c> to give the user after a successful upload.</param>
        public static void UploadImage(Provider provider, string message, string fileName, byte[] imageBytes,
                                       int jpegQuality, string payload = "", Reward reward = null)
        {
            SocialProvider targetProvider = GetSocialProvider(provider);
            string         userPayload    = (payload == null) ? "" : payload;

            if (targetProvider == null)
            {
                return;
            }

            if (targetProvider.IsNativelyImplemented())
            {
                string rewardId = reward != null ? reward.ID: "";
                instance._uploadImage(provider, message, fileName, imageBytes, jpegQuality,
                                      ProfilePayload.ToJSONObj(userPayload, rewardId).ToString());
            }

            else
            {
                ProfileEvents.OnSocialActionStarted(provider, SocialActionType.UPLOAD_IMAGE, userPayload);
                targetProvider.UploadImage(imageBytes, fileName, message,
                                           /* success */ () => {
                    if (reward != null)
                    {
                        reward.Give();
                    }
                    ProfileEvents.OnSocialActionFinished(provider, SocialActionType.UPLOAD_IMAGE, userPayload);
                },
                                           /* fail */ (string error) => { ProfileEvents.OnSocialActionFailed(provider, SocialActionType.UPLOAD_IMAGE, error, userPayload); },
                                           /* cancel */ () => { ProfileEvents.OnSocialActionCancelled(provider, SocialActionType.UPLOAD_IMAGE, userPayload); }
                                           );
            }
        }
Example #13
0
        /// <summary>
        /// Handles an <c>onGetScoresFinished</c> event
        /// </summary>
        /// <param name="message">
        /// Will contain a numeric representation of <c>Provider</c>,
        /// and payload</param>
        public void onGetScoresFinished(String message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onGetScoresFinished");

            JSONObject eventJson = new JSONObject(message);

            Provider    provider = Provider.fromInt((int)eventJson["provider"].n);
            Leaderboard owner    = new Leaderboard(eventJson["leaderboard"]);

            bool hasMore = eventJson["hasMore"].b;

            JSONObject payloadJSON = new JSONObject(eventJson ["payload"].str);

            JSONObject   scoresArray = eventJson ["scores"];
            List <Score> scores      = new List <Score>();

            foreach (JSONObject scoreJson in scoresArray.list)
            {
                scores.Add(new Score(scoreJson));
            }

            SocialPageData <Score> data = new SocialPageData <Score>();

            data.PageData   = scores;
            data.PageNumber = 0;
            data.HasMore    = hasMore;

            ProfileEvents.OnGetScoresFinished(new GetScoresFinishedEvent(provider, owner, data, ProfilePayload.GetUserPayload(payloadJSON)));
        }
Example #14
0
        /// <summary>
        /// Handles an <c>onGetLeaderboardsFinished</c> event
        /// </summary>
        /// <param name="message">
        /// Will contain a numeric representation of <c>Provider</c>,
        /// and payload</param>
        public void onGetLeaderboardsFinished(String message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onGetLeaderboardsFinished");

            JSONObject eventJson = new JSONObject(message);

            Provider provider = Provider.fromInt((int)eventJson["provider"].n);


            JSONObject payloadJSON = new JSONObject(eventJson ["payload"].str);

            JSONObject         leaderboardsArray = eventJson ["leaderboards"];
            List <Leaderboard> leaderboards      = new List <Leaderboard>();

            foreach (JSONObject leaderboardJson in leaderboardsArray.list)
            {
                leaderboards.Add(new Leaderboard(leaderboardJson));
            }

            SocialPageData <Leaderboard> data = new SocialPageData <Leaderboard>();

            data.PageData   = leaderboards;
            data.PageNumber = 0;
            data.HasMore    = false;

            ProfileEvents.OnGetLeaderboardsFinished(new GetLeaderboardsFinishedEvent(provider, data, ProfilePayload.GetUserPayload(payloadJSON)));
        }
Example #15
0
        /// <summary>
        /// Handles an <c>onUserProfileUpdated</c> event
        /// </summary>
        /// <param name="message">Will contain a JSON representation of a <c>UserProfile</c></param>
        public void onUserProfileUpdated(String message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onUserProfileUpdated");

            JSONObject  eventJson   = new JSONObject(message);
            UserProfile userProfile = new UserProfile(eventJson ["userProfile"]);

            ProfileEvents.OnUserProfileUpdated(userProfile);
        }
Example #16
0
        /// <summary>
        /// Handles an <c>onGetFeedStarted</c> event
        /// </summary>
        /// <param name="message">
        /// Will contain a numeric representation of <c>Provider</c>,
        /// and payload</param>
        public void onGetFeedStarted(String message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onGetFeedStarted");

            JSONObject eventJson = new JSONObject(message);

            Provider provider = Provider.fromInt((int)eventJson["provider"].n);

            ProfileEvents.OnGetFeedStarted(provider);
        }
Example #17
0
        /// <summary>
        /// Handles an <c>onShowLeaderboards</c> event
        /// </summary>
        /// <param name="message">
        /// Will contain a numeric representation of <c>Provider</c>
        /// </param>
        public void onShowLeaderboards(String message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onShowLeaderboards");

            JSONObject eventJson = new JSONObject(message);

            Provider   provider    = Provider.fromInt((int)eventJson["provider"].n);
            JSONObject payloadJSON = new JSONObject(eventJson ["payload"].str);

            ProfileEvents.OnShowLeaderboards(new ShowLeaderboardsEvent(provider, ProfilePayload.GetUserPayload(payloadJSON)));
        }
Example #18
0
        /// <summary>
        /// Handles an <c>onLogoutFinished</c> event
        /// </summary>
        /// <param name="message">
        /// Will contain a numeric representation of <c>Provider</c></param>
        public void onLogoutFinished(String message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onLogoutFinished");

            JSONObject eventJson = new JSONObject(message);

            Provider provider = Provider.fromInt((int)(eventJson["provider"].n));

            ProfileEvents.OnLogoutFinished(provider);
            //ProfileEvents.OnLogoutFinished(new LogoutFinishedEvent(provider));
        }
Example #19
0
        /// <summary>
        /// Handles an <c>onLoginStarted</c> event
        /// </summary>
        /// <param name="message">
        /// Will contain a numeric representation of <c>Provider</c>
        /// as well as payload </param>
        public void onLoginStarted(String message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onLoginStarted");

            JSONObject eventJson = new JSONObject(message);
            Provider   provider  = Provider.fromInt((int)(eventJson["provider"].n));

            JSONObject payloadJSON = new JSONObject(eventJson ["payload"].str);

            ProfileEvents.OnLoginStarted(provider, ProfilePayload.GetUserPayload(payloadJSON));
        }
Example #20
0
        /// <summary>
        /// Handles an <c>onLogoutFailed</c> event
        /// </summary>
        /// <param name="message">
        /// Will contain a numeric representation of <c>Provider</c>
        /// and payload</param>
        public void onLogoutFailed(String message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onLogoutFailed");

            JSONObject eventJson = new JSONObject(message);

            Provider provider     = Provider.fromInt((int)(eventJson["provider"].n));
            String   errorMessage = eventJson["message"].str;

            ProfileEvents.OnLogoutFailed(provider, errorMessage);
        }
Example #21
0
        /// <summary>
        /// Handles an <c>onSubmitScoreStarted</c> event
        /// </summary>
        /// <param name="message">
        /// Will contain a numeric representation of <c>Provider</c>,
        /// and payload</param>
        public void onSubmitScoreStarted(String message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onSubmitScoreStarted");

            JSONObject eventJson = new JSONObject(message);

            Provider    provider    = Provider.fromInt((int)eventJson["provider"].n);
            Leaderboard owner       = new Leaderboard(eventJson["leaderboard"]);
            JSONObject  payloadJSON = new JSONObject(eventJson ["payload"].str);

            ProfileEvents.OnSubmitScoreStarted(new SubmitScoreStartedEvent(provider, owner, ProfilePayload.GetUserPayload(payloadJSON)));
        }
Example #22
0
        /// <summary>
        /// Handles an <c>onSocialActionCancelled</c> event
        /// </summary>
        /// <param name="message">
        /// Will contain a numeric representation of <c>Provider</c>
        /// numeric representation of <c>SocialActionType</c> and payload</param>
        public void onSocialActionCancelled(String message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onSocialActionCancelled");

            JSONObject eventJson = new JSONObject(message);

            Provider         provider     = Provider.fromInt((int)eventJson["provider"].n);
            SocialActionType socialAction = SocialActionType.fromInt((int)eventJson["socialActionType"].n);

            JSONObject payloadJSON = new JSONObject(eventJson ["payload"].str);

            ProfileEvents.OnSocialActionCancelled(provider, socialAction, ProfilePayload.GetUserPayload(payloadJSON));
        }
Example #23
0
        /// <summary>
        /// Handles an <c>onInviteFailed</c> event
        /// </summary>
        /// <param name="message">
        /// Will contain a numeric representation of <c>Provider</c>
        /// numeric representation of <c>SocialActionType</c>,
        /// error message and payload</param>
        public void onInviteFailed(String message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onInviteFailed");

            JSONObject eventJson = new JSONObject(message);

            Provider provider     = Provider.fromInt((int)eventJson["provider"].n);
            String   errorMessage = eventJson["message"].str;

            JSONObject payloadJSON = new JSONObject(eventJson ["payload"].str);

            ProfileEvents.OnInviteFailed(provider, errorMessage, ProfilePayload.GetUserPayload(payloadJSON));
        }
Example #24
0
        /// <summary>
        /// Handles an <c>onGetContactsStarted</c> event
        /// </summary>
        /// <param name="message">
        /// Will contain a numeric representation of <c>Provider</c>,
        /// and payload</param>
        public void onGetContactsStarted(String message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onGetContactsStarted");

            JSONObject eventJson = new JSONObject(message);

            Provider provider = Provider.fromInt((int)eventJson["provider"].n);

            JSONObject payloadJSON = new JSONObject(eventJson ["payload"].str);

            bool fromStart = eventJson["fromStart"].b;

            ProfileEvents.OnGetContactsStarted(provider, fromStart, ProfilePayload.GetUserPayload(payloadJSON));
        }
Example #25
0
        protected virtual void _storeUserProfile(UserProfile userProfile, bool notify)
        {
#if UNITY_EDITOR
            string key = keyUserProfile(userProfile.Provider);
            string val = userProfile.toJSONObject().ToString();
            SoomlaUtils.LogDebug(TAG, "key/val:" + key + "/" + val);
            PlayerPrefs.SetString(key, val);

            if (notify)
            {
                ProfileEvents.OnUserProfileUpdated(userProfile);
            }
#endif
        }
Example #26
0
        /// <summary>
        /// Handles an <c>onLoginCancelled</c> event
        /// </summary>
        /// <param name="message">
        /// Will contain a numeric representation of <c>Provider</c>
        /// as well as payload </param>
        public void onLoginCancelled(String message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onLoginCancelled");

            JSONObject eventJson = new JSONObject(message);

            Provider provider = Provider.fromInt((int)(eventJson["provider"].n));

            bool autoLogin = eventJson["autoLogin"].b;

            JSONObject payloadJSON = new JSONObject(eventJson ["payload"].str);

            ProfileEvents.OnLoginCancelled(provider, autoLogin, ProfilePayload.GetUserPayload(payloadJSON));
            //ProfileEvents.OnLoginCancelled (new LoginCancelledEvent(provider, autoLogin, ProfilePayload.GetUserPayload(payloadJSON)));
        }
Example #27
0
        /// <summary>
        /// Handles an <c>onGetScoresFailed</c> event
        /// </summary>
        /// <param name="message">
        /// Will contain a numeric representation of <c>Provider</c>,
        /// and payload</param>
        public void onGetScoresFailed(String message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onGetScoresFailed");

            JSONObject eventJson = new JSONObject(message);

            Provider    provider     = Provider.fromInt((int)eventJson["provider"].n);
            Leaderboard owner        = new Leaderboard(eventJson["leaderboard"]);
            String      errorMessage = eventJson["message"].str;

            JSONObject payloadJSON = new JSONObject(eventJson ["payload"].str);

            bool fromStart = eventJson["fromStart"].b;

            ProfileEvents.OnGetScoresFailed(new GetScoresFailedEvent(provider, owner, fromStart, errorMessage, ProfilePayload.GetUserPayload(payloadJSON)));
        }
		#pragma warning restore 414


		public static void Initialize() {
			if (Instance == null) {
				CoreEvents.Initialize();
				Instance = GetSynchronousCodeGeneratedInstance<ProfileEvents>();
				
				SoomlaUtils.LogDebug (TAG, "Initializing ProfileEvents ...");
#if UNITY_ANDROID && !UNITY_EDITOR
				AndroidJNI.PushLocalFrame(100);
				//init ProfileEventHandler
				using(AndroidJavaClass jniEventHandler = new AndroidJavaClass("com.soomla.profile.unity.ProfileEventHandler")) {
					jniEventHandler.CallStatic("initialize");
				}
				AndroidJNI.PopLocalFrame(IntPtr.Zero);
#elif UNITY_IOS && !UNITY_EDITOR
				// On iOS, this is initialized inside the bridge library when we call "soomlaProfile_Initialize" in SoomlaProfileIOS
#endif
			}
		}
Example #29
0
        /// <summary>
        /// Initializes the SOOMLA Profile Module.
        ///
        /// NOTE: This function must be called before any of the class methods can be used.
        /// </summary>
        public static void Initialize()
        {
            instance._initialize(GetCustomParamsJson());             //add parameters
#if SOOMLA_FACEBOOK
            providers.Add(Provider.FACEBOOK, new FBSocialProvider());
#endif
#if SOOMLA_GOOGLE
            providers.Add(Provider.GOOGLE, new GPSocialProvider());
#endif
#if SOOMLA_TWITTER
            SoomlaUtils.LogDebug(TAG, "Adding TWITTER provider!!!!!");
            providers.Add(Provider.TWITTER, new TwitterSocialProvider());
#endif

#if UNITY_EDITOR
            ProfileEvents.OnSoomlaProfileInitialized();
#endif
        }
Example #30
0
		#pragma warning restore 414

		/// <summary>
		/// Initializes the game state before the game starts.
		/// </summary>
		void Awake(){
			if(instance == null){ 	// making sure we only initialize one instance.
				SoomlaUtils.LogDebug(TAG, "Initializing ProfileEvents (Awake)");

				instance = this;
				GameObject.DontDestroyOnLoad(this.gameObject);
				Initialize();
				// now we initialize the event pusher
				#if UNITY_ANDROID && !UNITY_EDITOR
				pep = new ProfileEventPusherAndroid();
				#elif UNITY_IOS && !UNITY_EDITOR
				pep = new ProfileEventPusherIOS();
				#endif

			} else {				// Destroying unused instances.
				GameObject.Destroy(this.gameObject);
			}
		}
Example #31
0
        /// <summary>
        /// Handles an <c>onGetFeedFinished</c> event
        /// </summary>
        /// <param name="message">
        /// Will contain a numeric representation of <c>Provider</c>,
        /// json array of feeds</param>
        public void onGetFeedFinished(String message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onGetFeedFinished");

            JSONObject eventJson = new JSONObject(message);

            Provider provider = Provider.fromInt((int)eventJson["provider"].n);

            JSONObject    feedsJson = eventJson ["feeds"];
            List <String> feeds     = new List <String>();

            foreach (String key in feedsJson.keys)
            {
                //iterate "feed" keys
                feeds.Add(feedsJson[key].str);
            }

            ProfileEvents.OnGetFeedFinished(provider, feeds);
        }
        /// <summary>
        /// Logs the user into the given provider.
        /// Supported platforms: Facebook, Twitter, Google+
        /// </summary>
        /// <param name="provider">The provider to log in to.</param>
        /// <param name="payload">A string to receive when the function returns.</param>
        /// <param name="reward">A <c>Reward</c> to give the user after a successful login.</param>
        public static void Login(Provider provider, string payload = "", Reward reward = null)
        {
            SoomlaUtils.LogDebug(TAG, "Trying to login with provider " + provider.ToString());
            SocialProvider targetProvider = GetSocialProvider(provider);
            string         userPayload    = (payload == null) ? "" : payload;

            if (targetProvider == null)
            {
                SoomlaUtils.LogError(TAG, "Provider not supported or not set as active: " + provider.ToString());
                return;
            }

            if (targetProvider.IsNativelyImplemented())
            {
                //fallback to native
                string rewardId = reward != null ? reward.ID : "";
                instance._login(provider, ProfilePayload.ToJSONObj(userPayload, rewardId).ToString());
            }

            else
            {
                setLoggedInForProvider(provider, false);
                ProfileEvents.OnLoginStarted(provider, userPayload);
                targetProvider.Login(
                    /* success */ () => {
                    targetProvider.GetUserProfile((UserProfile userProfile) => {
                        StoreUserProfile(userProfile);
                        setLoggedInForProvider(provider, true);
                        ProfileEvents.OnLoginFinished(userProfile, userPayload);
                        if (reward != null)
                        {
                            reward.Give();
                        }
                    }, (string message) => {
                        ProfileEvents.OnLoginFailed(provider, message, userPayload);
                    });
                },
                    /* fail */ (string message) => { ProfileEvents.OnLoginFailed(provider, message, userPayload); },
                    /* cancel */ () => { ProfileEvents.OnLoginCancelled(provider, userPayload); }
                    );
            }
        }