private static void ProcessNotifications <T>(FoursquareResponse <T> response)
            where T : IFoursquareType
        {
            if (response?.notifications == null)
            {
                return;
            }

            foreach (var notif in response.notifications)
            {
                switch (notif.type)
                {
                case "pendingFriendRequests":
                    break;

                case "notificationTray":
                    break;

                case "plans":
                    break;

                default:
                    break;
                }
            }
        }
        public async Task <string> GetFoursquareCheckin(Xamarin.Essentials.Location cor)
        {
            HttpResponseMessage foursquareResponse = new HttpResponseMessage();

            foursquareResponse = await client.GetAsync(" https://api.foursquare.com/v2/venues/search?client_id=VFAATN22EINFZGCHWKOQCUPOE0U3XIU4LL44DCQ2KWBA3JFV%20&client_secret=NL1XOSKNPJTNNQK3JPVVXHGS2AG4PM014AONQVSF2NGTX20V&ll=" + cor.Latitude + "," + cor.Longitude + "&&v=20190418");

            if (foursquareResponse.IsSuccessStatusCode)

            {
                string content = await foursquareResponse.Content.ReadAsStringAsync();

                FoursquareResponse fResponse = new FoursquareResponse();
                fResponse = JsonConvert.DeserializeObject <FoursquareResponse>(content);
                List <Venue> venues;
                string       CurrentVenue;

                venues = new List <Venue>();
                if (fResponse.response.venues.Count != 0)
                {
                    venues       = fResponse.response.venues.OrderBy(o => o.location.distance).ToList();
                    CurrentVenue = venues[0].name;
                    return(CurrentVenue);
                }
            }

            return(null);
        }
示例#3
0
        protected FoursquareResponse <T> ParseResponse <T>(JToken root) where T : IFoursquareType
        {
            FoursquareResponse <T> output = new FoursquareResponse <T>();

            if (root["meta"] != null)
            {
                output.meta = root["meta"].ToObject <Meta>();
            }

            if (root["notifications"] != null)
            {
                output.notifications = root["notifications"].ToObject <List <Notifications> >();
            }

            JToken response = root["response"];

            if (response != null)
            {
                output.response = response.ToObject <T>();
            }

            if (root["access_token"] != null)
            {
                output.response = root.ToObject <T>();
            }

            return(output);
        }
示例#4
0
        private bool CheckMeta <T>(string url, FoursquareResponse <T> response)
        {
            if (response.Meta.Code == 200)
            {
                return(true);
            }

            _logger.Error($"Foursquare request failed on url={{{url}}}: {response.Meta.ErrorType}. {response.Meta.ErrorDetail}");

            return(false);
        }
        public async Task <FoursquareResponse <T> > MakeRequest <T>(CancellationToken?cancellationToken = null) where T : IFoursquareType
        {
            try
            {
                if (cancellationToken == null)
                {
                    cancellationToken = _cancellationToken.Token;
                }

                FoursquareResponse <T> parsedResponse;
                HttpResponseMessage    responseMessage;
                switch (Method)
                {
                case HttpMethod.GET:
                    Debug.WriteLine(GetFullUrl());
                    responseMessage = await GetClient().GetAsync(GetFullUrl(), cancellationToken.Value).ConfigureAwait(false);

                    break;

                case HttpMethod.POST:
                    Debug.WriteLine(GetFullUrl());
                    responseMessage = await GetClient().PostAsync(Url, GetPostContent(), cancellationToken.Value).ConfigureAwait(false);

                    break;

                case HttpMethod.PHOTO_POST:
                    MultipartFormDataContent content   = new MultipartFormDataContent();
                    StreamContent            baContent = new StreamContent(File);
                    baContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/jpeg");
                    content.Add(baContent, "image", "image.jpeg");
                    responseMessage = await GetClient().PostAsync(GetFullUrl(), content, cancellationToken.Value).ConfigureAwait(false);

                    break;

                default:
                    throw new Exception("Unsupported HttpMethod type");
                }
                HandleHttpResponseMessage(responseMessage);
                string respString = await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);

                if (!string.IsNullOrEmpty(respString))
                {
                    parsedResponse = JsonConvert.DeserializeObject <FoursquareResponse <T> >(respString, new FoursquareResponseConverter <T>());
                }
                else
                {
                    throw new FoursquareNetworkException(FoursquareNetworkException.NetworkError.NoData);
                }
                ProcessNotifications(parsedResponse);
                return(parsedResponse);
            }
            catch (Exception e)
            {
                Debug.WriteLine("Network exception: " + e.Message);
                var response = new FoursquareResponse <T>
                {
                    Exception = e
                };
                return(response);
            }
        }