Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AchievementsPublisher"/> class.
        /// </summary>
        public AchievementsPublisher()
        {
            string appKey    = WebConfigurationManager.AppSettings["APIKey"];
            string appSecret = WebConfigurationManager.AppSettings["Secret"];
            List <Enums.ExtendedPermissions> permissions =
                new List <Enums.ExtendedPermissions> {
                Enums.ExtendedPermissions.publish_stream
            };
            CanvasSession session = new IFrameCanvasSession(appKey, appSecret, permissions, false);

            _api = new Api(session);
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AchievementsPublisher"/> class.
        /// </summary>
        public AchievementsPublisher()
        {
            string testModeValue = WebConfigurationManager.AppSettings["TestMode"] ?? true.ToString();

            _testMode = Convert.ToBoolean(testModeValue);

            string appKey    = WebConfigurationManager.AppSettings["APIKey"];
            string appSecret = WebConfigurationManager.AppSettings["Secret"];

            List <Enums.ExtendedPermissions> permissions =
                new List <Enums.ExtendedPermissions> {
                Enums.ExtendedPermissions.publish_stream
            };
            CanvasSession session = new IFrameCanvasSession(appKey, appSecret, permissions, false);

            _api = new Api(session);
        }
        public static void PostAchievements(string steamUserId)
        {
            if (steamUserId == null)
            {
                throw new ArgumentNullException("steamUserId");
            }

            string appKey    = WebConfigurationManager.AppSettings["APIKey"];
            string appSecret = WebConfigurationManager.AppSettings["Secret"];
            List <Enums.ExtendedPermissions> permissions =
                new List <Enums.ExtendedPermissions> {
                Enums.ExtendedPermissions.publish_stream
            };
            IFrameCanvasSession session = new IFrameCanvasSession(appKey, appSecret, permissions);
            Api api = new Api(session);

            AchievementManager        manager            = new AchievementManager();
            IEnumerable <Achievement> latestAchievements = manager.GetLatestAchievements(steamUserId);

            foreach (Achievement achievement in latestAchievements)
            {
                string description = String.Format("earned the {0} achievement in {1}.", achievement.Name,
                                                   achievement.Game.Name);
                attachment attachment = new attachment
                {
                    caption = achievement.Description,
                    name    = achievement.Name,
                    href    = String.Format("http://steamcommunity.com/id/{0}/stats/{1}",
                                            steamUserId, achievement.Game.Abbreviation),
                    media = new List <attachment_media>
                    {
                        new attachment_media_image
                        {
                            src  = achievement.ImageUrl,
                            href =
                                String.Format(
                                    "http://steamcommunity.com/id/{0}/stats/{1}?tab=achievements",
                                    steamUserId, achievement.Game.Abbreviation)
                        }
                    }
                };

                api.Stream.Publish(description, attachment, null, null, 0);
            }
        }
Пример #4
0
        public override void OnActionExecuting(ActionExecutingContext c)
        {
            CanvasSession session = null;

            if (IsFbml)
            {
                if (!string.IsNullOrEmpty(RequiredPermissions))
                {
                    session = new FBMLCanvasSession(ApiKey ?? WebConfigurationManager.AppSettings["ApiKey"], Secret ?? WebConfigurationManager.AppSettings["Secret"], ParsePermissions(RequiredPermissions));
                }
                else
                {
                    session = new FBMLCanvasSession(ApiKey ?? WebConfigurationManager.AppSettings["ApiKey"], Secret ?? WebConfigurationManager.AppSettings["Secret"]);
                }
            }
            else
            {
                c.HttpContext.Response.AppendHeader("p3p", "CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"");

                if (!string.IsNullOrEmpty(RequiredPermissions))
                {
                    session = new IFrameCanvasSession(ApiKey ?? WebConfigurationManager.AppSettings["ApiKey"], Secret ?? WebConfigurationManager.AppSettings["Secret"], ParsePermissions(RequiredPermissions), c.Controller.ControllerContext.HttpContext.Session.Contents);
                }
                else
                {
                    session = new IFrameCanvasSession(ApiKey ?? WebConfigurationManager.AppSettings["ApiKey"], Secret ?? WebConfigurationManager.AppSettings["Secret"], c.Controller.ControllerContext.HttpContext.Session.Contents);
                }
            }
            if (string.IsNullOrEmpty(session.SessionKey))
            {
                c.Result = new ContentResult {
                    Content = session.GetRedirect()
                };
            }
            else
            {
                var permissionsString = session.CheckPermissions();
                if (!string.IsNullOrEmpty(permissionsString))
                {
                    c.Result = new ContentResult {
                        Content = session.GetPermissionsRedirect(session.GetPermissionUrl(permissionsString, session.GetNextUrl()))
                    };
                }
            }
        }
Пример #5
0
        public override void OnActionExecuting(ActionExecutingContext c)
        {
            CanvasSession session = null;

            if (IsFbml)
            {
                if (!string.IsNullOrEmpty(RequiredPermissions))
                {
                    session = new FBMLCanvasSession(ApiKey ?? WebConfigurationManager.AppSettings["ApiKey"], Secret ?? WebConfigurationManager.AppSettings["Secret"], ParsePermissions(RequiredPermissions));
                }
                else
                {
                    session = new FBMLCanvasSession(ApiKey ?? WebConfigurationManager.AppSettings["ApiKey"], Secret ?? WebConfigurationManager.AppSettings["Secret"]);
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(RequiredPermissions))
                {
                    session = new IFrameCanvasSession(ApiKey ?? WebConfigurationManager.AppSettings["ApiKey"], Secret ?? WebConfigurationManager.AppSettings["Secret"], ParsePermissions(RequiredPermissions));
                }
                else
                {
                    session = new IFrameCanvasSession(ApiKey ?? WebConfigurationManager.AppSettings["ApiKey"], Secret ?? WebConfigurationManager.AppSettings["Secret"]);
                }
            }
            if (string.IsNullOrEmpty(session.SessionKey))
            {
                c.Result = new ContentResult {
                    Content = session.GetRedirect()
                };
            }
            else
            {
                var permissionsString = session.CheckPermissions();
                if (!string.IsNullOrEmpty(permissionsString))
                {
                    c.Result = new ContentResult {
                        Content = session.GetPermissionsRedirect(session.GetPermissionUrl(permissionsString, session.GetNextUrl()))
                    };
                }
            }
        }
Пример #6
0
        public static Api GetApiIFrame(this Controller controller)
        {
            IFrameCanvasSession session = new IFrameCanvasSession(WebConfigurationManager.AppSettings["ApiKey"], WebConfigurationManager.AppSettings["Secret"], controller.ControllerContext.HttpContext.Session.Contents);

            return(new Api(session));
        }