示例#1
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)));
        }
示例#2
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)));
        }
示例#3
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));
        }
示例#4
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);
        }
示例#5
0
        /// <summary>
        /// See docs in <see cref="SoomlaProfile.GetContacts"/>
        /// </summary>
        /// <param name="pageNumber">The contacts' page number to get</param>
        /// <param name="success">Callback function that is called if the contacts were fetched successfully.</param>
        /// <param name="fail">Callback function that is called if fetching contacts failed.</param>
        public override void GetContacts(int pageNumber, ContactsSuccess success, ContactsFailed fail)
        {
            FB.API("/me/friends?fields=id,name,picture,email,first_name,last_name&limit=" + DEFAULT_CONTACTS_PAGE_SIZE + "&offset=" + DEFAULT_CONTACTS_PAGE_SIZE * pageNumber,
                   Facebook.HttpMethod.GET,
                   (FBResult result) => {
                if (result.Error != null)
                {
                    SoomlaUtils.LogDebug(TAG, "GetContactsCallback[result.Error]: " + result.Error);
                    fail(result.Error);
                }
                else
                {
                    SoomlaUtils.LogDebug(TAG, "GetContactsCallback[result.Text]: " + result.Text);
                    SoomlaUtils.LogDebug(TAG, "GetContactsCallback[result.Texture]: " + result.Texture);
                    JSONObject jsonContacts = new JSONObject(result.Text);

                    SocialPageData <UserProfile> resultData = new SocialPageData <UserProfile>();
                    resultData.PageData   = UserProfilesFromFBJsonObjs(jsonContacts["data"].list);
                    resultData.PageNumber = pageNumber;

                    JSONObject paging = jsonContacts["paging"];
                    if (paging != null)
                    {
                        resultData.HasMore = (paging["next"] != null);
                    }

                    success(resultData);
                }
            });
        }
示例#6
0
        /// <summary>
        /// See docs in <see cref="SoomlaProfile.GetContacts"/>
        /// </summary>
        /// <param name="fromStart">Should we reset pagination or request the next page</param>
        /// <param name="success">Callback function that is called if the contacts were fetched successfully.</param>
        /// <param name="fail">Callback function that is called if fetching contacts failed.</param>
        public override void GetContacts(bool fromStart, ContactsSuccess success, ContactsFailed fail)
        {
            checkPermission("user_friends", () => {
                int pageNumber;
                if (fromStart || this.lastPageNumber == 0)
                {
                    pageNumber = 1;
                }
                else
                {
                    pageNumber = this.lastPageNumber + 1;
                }

                this.lastPageNumber = 0;


                FB.API("/me/friends?fields=id,name,picture,email,first_name,last_name&limit=" + DEFAULT_CONTACTS_PAGE_SIZE + "&offset=" + DEFAULT_CONTACTS_PAGE_SIZE * (pageNumber - 1),
                       Facebook.HttpMethod.GET,
                       (FBResult result) => {
                    if (result.Error != null)
                    {
                        SoomlaUtils.LogDebug(TAG, "GetContactsCallback[result.Error]: " + result.Error);
                        fail(result.Error);
                    }
                    else
                    {
                        SoomlaUtils.LogDebug(TAG, "GetContactsCallback[result.Text]: " + result.Text);
                        SoomlaUtils.LogDebug(TAG, "GetContactsCallback[result.Texture]: " + result.Texture);
                        JSONObject jsonContacts = new JSONObject(result.Text);

                        SocialPageData <UserProfile> resultData = new SocialPageData <UserProfile>();
                        resultData.PageData   = UserProfilesFromFBJsonObjs(jsonContacts["data"].list);
                        resultData.PageNumber = pageNumber;

                        this.lastPageNumber = pageNumber;

                        JSONObject paging = jsonContacts["paging"];
                        if (paging != null)
                        {
                            resultData.HasMore = (paging["next"] != null);
                        }

                        success(resultData);
                    }
                });
            }, (string errorMessage) => {
                fail(errorMessage);
            });
        }
