Esempio n. 1
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));
        }
Esempio n. 2
0
        /// <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="pageNumber">The contacts' page number to get.</param>
        /// <param name="payload">A string to receive when the function returns.</param>
        public static void GetContacts(Provider provider, int pageNumber = 0, string payload = "")
        {
            SocialProvider targetProvider = GetSocialProvider(provider);
            string         userPayload    = (payload == null) ? "" : payload;

            if (targetProvider == null)
            {
                return;
            }

            if (targetProvider.IsNativelyImplemented())
            {
                //fallback to native
                //TODO: add pageNumber here when implemented natively
                instance._getContacts(provider, ProfilePayload.ToJSONObj(userPayload).ToString());
            }

            else
            {
                ProfileEvents.OnGetContactsStarted(provider, pageNumber, userPayload);
                targetProvider.GetContacts(pageNumber,
                                           /* success */ (SocialPageData <UserProfile> contactsData) => {
                    ProfileEvents.OnGetContactsFinished(provider, contactsData, userPayload);
                },
                                           /* fail */ (string message) => { ProfileEvents.OnGetContactsFailed(provider, pageNumber, message, userPayload); }
                                           );
            }
        }
Esempio n. 3
0
        /// <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="payload">A string to receive when the function returns.</param>
        public static void GetContacts(Provider provider, string payload = "")
        {
            SocialProvider targetProvider = GetSocialProvider(provider);
            string         userPayload    = (payload == null) ? "" : payload;

            if (targetProvider == null)
            {
                return;
            }

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

            else
            {
                ProfileEvents.OnGetContactsStarted(provider, userPayload);
                targetProvider.GetContacts(
                    /* success */ (List <UserProfile> profiles) => {
                    ProfileEvents.OnGetContactsFinished(provider, profiles, userPayload);
                },
                    /* fail */ (string message) => { ProfileEvents.OnGetContactsFailed(provider, message, userPayload); }
                    );
            }
        }
Esempio n. 4
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);

            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));
            }

            ProfileEvents.OnGetContactsFinished(provider, userProfiles, ProfilePayload.GetUserPayload(payloadJSON));
        }