/// <summary>
        /// Retrieves the list of recent checkins.
        /// </summary>
        private async Task GetRecentCheckinsAsync()
        {
            _currentListViewMode = ListViewMode.MyCheckins;
            bool accessDenied = false;

            if (_checkinsCache == null)
            {
                Title.Text = "Getting Checkins...";
                var resourceUri = String.Format("https://api.foursquare.com/v2/users/self/checkins?limit={0}&v={1}",
                                                Settings.QueryLimit,
                                                Constants.ApiVerifiedDate);

                try
                {
                    HttpResponseMessage response = await _httpClient.GetAsync(new Uri(resourceUri));

                    switch (response.StatusCode)
                    {
                    case HttpStatusCode.Ok:
                        var responseBodyAsText = await response.Content.ReadAsStringAsync();

                        var responseBodyAsJson = JsonObject.Parse(responseBodyAsText);
                        _checkinsCache = Checkin.ListFromJson(responseBodyAsJson["response"].GetObject());
                        break;

                    case HttpStatusCode.Unauthorized:     // token was revoked
                        Logger.Trace(TraceLevel.Error, "User disconnected this app from the Foursquare Settings page: " + response.StatusCode.ToString());
                        accessDenied = true;
                        break;

                    default:
                        Logger.Trace(TraceLevel.Error, "Failed to get checkins from Foursquare: " + response.StatusCode.ToString());
                        break;
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    accessDenied = true;
                }
            }

            if (accessDenied)
            {
                Logger.Trace(TraceLevel.Info, "Access denied, deleting state.");
                await DeleteStateAsync();
            }

            if (_checkinsCache != null)
            {
                Title.Text = _checkinsCache.Count + " Latest Checkins";
                ItemsListView.ItemsSource = _checkinsCache;
            }
            else
            {
                Title.Text = "Checkins Unavailable";
            }
        }
Пример #2
0
        public static Checkin FromJson(JsonObject json)
        {
            var c = new Checkin();

            c.UtcTimestamp = new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds((long)json["createdAt"].GetNumber());
            c.Venue        = Venue.FromJson(json["venue"].GetObject());

            return(c);
        }
Пример #3
0
        public static List <Checkin> ListFromJson(JsonObject json)
        {
            var items  = json["checkins"].GetObject()["items"].GetArray();
            var result = new List <Checkin>();

            foreach (var item in items)
            {
                try
                {
                    var v = Checkin.FromJson(item.GetObject());
                    result.Add(v);
                }
                catch (KeyNotFoundException)
                {
                    // If key not found, skip the item
                    Logger.Trace(TraceLevel.Warn, "Skipping checkin because of missing key");
                }
            }
            return(result);
        }