Example #1
0
        public Location AddLocation(Location MyLocation)
        {
            Console.WriteLine("Adding location " + MyLocation.Name + "...");

            RestRequest request = new RestRequest("/{version}/admin/locations", Method.POST);

            request.AddParameter("version", _ver, ParameterType.UrlSegment);
            request.AddParameter("application/json", API.LocationJson(MyLocation), ParameterType.RequestBody);
            request.AddParameter("Authorization", _token.token_type + " " + _token.access_token, ParameterType.HttpHeader);

            IRestResponse  response    = _client.Execute(request);
            HttpStatusCode statusCode  = response.StatusCode;
            int            numericCode = (int)statusCode;

            if (numericCode != 201)
            {
                throw new FoundryException(response.ErrorMessage, numericCode, response.Content);
            }

            //verify if adding was okay with status code

            LocationDataJson locationData = JsonConvert.DeserializeObject <LocationDataJson>(response.Content);

            Console.WriteLine("Location successfully added.");

            Location location = locationData.LocationData.LocationAttributes;

            location.Id = locationData.LocationData.Id;

            FoundryLocations.Add(location);
            return(location);
        }
Example #2
0
        public Location UpdateLocation(Location MyLocation)
        {
            Console.WriteLine("Updating location " + MyLocation.Name + "...");

            RestRequest request = new RestRequest("/{version}/admin/locations/{location_id}", Method.PATCH);

            request.AddParameter("version", _ver, ParameterType.UrlSegment);
            request.AddParameter("location_id", MyLocation.Id, ParameterType.UrlSegment);
            request.AddParameter("application/json", API.LocationJson(MyLocation), ParameterType.RequestBody);
            request.AddParameter("Authorization", _token.token_type + " " + _token.access_token, ParameterType.HttpHeader);

            IRestResponse  response    = _client.Execute(request);
            HttpStatusCode statusCode  = response.StatusCode;
            int            numericCode = (int)statusCode;

            if (numericCode != 200)
            {
                throw new FoundryException(response.ErrorMessage, numericCode, response.Content);
            }

            LocationDataJson locationData = JsonConvert.DeserializeObject <LocationDataJson>(response.Content);
            Location         location     = locationData.LocationData.LocationAttributes;

            location.AddIdFromData(locationData.LocationData);

            FoundryLocations.Remove(MyLocation);
            FoundryLocations.Add(location);

            return(location);
        }
Example #3
0
        public Location GetLocationById(string LocationId)
        {
            RestRequest request = new RestRequest("/{version}/admin/locations/{location_id}", Method.GET);

            request.AddParameter("version", _ver, ParameterType.UrlSegment);
            request.AddParameter("location_id", LocationId, ParameterType.UrlSegment);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("Authorization", _token.token_type + " " + _token.access_token, ParameterType.HttpHeader);

            IRestResponse  response    = _client.Execute(request);
            HttpStatusCode statusCode  = response.StatusCode;
            int            numericCode = (int)statusCode;

            if (numericCode != 200)
            {
                throw new FoundryException(response.ErrorMessage, numericCode, response.Content);
            }

            LocationDataJson locationData = JsonConvert.DeserializeObject <LocationDataJson>(response.Content);
            Location         location     = locationData.LocationData.LocationAttributes;

            location.AddIdFromData(locationData.LocationData);

            return(location);
        }