public static async Task <List <Item> > GetPocketItems(DateTime?sinceDate = null)
        {
            IEnumerable <PocketItem> items = null;

            try
            {
                items = await pocketClient.Get();
            }
            catch (PocketException ex)
            {
                if (ex.PocketErrorCode == 107) //Need to reauth
                {
                    //Todo: need to alert user that we need to reauth
                    await AuthPocket(null);

                    items = await pocketClient.Get();
                }
            }

            List <PocketItem> pocketItemsList = items.Where(p => p.Uri.ToString().Contains("youtu")).ToList();

            if (sinceDate != null)
            {
                pocketItemsList = pocketItemsList.Where(p => p.UpdateTime.Value >= sinceDate.Value.ToUniversalTime()).ToList();
            }

            return(pocketItemsList.Select(p => new Item(p)).ToList());
        }
        /// <summary>
        /// Creates and adds a few ItemViewModel objects into the Items collection.
        /// </summary>
        public async Task LoadData()
        {
            // !! please don't misuse this account !!
            PocketClient client = new PocketClient(
                consumerKey: "15396-f6f92101d72c8e270a6c9bb3",
                callbackUri: "http://frontendplay.com",
                accessCode: "80acf6c5-c198-03c0-b94c-e74402"
                );

            List <PocketSharp.Models.PocketItem> items = null;

            try
            {
                items = (await client.Get()).ToList();

                items.ForEach(item =>
                {
                    this.Items.Add(new ItemViewModel()
                    {
                        ID      = item.ID.ToString(),
                        LineOne = item.Title,
                        LineTwo = item.Uri.ToString()
                    });
                });
            }
            catch (PocketException ex)
            {
                Debug.WriteLine(ex.Message);
            }

            this.IsDataLoaded = true;
        }
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            // !! please don't misuse this account !!
            PocketClient client = new PocketClient(
                consumerKey: "15396-f6f92101d72c8e270a6c9bb3",
                callbackUri: "http://frontendplay.com",
                accessCode: "80acf6c5-c198-03c0-b94c-e74402"
                );

            List <PocketSharp.Models.PocketItem> items = null;

            try
            {
                items = await client.Get();

                items.ForEach(item =>
                {
                    Sites.Add(new Site()
                    {
                        Content = item.Title,
                        Url     = item.Uri.ToString()
                    });
                });
            }
            catch (PocketException ex)
            {
                Debug.Write(ex.Message);
            }
        }
    private async void Button_Click(object sender, RoutedEventArgs e)
    {
      // !! please don't misuse this account !!
      PocketClient client = new PocketClient(
        consumerKey: "15396-f6f92101d72c8e270a6c9bb3",
        callbackUri: "http://frontendplay.com",
        accessCode: "80acf6c5-c198-03c0-b94c-e74402"
      );

      List<PocketSharp.Models.PocketItem> items = null;

      try
      {
        items = (await client.Get()).ToList();

        items.ForEach(item =>
        {
          Sites.Add(new Site()
          {
            Content = item.Title,
            Url = item.Uri.ToString()
          });
        });
      }
      catch (PocketException ex)
      {
        Debug.Write(ex.Message);
      }
    }
    /// <summary>
    /// Creates and adds a few ItemViewModel objects into the Items collection.
    /// </summary>
    public async Task LoadData()
    {
      // !! please don't misuse this account !!
      PocketClient client = new PocketClient(
        consumerKey: "15396-f6f92101d72c8e270a6c9bb3",
        callbackUri: "http://frontendplay.com",
        accessCode: "80acf6c5-c198-03c0-b94c-e74402"
      );

      List<PocketSharp.Models.PocketItem> items = null;

      try
      {
        items = (await client.Get()).ToList();

        items.ForEach(item =>
        {
          this.Items.Add(new ItemViewModel()
          {
            ID = item.ID.ToString(),
            LineOne = item.Title,
            LineTwo = item.Uri.ToString()
          });
        });
      }
      catch (PocketException ex)
      {
        Debug.WriteLine(ex.Message);
      }

      this.IsDataLoaded = true;
    }
Exemple #6
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ExecutionContext context)
        {
            Config _config = new ConfigBuilder(context.FunctionAppDirectory).Build();

            string articleId = req.Query["articleId"];
            string userHash  = req.Query["token"];

            if (articleId == null || userHash == null)
            {
                return(new BadRequestObjectResult("no token or articleId"));
            }

            var userService = UserService.BuildUserService(_config.StorageConnectionString);
            var user        = await userService.FindUserWithToken(userHash);

            if (user == null)
            {
                return(new BadRequestObjectResult("invalid user hash"));
            }

            var pocketClient = new PocketClient(_config.PocketConsumerKey, user.AccessCode);
            var article      = await pocketClient.Get(articleId);

            if (article == null)
            {
                return(new BadRequestObjectResult("invalid article id"));
            }

            var success = await pocketClient.Favorite(article);

            //todo have html results
            return(success
                ? (ActionResult) new OkObjectResult("Archiving successful")
                : new BadRequestObjectResult("Something went wrong"));
        }
Exemple #7
0
        public static async Task <HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ExecutionContext context)
        {
            Config _config = new ConfigBuilder(context.FunctionAppDirectory).Build();

            string articleId = req.Query["articleId"];
            string userHash  = req.Query["token"];

            if (articleId == null || userHash == null)
            {
                return(new HtmlResponseMessage(HttpStatusCode.BadRequest, "no token or articleId"));
            }

            var userService = UserService.BuildUserService(_config.StorageConnectionString);
            var user        = await userService.FindUserWithToken(userHash);

            if (user == null)
            {
                return(new HtmlResponseMessage(HttpStatusCode.Unauthorized, "invalid user hash"));
            }

            var pocketClient = new PocketClient(_config.PocketConsumerKey, user.AccessCode);
            var article      = await pocketClient.Get(articleId);

            if (article == null)
            {
                return(new HtmlResponseMessage(HttpStatusCode.NotFound, "invalid article id"));
            }

            var success = await pocketClient.Favorite(article);

            return(success
                ? new HtmlResponseMessage(HttpStatusCode.OK, "Starring successful")
                : new HtmlResponseMessage(HttpStatusCode.InternalServerError, "Something went wrong"));
        }
Exemple #8
0
        public async Task LoadData()
        {
            // !! please don't misuse this account !!
            PocketClient client = new PocketClient(
                consumerKey: "15396-f6f92101d72c8e270a6c9bb3",
                callbackUri: "http://frontendplay.com",
                accessCode: "80acf6c5-c198-03c0-b94c-e74402"
                );

            List <PocketSharp.Models.PocketItem> items = null;

            try
            {
                items = (await client.Get()).ToList();
                foreach (var item in items)
                {
                    Items.Add(item);
                }
            }
            catch (PocketException ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Exemple #9
0
        public async Task <IEnumerable <PocketItem> > GetItems()
        {
            var items = await _client.Get();

            return(items.Select(i => new PocketItem(i.Uri, i.Title)).ToList());
        }