Exemplo n.º 1
0
        public DataLayer.ImgurUser jsonToUser(Windows.Data.Json.JsonObject json)
        {
            DataLayer.ImgurUser _usr;
            //----------------------------

            _usr = new DataLayer.ImgurUser();
            _usr.Id = (int)(json.GetNamedArray("data").GetNumberAt (0));
            _usr.Url = json.GetNamedArray("data").GetStringAt(1);
            _usr.Bio = json.GetNamedArray("data").GetStringAt(2);
            _usr.Rep = (float) json.GetNamedArray("data").GetNumberAt(3);
            _usr.Created = (int)json.GetNamedArray("data").GetNumberAt(4);
            _usr.Pro = (int)json.GetNamedArray("data").GetNumberAt(5);

            // return user
            return _usr;
        }
Exemplo n.º 2
0
        public DataLayer.ImgurUser jsonToUser(Windows.Data.Json.JsonObject json)
        {
            DataLayer.ImgurUser _usr;
            //----------------------------

            _usr         = new DataLayer.ImgurUser();
            _usr.Id      = (int)(json.GetNamedArray("data").GetNumberAt(0));
            _usr.Url     = json.GetNamedArray("data").GetStringAt(1);
            _usr.Bio     = json.GetNamedArray("data").GetStringAt(2);
            _usr.Rep     = (float)json.GetNamedArray("data").GetNumberAt(3);
            _usr.Created = (int)json.GetNamedArray("data").GetNumberAt(4);
            _usr.Pro     = (int)json.GetNamedArray("data").GetNumberAt(5);


            // return user
            return(_usr);
        }
Exemplo n.º 3
0
        public DataLayer.ImgurUser logIn(string username, String OAuth = null)
        {
            DataLayer.ImgurUser user;
            //------------------------

            HttpClient client = GetHttpClient(OAuth);

            string URI = BaseURL;
            URI += "account/" + username + ".json";
           
            var jsonStr = client.GetStringAsync(URI).Result;
            JsonObject json = new JsonObject();
            JsonObject.TryParse(jsonStr, out json);

            //TODO: Process JSON
            user = new DataLayer.ImgurUser();
            BuisnessLayer.JSONProcessor jproc = new BuisnessLayer.JSONProcessor();
            user = jproc.jsonToUser(json);

            // return logged in user:
            return user;
        }
Exemplo n.º 4
0
        public DataLayer.ImgurUser jsonToUser(Windows.Data.Json.JsonObject json)
        {
            DataLayer.ImgurUser _usr;
            //----------------------------
            
            _usr = new DataLayer.ImgurUser();
            JsonObject data = json.GetNamedObject("data", null);
            JsonValue jsonV;
            _usr.Id = (int)(data.GetNamedNumber("id"));
            _usr.Url = data.GetNamedString("url");
            //null value causes JSON object to crash
            jsonV=data.GetNamedValue("bio");
            if(jsonV.ValueType.ToString() == "Null")
            {
              _usr.Bio = "";
            }
            else
            {
              _usr.Bio = jsonV.ToString();
            }
            _usr.Rep = (float) data.GetNamedNumber("reputation");
            _usr.Created = (int)data.GetNamedNumber("created");
            //may be boolean or int: false = not a pro user, number if is a pro user
            jsonV = data.GetNamedValue("pro_expiration");
            if (jsonV.ValueType.ToString() == "Boolean")
            {
                _usr.Pro = -1;
            }
            else
            {
                _usr.Pro = (int)jsonV.GetNumber();
            }

            // return user
            return _usr;
        }