Пример #1
0
        public void Share()
        {
            if (CanShare()) return;

            var leaderboardInfo = new LeaderboardInfo
            {
                TwitterHandle = _twitterShareService.GetUserProfile().ScreenName,
                Score = _productivityService.Score,
                Language = _productivityService.Language,
                LastTranslationAt = _productivityService.LastTranslationDate.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'"),
                AppVersion = _versioningService.PluginVersion
            };

            var isSharedOnTheLeaderboard = _leaderboardShareService.ShareOnLeaderboard(leaderboardInfo);

            if (isSharedOnTheLeaderboard)
            {

            #if !DEBUG
                {
                    _twitterShareService.ShareOnTwitter(leaderboardInfo);
                }
            #endif

            }
        }
        public bool ShareOnLeaderboard(LeaderboardInfo leaderboardInfo)
        {
            var request = new RestRequest(Method.POST) { Resource = "entries", RequestFormat = DataFormat.Json };
            request.Parameters.AddRange(CreateParameters(leaderboardInfo));

            return _leaderboardApi.ExecuteWithoutResponse(request);
        }
Пример #3
0
 public void ShareOnTwitter(LeaderboardInfo leaderboardInfo)
 {
     if (!_authenticated) return;
     var tweetOptions = new SendTweetOptions
     {
         Status = _tweetMessageService.GetTwitterMessage(leaderboardInfo.Score)
     };
     _twitterService.SendTweet(tweetOptions);
 }
        private IEnumerable<Parameter> CreateParameters(LeaderboardInfo leaderboardInfo)
        {
            var result = new List<Parameter>();
            if (leaderboardInfo == null) return result;

            result.Add(new Parameter
            {
                Name = "twitterHandle",
                Type = ParameterType.GetOrPost,
                Value = leaderboardInfo.TwitterHandle
            });
            result.Add(new Parameter
            {
                Name = "score",
                Type = ParameterType.GetOrPost,
                Value = leaderboardInfo.Score
            });
            result.Add(new Parameter
            {
                Name = "language",
                Type = ParameterType.GetOrPost,
                Value = leaderboardInfo.Language
            });
            result.Add(new Parameter
            {
                Name = "lastTranslationAt",
                Type = ParameterType.GetOrPost,
                Value = leaderboardInfo.LastTranslationAt
            });
            result.Add(new Parameter
            {
                Name = "appVersion",
                Type = ParameterType.GetOrPost,
                Value = leaderboardInfo.AppVersion
            });

            result.Add(new Parameter
            {
                Name = "accessToken",
                Type = ParameterType.GetOrPost,
                Value = _twitterAccountInfo.AccessToken
            });
            result.Add(new Parameter
            {
                Name = "accessTokenSecret",
                Type = ParameterType.GetOrPost,
                Value = _twitterAccountInfo.AccessTokenSecret
            });

            return result;
        }