Beispiel #1
0
        /// <summary>
        /// Create a Uri for sending a request to the specified resource metadata on the specified Socrata host.
        /// </summary>
        /// <param name="socrataHost">The Socrata host to target.</param>
        /// <param name="resourceId">The identifier (4x4) for a resource on the Socrata host to target.</param>
        /// <returns>A Uri pointing to resource metadata for the specified Socrata host and resource identifier.</returns>
        public static Uri ForMetadata(string socrataHost, string resourceId)
        {
            if (String.IsNullOrEmpty(socrataHost))
            {
                throw new ArgumentException("socrataHost", "Must provide a Socrata host to target.");
            }

            if (FourByFour.IsNotValid(resourceId))
            {
                throw new ArgumentOutOfRangeException("resourceId", "The provided resourceId is not a valid Socrata (4x4) resource identifier.");
            }

            string url = metadataUrl(socrataHost, resourceId);

            return(new Uri(url));
        }
Beispiel #2
0
        /// <summary>
        /// Create a revision Uri the specified resource on the specified Socrata host.
        /// </summary>
        /// <param name="socrataHost">The Socrata host to target.</param>
        /// <param name="resourceId">The identifier (4x4) for a resource on the Socrata host to target.</param>
        /// <returns>A revision Uri for the specified resource on the specified Socrata host.</returns>
        public static Uri ForRevision(string socrataHost, string resourceId)
        {
            if (String.IsNullOrEmpty(socrataHost))
            {
                throw new ArgumentException("socrataHost", "Must provide a Socrata host to target.");
            }

            if (FourByFour.IsNotValid(resourceId))
            {
                throw new ArgumentOutOfRangeException("resourceId", "The provided resourceId is not a valid Socrata (4x4) resource identifier.");
            }

            string url = String.Format("{0}/api/publishing/v1/revision/{1}", enforceHttps(socrataHost), resourceId);

            return(new Uri(url));
        }
Beispiel #3
0
        /// <summary>
        /// Create a Uri to the Foundry-style API documentation page of the specified resource on the specified Socrata host.
        /// </summary>
        /// <param name="socrataHost">The Socrata host to target.</param>
        /// <param name="resourceId">The identifier (4x4) for a resource on the Socrata host to target.</param>
        /// <returns>A Uri pointing to the Foundry API documentation page of the specified resource on the specified Socrata host.</returns>
        public static Uri ForResourceAPIPage(string socrataHost, string resourceId)
        {
            if (String.IsNullOrEmpty(socrataHost))
            {
                throw new ArgumentException("socrataHost", "Must provide a Socrata host to target.");
            }

            if (FourByFour.IsNotValid(resourceId))
            {
                throw new ArgumentOutOfRangeException("resourceId", "The provided resourceId is not a valid Socrata (4x4) resource identifier.");
            }

            string hostOnly = httpsPrefix.Replace(httpPrefix.Replace(socrataHost, ""), "");

            string url = String.Format("http://dev.socrata.com/foundry/#/{0}/{1}", hostOnly, resourceId);

            return(new Uri(url));
        }
Beispiel #4
0
        /// <summary>
        /// Create a Uri for sending a request to the specified resource on the specified Socrata host.
        /// </summary>
        /// <param name="socrataHost">The Socrata host to target.</param>
        /// <param name="resourceId">The identifier (4x4) for a resource on the Socrata host to target.</param>
        /// <param name="rowId">The identifier for a row in the resource to target.</param>
        /// <returns>A Uri pointing to the SODA endpoint for the specified resource in the specified Socrata host.</returns>
        public static Uri ForResourceAPI(string socrataHost, string resourceId, string rowId = null)
        {
            if (String.IsNullOrEmpty(socrataHost))
            {
                throw new ArgumentException("socrataHost", "Must provide a Socrata host to target.");
            }

            if (FourByFour.IsNotValid(resourceId))
            {
                throw new ArgumentOutOfRangeException("resourceId", "The provided resourceId is not a valid Socrata (4x4) resource identifier.");
            }

            string url = metadataUrl(socrataHost, resourceId).Replace("views", "resource");

            if (!String.IsNullOrEmpty(rowId))
            {
                url = String.Format("{0}/{1}", url, rowId);
            }

            return(new Uri(url));
        }
Beispiel #5
0
        /// <summary>
        /// Create a Uri for querying the specified resource on the specified Socrata host, using the specified SoqlQuery object.
        /// </summary>
        /// <param name="socrataHost">The Socrata host to target.</param>
        /// <param name="resourceId">The identifier (4x4) for a resource on the Socrata host to target.</param>
        /// <param name="soqlQuery">A SoqlQuery object to use for querying.</param>
        /// <returns>A query Uri for the specified resource on the specified Socrata host.</returns>
        public static Uri ForQuery(string socrataHost, string resourceId, SoqlQuery soqlQuery)
        {
            if (String.IsNullOrEmpty(socrataHost))
            {
                throw new ArgumentException("socrataHost", "Must provide a Socrata host to target.");
            }

            if (FourByFour.IsNotValid(resourceId))
            {
                throw new ArgumentOutOfRangeException("resourceId", "The provided resourceId is not a valid Socrata (4x4) resource identifier.");
            }

            if (soqlQuery == null)
            {
                throw new ArgumentNullException("soqlQuery", "Must provide a valid SoqlQuery object");
            }

            string url = metadataUrl(socrataHost, resourceId).Replace("views", "resource");

            string queryUrl = Uri.EscapeUriString(String.Format("{0}?{1}", url, soqlQuery.ToString()));

            return(new Uri(queryUrl));
        }