示例#7
0
        public override void GetFeed(bool fromStart, FeedSuccess success, FeedFailed fail)
        {
            checkPermission("read_stream", () => {
                int pageNumber;
                if (fromStart || this.lastPageNumber == 0)
                {
                    pageNumber = 1;
                }
                else
                {
                    pageNumber = this.lastPageNumber + 1;
                }

                this.lastPageNumber = 0;

                FB.API("/me/feed?limit=" + DEFAULT_FEED_PAGE_SIZE + "&offset=" + DEFAULT_FEED_PAGE_SIZE * (pageNumber - 1),
                       Facebook.HttpMethod.GET,
                       (FBResult result) => {
                    if (result.Error != null)
                    {
                        SoomlaUtils.LogDebug(TAG, "GetFeedCallback[result.Error]: " + result.Error);
                        fail(result.Error);
                    }
                    else
                    {
                        SoomlaUtils.LogDebug(TAG, "GetFeedCallback[result.Text]: " + result.Text);
                        SoomlaUtils.LogDebug(TAG, "GetFeedCallback[result.Texture]: " + result.Texture);
                        JSONObject jsonFeed = new JSONObject(result.Text);

                        SocialPageData <String> resultData = new SocialPageData <String>();
                        resultData.PageData   = StoriesFromFBJsonObjs(jsonFeed["data"].list);
                        resultData.PageNumber = pageNumber;

                        this.lastPageNumber = pageNumber;

                        JSONObject paging = jsonFeed["paging"];
                        if (paging != null)
                        {
                            resultData.HasMore = (paging["next"] != null);
                        }

                        success(resultData);
                    }
                });
            },
                            (string errorMessage) => {
                fail(errorMessage);
            });
        }
        protected override void _pushEventGetContactsFinished(Provider provider, SocialPageData <UserProfile> contactsPage, string payload)
        {
            if (SoomlaProfile.IsProviderNativelyImplemented(provider))
            {
                return;
            }
            List <JSONObject> profiles = new List <JSONObject>();

            foreach (var profile in contactsPage.PageData)
            {
                profiles.Add(profile.toJSONObject());
            }
            JSONObject contacts = new JSONObject(profiles.ToArray());

            soomlaProfile_PushEventGetContactsFinished(provider.ToString(), contacts.ToString(), payload, contactsPage.HasMore);
        }
        protected override void _pushEventGetFeedFinished(Provider provider, SocialPageData <String> feedPage, string payload)
        {
            if (SoomlaProfile.IsProviderNativelyImplemented(provider))
            {
                return;
            }
            List <JSONObject> feeds = new List <JSONObject>();

            foreach (var feed in feedPage.PageData)
            {
                feeds.Add(JSONObject.StringObject(feed));
            }
            JSONObject jsonFeeds = new JSONObject(feeds.ToArray());

            soomlaProfile_PushEventGetFeedFinished(provider.ToString(), jsonFeeds.ToString(), payload, feedPage.HasMore);
        }
示例#10
0
        /// <summary>
        /// See docs in <see cref="SoomlaProfile.GetLeaderboards"/>
        /// </summary>
        public void GetLeaderboards(SocialPageDataSuccess <Leaderboard> success, FailureHandler fail)
        {
            var leaderboardJson = new JSONObject();

            leaderboardJson.AddField(PJSONConsts.UP_IDENTIFIER, "main");
            leaderboardJson.AddField(PJSONConsts.UP_PROVIDER, Provider.FACEBOOK.ToString());
            var leaderboard = new Leaderboard(leaderboardJson);

            var pageData = new SocialPageData <Leaderboard>();

            pageData.HasMore    = false;
            pageData.PageNumber = 1;
            pageData.PageData   = new List <Leaderboard>()
            {
                leaderboard
            };
            success(pageData);
        }
