Esempio n. 1
0
        /// <summary>
        /// Default ctor
        /// </summary>
        internal AirportStatus(JSONObject source)
        {
            Delay = source.GetBoolean("delay");
            IataCode = source.GetString("IATA");
            State= source.GetString("state");
            City = source.GetString("city");
            Name = source.GetString("name");

            var weather = source.GetJSONObject("weather");
            Temperature = weather.GetString("temp");
            Wind = weather.GetString("wind");
        }
Esempio n. 2
0
        private Weather CallbackResponse(string responseObj)
        {
            Weather weather = null;


            Org.Json.JSONObject weatherMain = new Org.Json.JSONObject(responseObj);

            Org.Json.JSONArray weatherArray = new Org.Json.JSONArray();
            weatherArray.Put(weatherMain);


            for (int i = 0; i < weatherArray.Length(); i++)
            {
                try
                {
                    Org.Json.JSONObject weatherObject = weatherArray.GetJSONObject(i);

                    JSONObject objectLocation = weatherObject.GetJSONObject("location");
                    JSONObject objectCurrent  = weatherObject.GetJSONObject("current");

                    //JSONObject objectrequest = objectCurrent.GetJSONObject("request");
                    //"request":{ "type":"City","query":"Tel Aviv-Yafo, Israel","language":"en","unit":"m"}

                    weather = new Weather();

                    weather.setTemperature(objectCurrent.GetString("temperature"));
                    weather.setDescription(objectCurrent.GetString("weather_descriptions"));
                    weather.setWind_kph(objectCurrent.GetString("wind_speed"));
                    string icon = objectCurrent.GetString("weather_icons");
                    icon = icon.Replace("[\"" + "https:\\/\\/assets", @"https://assets");
                    icon = icon.Replace("[", "");
                    icon = icon.Replace("]", "");
                    icon = icon.Replace("\"", "");
                    icon = icon.Replace(@"\/", "//");
                    icon = icon.Replace(@"\\", "//");
                    //Android.Net.Uri uri = Android.Net.Uri.Parse(icon);
                    //Android.Net.Uri uri = Android.Net.Uri.Parse(icon);
                    //icon = uri.Path;
                    //icon = uri.AbsolutePath;
                    weather.setPoster(icon);
                    weather.setIs_day(objectCurrent.GetString("is_day").ToString());
                    weather.setCloud(objectCurrent.GetString("cloudcover"));

                    weather.setLast_update(objectLocation.GetString("localtime"));
                    weather.setCountry(objectLocation.GetString("country"));
                    icon = objectLocation.GetString("name").Trim();
                    icon = icon.Replace(@"[", "");
                    icon = icon.Replace("[", "");
                    icon = icon.Replace(@"]", "");
                    icon = icon.Replace("]", "");
                    icon = icon.Replace("\"", "");
                    icon = icon.Replace("\"", "");
                    icon = icon.Replace("[\"", "");
                    //icon = icon.Replace('\'', (char)32);
                    weather.setCity(icon.Trim());         // "type":"City","query":"Tel Aviv-Yafo, Israel"
                    weather.setRegion(objectLocation.GetString("region"));
                    weather.setLocal_time(objectLocation.GetString("localtime"));
                    weather.setTz_id(objectLocation.GetString("timezone_id"));

                    //"localtime_epoch":1583177400,"utc_offset":"2.0"
                    //wind_degree":311,"wind_dir":"NW","pressure":1021,"precip":0,"humidity":60,"cloudcover":7,"feelslike":17

                    try
                    {
                        //weather.setImageView(Utils.GetImageViewFromhUrl(weather.getPoster()));
                        //weather.setImageView(new ImageView(Application.Context));
                        //Android.Net.Uri uri = Android.Net.Uri.Parse(weather.getPoster());
                        //weather.getImageView().SetImageURI(uri);
                    }
                    catch
                    {
                    }

                    if (WeatherList.Count < 4)
                    {
                        WeatherList.Add(weather);
                    }
                    else
                    {
                        WeatherList[currentListIndex] = weather;
                    }
                }
                catch (JSONException ex)
                {
                    MH_Utils.Utils.WriteToLog(ex.Message);
                    //Log.d("Error: ", ex.getMessage());
                    //ex.printStackTrace();
                }
            }


            return(weather);
        }
        public void GetCurrentPlayer(Action<CurrentPlayer> callback)
        {
            var client = new RestClient("http://webmat.cs.aau.dk/api/");

            var request = new RestRequest(Method.POST);

            request.AddParameter("action", "get_current_user");
            request.AddParameter("token", token);

            string data;

            try
            {
                data = client.Execute(request).Content;
            }
            catch (TimeoutException)
            {
                GetCurrentPlayer(callback);
                return;
            }

            JSONObject json = new JSONObject(data);
            JSONObject jsonData = json.GetJSONObject("data");
            CurrentPlayer currentPlayer = new CurrentPlayer(jsonData.GetString("name"));
            var badges = jsonData.GetJSONArray("badges");
            for (int index = 0; index < badges.Length(); index++)
            {
                string badgeString = badges.GetString(index);
                if (badgeString != "")
                {
                    currentPlayer.Badges.Add((BadgeName)int.Parse(badgeString));
                }
            }
            getCategories((categories) =>
            {
                foreach (LevelCategory category in categories)
                {
                    currentPlayer.AddCategory(category);
                }
                callback(currentPlayer);
            });
            callback(currentPlayer);

        }
        public void Authenticate(string username, string password, Action<bool> callback)
        {
            var client = new RestClient("http://webmat.cs.aau.dk/api/");

            var request = new RestRequest(Method.POST);

            request.AddParameter("action", "user_login");
            request.AddParameter("username", username);
            request.AddParameter("password", password);

            string data;

            try
            {
                data = client.Execute(request).Content;
            }
            catch (TimeoutException)
            {
                Authenticate(username, password, callback);
                return;
            }

            JSONObject json = new JSONObject(data);
            bool success = json.GetString("success") == "true";
            if (success)
            {
                token = json.GetJSONObject("data").GetString("token");
            }
            callback(success);
        }
        public void IsAuthenticated(Action<bool> callback)
        {
            var client = new RestClient("http://webmat.cs.aau.dk/api/");

            var request = new RestRequest(Method.POST);

            request.AddParameter("action", "is_authenticated");

            string data;

            try
            {
                data = client.Execute(request).Content;
            }
            catch (TimeoutException)
            {
                IsAuthenticated(callback);
                return;
            }

            Console.WriteLine(data);
            JSONObject json = new JSONObject(data);
            bool success = json.GetString("success") == "true";
            if(success)
            {
                token = json.GetJSONObject("data").GetString("token");
            }
            callback(success);
        }
