Esempio n. 1
0
        public async Task<HttpResponseMessage> Get(string userName)
        {
            //async await to be completed
            var statuses = await _twitterService.GetUserTimelineData(userName);

            //now google maps
            //for now just workout link
            MemoryStream ms = null;

            HttpResponseMessage response;

            foreach (var status in statuses)
            {
                var mapLoc = userName + ".png";

                if (!string.IsNullOrWhiteSpace((string) status["place"]))
                {
                    await _googleService.SaveMap(Properties.Settings.Default.StaticGoogleMapApi, userName);
                }
                else
                {
                    await _googleService.SaveMap(userName);
                }
                
                var map = Image.FromFile(mapLoc);
                var mapData = _generalService.ImageToByteArray(map);
                ms = new MemoryStream(mapData);
            }
            
            //save user to 'database' just an xml file
            if (ms != null)
            {
                response = new HttpResponseMessage(HttpStatusCode.OK) {Content = new StreamContent(ms)};
                response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/png");
                var apiResponse = new MemoryStream(_generalService.GetBytes(statuses.ToString()));
                response.Content = new StreamContent(apiResponse);

                return response;
            }
            var message = _generalService.GetBytes("The Map file was not found");
            ms = new MemoryStream(message);
            response = new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StreamContent(ms) };
            
            return response;
        }