示例#11
0
        protected override void _pushEventGetFeedFinished(Provider provider, SocialPageData <String> feedPage, string payload)
        {
            if (SoomlaProfile.IsProviderNativelyImplemented(provider))
            {
                return;
            }
            List <JSONObject> feeds = new List <JSONObject>();

            foreach (var feed in feedPage.PageData)
            {
                feeds.Add(JSONObject.StringObject(feed));
            }
            JSONObject feedJson = new JSONObject(feeds.ToArray());

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaClass jniSoomlaProfile = new AndroidJavaClass("com.soomla.profile.unity.ProfileEventHandler")) {
                ProfileJNIHandler.CallStaticVoid(jniSoomlaProfile, "pushEventGetFeedFinished",
                                                 provider.ToString(), feedJson.ToString(), payload, feedPage.HasMore);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
        }
示例#12
0
        protected override void _pushEventGetContactsFinished(Provider provider, SocialPageData <UserProfile> contactsPage, string payload)
        {
            if (SoomlaProfile.IsProviderNativelyImplemented(provider))
            {
                return;
            }
            List <JSONObject> profiles = new List <JSONObject>();

            foreach (var profile in contactsPage.PageData)
            {
                profiles.Add(profile.toJSONObject());
            }
            JSONObject contacts = new JSONObject(profiles.ToArray());

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaClass jniSoomlaProfile = new AndroidJavaClass("com.soomla.profile.unity.ProfileEventHandler")) {
                ProfileJNIHandler.CallStaticVoid(jniSoomlaProfile, "pushEventGetContactsFinished",
                                                 provider.ToString(), contacts.ToString(), payload, contactsPage.HasMore);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
        }
示例#13
0
        /// <summary>
        /// See docs in <see cref="SoomlaProfile.GetScores"/>
        /// </summary>
        public void GetScores(Leaderboard owner, bool fromStart, SocialPageDataSuccess <Score> success, FailureHandler fail)
        {
            FB.API("/app/scores?fields=score,user",
                   HttpMethod.GET,
                   (IGraphResult result) => {
                if (result.Error != null)
                {
                    SoomlaUtils.LogDebug(TAG, "GetScoreCallback[result.Error]: " + result.Error);
                    fail(result.Error);
                }
                else
                {
                    SoomlaUtils.LogDebug(TAG, "GetScoreCallback[result.Text]: " + result.RawResult);
                    JSONObject jsonFeed = new JSONObject(result.RawResult);

                    SocialPageData <Score> resultData = new SocialPageData <Score>();
                    resultData.PageData   = ScoreFromFBJsonObjs(owner, jsonFeed["data"].list);
                    resultData.PageNumber = 1;
                    resultData.HasMore    = false;

                    success(resultData);
                }
            });
        }
 public GetLeaderboardsFinishedEvent(Provider provider, SocialPageData <Leaderboard> leaderboards, string payload)
     : base(provider, payload)
 {
     this.Leaderboards = leaderboards;
 }
示例#15
0
 protected virtual void _pushEventGetFeedFinished(Provider provider, SocialPageData <String> feedPage, string payload)
 {
 }
示例#16
0
 protected virtual void _pushEventGetContactsFinished(Provider provider, SocialPageData <UserProfile> contactsPage, string payload)
 {
 }
 public GetFeedFinishedEvent(Provider provider, SocialPageData <String> feedPosts) : base(provider)
 {
     this.Posts = feedPosts;
 }
 public GetScoresFinishedEvent(Provider provider, Leaderboard from, SocialPageData <Score> scores, string payload)
     : base(provider, payload)
 {
     this.From   = from;
     this.Scores = scores;
 }
 public GetContactsFinishedEvent(Provider provider, SocialPageData <UserProfile> contacts, string payLoad) : base(provider)
 {
     this.Contacts = contacts;
     this.payLoad  = payLoad;
 }