Esempio n. 6
0
        public String[] getUserDeets(String token)
        {
            Console.WriteLine ("into the belly of it m8");
            String output = httpRequest(token,"https://www.yammer.com/api/v1/users/current.json");
            Console.WriteLine ("we dun it now");
            if (output != "") {

                //JSONArray jObject = new JSONArray (output); // json
                String[] details;

                JSONObject data, tmp;
                //String[] items;
                String uid, fname, lname, email, phone = "", org, profilepicture;
                //maybe use less memory because im using heaps apparently

                data = new JSONObject (output); // get data object

                uid = data.GetString ("id");
                fname = data.GetString ("first_name");
                lname = data.GetString ("last_name");
                email = data.GetString ("email");
                profilepicture = data.GetString ("mugshot_url_template");
                profilepicture = profilepicture.Replace ("{width}x{height}", "300x300");

                tmp = data.GetJSONObject ("contact");
                phone = tmp.GetString ("phone_numbers");

                try {
                    tmp = new JSONArray (phone).GetJSONObject (0);
                    phone = tmp.GetString ("number");
                } catch {
                    phone = "";
                }

                org = data.GetString ("network_name");

                details = new String[] { fname, lname, email, phone, org, uid, profilepicture };
                tmp.Dispose ();
                data.Dispose ();

                fname = "";
                lname = "";
                email = "";
                phone = "";
                org = "";
                uid = "";
                profilepicture = "";

                //jObject.Dispose ();

                return details;

            }
            String[] gg = null;
            return gg;
        }
