Ejemplo n.º 1
0
        public ActionResult Post(string mediaID)
        {
            /* No current session could be found, back to the homepage. */
            if (this.Session["CurrentSession"] == null)
            {
                return(RedirectToAction("Index"));
            }

            /* Access the current InstagramSession and fetch all media. */
            InstagramSession      currentSession = (InstagramSession)this.Session["CurrentSession"];
            IList <InstagramPost> recentMedia    = currentSession.GetMedia();

            /* Search for the specific post mentioned in 'mediaID' */
            foreach (InstagramPost post in recentMedia)
            {
                /* Post has been found */
                if (post.ID == mediaID)
                {
                    /* Fetch the comments of post in discussion,
                     * create a ViewModel and return it. */
                    IList <InstagramComment> comments  = currentSession.GetComments(mediaID);
                    PostViewModel            viewModel = new PostViewModel {
                        Post = post, Comments = comments
                    };
                    return(View(viewModel));
                }
            }

            /* No media matching specified mediaID has been found */
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        // GET: Instagram/Access

        /* The Access action is the redirect configured in Instagram API's settings.
         * Once authentication has been succesful, the user is redirected here, with
         * a code parameter that must be exchanged for the access_token. In case of
         * denial by user, the 'error' parameter will contain a value. */
        public ActionResult Access(string code, string error)
        {
            /* Either user has denied access or
             * there is no code parameter present. */
            if (error != null || code == null)
            {
                return(RedirectToAction("Index"));
            }

            /* Extract authentication data necessary for communication with Instagram servers.
             * Initialize an instance of InstagramSession, the class that handles communication
             * with the API. */
            string           clientID       = ConfigurationManager.AppSettings["Instagram.ClientID"];
            string           clientSecret   = ConfigurationManager.AppSettings["Instagram.ClientSecret"];
            string           redirectURL    = WebConfigurationManager.AppSettings["Instagram.RedirectUrl"];
            InstagramSession currentSession = new InstagramSession(clientID, clientSecret, redirectURL, code);

            /* Authentication succesful, access token has been retrieved.
             * Store current InstagramSession and redirect to 'Media'
             * controller for the purpose of fetching and displaying data. */
            if (currentSession.RequestAccesToken())
            {
                this.Session["CurrentSession"] = currentSession;
                return(RedirectToAction("Media"));
            }

            /* Authentication failed, back to homepage. */
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
        // GET: Instagram/Media

        /* Returns latest media of currently authenticated user. The InstagramSession
         * object for the current session is preserved through .NET Session State.
         * */
        public ActionResult Media()
        {
            /* No current session could be found, back to the homepage. */
            if (this.Session["CurrentSession"] == null)
            {
                return(RedirectToAction("Index"));
            }

            /* Access the current InstagramSession and fetch user data/media. */
            InstagramSession      currentSession = (InstagramSession)this.Session["CurrentSession"];
            IList <InstagramPost> recentMedia    = currentSession.GetMedia();
            InstagramUser         currentUser    = currentSession.GetUser();

            /* Wrap the user and media into a single model and pass
             * that to the view for displaying purposes. */
            MediaViewModel viewModel = new MediaViewModel {
                User = currentUser, Media = recentMedia
            };

            return(View(viewModel));
        }
 public MainWindowViewModel()
 {
     Session = new InstagramSession();
 }