示例#1
0
        public void TimeZoneParseFailedRequest()
        {
            TimeZoneCallResult result = TimeZoneRequest.Make(-999999m, -99999m);
            Assert.AreEqual(TimeZoneCallStatus.Unknown, result.Status);

            QueryString query = new QueryString();
            query.Add("lat", "not a latitude");
            query.Add("lng", "not a longitude");

            TimeZoneRequest request = new TimeZoneRequest(query);
            TimeZoneResponse response = request.GetResponse();

            Assert.IsTrue(response.Status == TimeZoneCallStatus.InvalidParameter || response.Status == TimeZoneCallStatus.NotFound);
        }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the GeocodeRequest class.
 /// </summary>
 /// <param name="query">The custom query to use when making the geocode request.</param>
 public GeocodeRequest(QueryString query)
 {
     this.RequestUri = CreateRequestUri(query);
 }
示例#3
0
        /// <summary>
        /// Creates a request URI to use in a geocode request with the given query.
        /// </summary>
        /// <param name="query">The query to create the request URI for.</param>
        /// <returns>A geocode service request URI.</returns>
        public static Uri CreateRequestUri(QueryString query)
        {
            UriBuilder builder = new UriBuilder(ServiceUri);
            builder.Query = query.ToString();

            return builder.Uri;
        }
示例#4
0
        /// <summary>
        /// Creates a request URI to use in a geocode request for the given address.
        /// Restricts the geocode request to the United States.
        /// </summary>
        /// <param name="address">The address to create a request URI for.</param>
        /// <param name="apiKey">The API key to use when making the request.</param>
        /// <returns>A geocode service request URI.</returns>
        public static Uri CreateRequestUri(GeocodeRequestAddress address, string apiKey)
        {
            QueryString query = new QueryString();
            query.Add("q", address.ToString());
            query.Add("key", apiKey);
            query.Add("sensor", "false");
            query.Add("output", "json");
            query.Add("oe", "utf8");
            query.Add("gl", ".us");

            return CreateRequestUri(query);
        }
示例#5
0
        /// <summary>
        /// Sets the entire query string for the given URL.
        /// </summary>
        /// <param name="url">The URl to set the query string for.</param>
        /// <param name="query">The query string to set.</param>
        /// <returns>The updated URL.</returns>
        public static Uri SetQuery(this Uri url, QueryString query)
        {
            UriBuilder builder = new UriBuilder(url);
            builder.Query = query != null ? query.ToString() : String.Empty;

            return builder.Uri;
        }
示例#6
0
        /// <summary>
        /// Creates a new <see cref="TimeZoneRequest"/> URI from the given latitude and longitude.
        /// </summary>
        /// <param name="latitude">The latitude to create the URI with.</param>
        /// <param name="longitude">The longitude to create the URI with.</param>
        /// <returns>A <see cref="TimeZoneRequest"/> URI.</returns>
        public static Uri CreateRequestUri(decimal latitude, decimal longitude)
        {
            QueryString query = new QueryString();
            query["lat"] = latitude.ToString(CultureInfo.InvariantCulture);
            query["lng"] = longitude.ToString(CultureInfo.InvariantCulture);

            return CreateRequestUri(query);
        }
示例#7
0
 /// <summary>
 /// Initializes a new instance of the TimeZoneRequest class.
 /// </summary>
 /// <param name="query">The query string to initialize the request's URI with.</param>
 public TimeZoneRequest(QueryString query)
 {
     this.RequestUri = CreateRequestUri(query);
 }
示例#8
0
 /// <summary>
 /// Creates a new <see cref="TimeZoneRequest"/> URI from the given query string.
 /// </summary>
 /// <param name="query">The query string to create the URI with.</param>
 /// <returns>A <see cref="TimeZoneRequest"/> URI.</returns>
 public static Uri CreateRequestUri(QueryString query)
 {
     return ServiceUri.SetQuery(query);
 }