Esempio n. 7
0
        private void getWeatherDataFromJson(String forecastJsonStr, String locationSetting)
        {
            // These are the names of the JSON objects that need to be extracted.
            // Location information
            const string OWM_CITY = "city";
            const string OWM_CITY_NAME = "name";
            const string OWM_COORD = "coord";

            const string OWM_LATITUDE = "lat";
            const string OWM_LONGITUDE = "lon";

            const string OWM_LIST = "list";

            const string OWM_PRESSURE = "pressure";
            const string OWM_HUMIDITY = "humidity";
            const string OWM_WINDSPEED = "speed";
            const string OWM_WIND_DIRECTION = "deg";

            const string OWM_TEMPERATURE = "temp";
            const string OWM_MAX = "max";
            const string OWM_MIN = "min";

            const string OWM_WEATHER = "weather";
            const string OWM_DESCRIPTION = "main";
            const string OWM_WEATHER_id = "id";

            try {
                JSONObject forecastJson = new JSONObject (forecastJsonStr);
                JSONArray weatherArray = forecastJson.GetJSONArray (OWM_LIST);

                JSONObject cityJson = forecastJson.GetJSONObject (OWM_CITY);
                String cityName = cityJson.GetString (OWM_CITY_NAME);

                JSONObject cityCoord = cityJson.GetJSONObject (OWM_COORD);
                double cityLatitude = cityCoord.GetDouble (OWM_LATITUDE);
                double cityLongitude = cityCoord.GetDouble (OWM_LONGITUDE);

                long locationId = AddLocation (locationSetting, cityName, cityLatitude, cityLongitude);

                ArrayList jsonResultValues = new ArrayList ();

                DateTime dayTime = DateTime.UtcNow;

                for (int i = 0; i < weatherArray.Length (); i++) {
                    // These are the values that will be collected.
                    long dateTime;
                    double pressure;
                    int humidity;
                    double windSpeed;
                    double windDirection;

                    double high;
                    double low;

                    string description;
                    int weatherId;

                    // Get the JSON object representing the day
                    JSONObject dayForecast = weatherArray.GetJSONObject (i);

                    // The date/time is returned as a long.  We need to convert that
                    // into something human-readable, since most people won't read "1400356800" as
                    // "this saturday".
                    // Cheating to convert this to UTC time, which is what we want anyhow
                    dateTime = dayTime.AddDays (i).Ticks;

                    pressure = dayForecast.GetDouble (OWM_PRESSURE);
                    humidity = dayForecast.GetInt (OWM_HUMIDITY);
                    windSpeed = dayForecast.GetDouble (OWM_WINDSPEED);
                    windDirection = dayForecast.GetDouble (OWM_WIND_DIRECTION);

                    // Description is in a child array called "weather", which is 1 element long.
                    // That element also contains a weather code.
                    JSONObject weatherObject =
                        dayForecast.GetJSONArray (OWM_WEATHER).GetJSONObject (0);
                    description = weatherObject.GetString (OWM_DESCRIPTION);
                    weatherId = weatherObject.GetInt (OWM_WEATHER_id);

                    // Temperatures are in a child object called "temp".  Try not to name variables
                    // "temp" when working with temperature.  It confuses everybody.
                    JSONObject temperatureObject = dayForecast.GetJSONObject (OWM_TEMPERATURE);
                    high = temperatureObject.GetDouble (OWM_MAX);
                    low = temperatureObject.GetDouble (OWM_MIN);

                    ContentValues weatherValues = new ContentValues ();

                    weatherValues.Put (WeatherContractOpen.WeatherEntryOpen.COLUMN_LOC_KEY, locationId);
                    weatherValues.Put (WeatherContractOpen.WeatherEntryOpen.COLUMN_DATE, dateTime);
                    weatherValues.Put (WeatherContractOpen.WeatherEntryOpen.COLUMN_HUMIDITY, humidity);
                    weatherValues.Put (WeatherContractOpen.WeatherEntryOpen.COLUMN_PRESSURE, pressure);
                    weatherValues.Put (WeatherContractOpen.WeatherEntryOpen.COLUMN_WIND_SPEED, windSpeed);
                    weatherValues.Put (WeatherContractOpen.WeatherEntryOpen.COLUMN_DEGREES, windDirection);
                    weatherValues.Put (WeatherContractOpen.WeatherEntryOpen.COLUMN_MAX_TEMP, high);
                    weatherValues.Put (WeatherContractOpen.WeatherEntryOpen.COLUMN_MIN_TEMP, low);
                    weatherValues.Put (WeatherContractOpen.WeatherEntryOpen.COLUMN_SHORT_DESC, description);
                    weatherValues.Put (WeatherContractOpen.WeatherEntryOpen.COLUMN_WEATHER_id, weatherId);

                    jsonResultValues.Add (weatherValues);
                }
                BulkInsertWeather (jsonResultValues, locationSetting);

            } catch (Exception ex) {
                Log.Error ("Featch Weather Task", ex.Message);
            }
        }