Exemplo n.º 1
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 */ () => {
                    ProfileEvents.OnSocialActionFinished(provider, SocialActionType.UPDATE_STATUS, userPayload);
                    if (reward != null)
                    {
                        reward.Give();
                    }
                },
                                            /* fail */ (string error) => { ProfileEvents.OnSocialActionFailed(provider, SocialActionType.UPDATE_STATUS, error, userPayload); }
                                            );
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Uploads an image to the user's social page on the given Provider with confirmation dialog.
        /// 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>
        /// <param name="customMessage">The message to show in the dialog</param>
        public static void UploadImageWithConfirmation(Provider provider, string message, string fileName, byte[] imageBytes,
                                                       int jpegQuality, string payload = "", Reward reward = null, string customMessage = 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(), true, customMessage);
            }

            else
            {
                // TODO: Support showConfirmation
                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); }
                                           );
            }
        }
        /// <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); }
                                       );
        }
Exemplo n.º 4
0
        /// <summary>
        /// Handles an <c>onSocialActionFinished</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 onSocialActionFinished(String message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onSocialActionFinished");

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

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

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

            ProfileEvents.OnSocialActionFinished(provider, socialAction, ProfilePayload.GetUserPayload(payloadJSON));
        }
Exemplo n.º 5
0
        /// <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;
            }

            if (targetProvider.IsNativelyImplemented())
            {
                //fallback to native
                string rewardId = reward != null ? reward.ID: "";
                instance._updateStory(provider, message, name, caption, description, link, pictureUrl,
                                      ProfilePayload.ToJSONObj(userPayload, rewardId).ToString(), true, customMessage);
            }

            else
            {
                // 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); }
                                           );
            }
        }
Exemplo n.º 6
0
//		public static void UploadImage(Provider provider, string message, string filename,
//		                               byte[] imageBytes, int quality, Reward reward) {
//			instance._uploadImage(provider, message, filename, imageBytes, quality, reward);
//		}
//

        /// <summary>
        /// Uploads an image to the user's social page on the given Provider.
        /// Supported platforms: Facebook
        ///
        /// 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="tex2D">Texture2D for image.</param>
        /// <param name="fileName">Name of image file.</param>
        /// <param name="message">Message to post with the image.</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 upload.</param>
        public static void UploadImage(Provider provider, Texture2D tex2D, string fileName, string message, string payload = "",
                                       Reward reward = null)
        {
            SocialProvider targetProvider = GetSocialProvider(provider);
            string         userPayload    = (payload == null) ? "" : payload;

            if (targetProvider == null)
            {
                return;
            }

            if (targetProvider.IsNativelyImplemented())
            {
                //fallback to native
                ProfileEvents.OnSocialActionFailed(provider,
                                                   SocialActionType.UPLOAD_IMAGE,
                                                   "Image uploading is not supported with Texture for natively implemented social providers",
                                                   userPayload);
            }

            else
            {
                ProfileEvents.OnSocialActionStarted(provider, SocialActionType.UPLOAD_IMAGE, userPayload);
                targetProvider.UploadImage(tex2D.EncodeToPNG(), fileName, message,
                                           /* success */ () => {
                    ProfileEvents.OnSocialActionFinished(provider, SocialActionType.UPLOAD_IMAGE, userPayload);
                    if (reward != null)
                    {
                        reward.Give();
                    }
                },
                                           /* fail */ (string error) => { ProfileEvents.OnSocialActionFailed(provider, SocialActionType.UPLOAD_IMAGE, error, userPayload); },
                                           /* cancel */ () => { ProfileEvents.OnSocialActionCancelled(provider, SocialActionType.UPLOAD_IMAGE, userPayload); }
                                           );
            }
        }