Beispiel #1
0
        public static Units MaximumUnits(this TimeSpan timeSpan, Units?units)
        {
            if (units != null)
            {
                maximumUnits = (Units)units;
            }

            return(maximumUnits);
        }
Beispiel #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="apiKey"></param>
 /// <param name="latitude"></param>
 /// <param name="longitude"></param>
 /// <param name="time"></param>
 /// <param name="units"></param>
 /// <param name="lang"></param>
 /// <param name="extend"></param>
 /// <param name="exclude"></param>
 public DarkSkyRequest(string apiKey, double latitude, double longitude, DateTime?time, Units?units, Language?lang, bool extend, IEnumerable <Exclude> exclude)
 {
     ApiKey    = apiKey;
     Latitude  = latitude;
     Longitude = longitude;
     Time      = time;
     Units     = units;
     Lang      = lang;
     Extend    = extend;
     Excludes  = exclude;
 }
Beispiel #3
0
        public void ParsingEncodedIntegersWorks(
            string encoded, bool shouldSucceed,
            int?expected = null, Units?expectedUnits = null)
        {
            Constant.TryParseEncoded(encoded, out var value)
            .Should().Be(shouldSucceed);

            if (shouldSucceed)
            {
                value.Value.Should().Be(expected.Value);
                value.Units.Should().Be(expectedUnits.Value);
                value.SupportedType.Should().Be(SupportedTypes.Integer);
            }
        }
Beispiel #4
0
        public static void AppendKey(this StringBuilder sb, string key, Units?units)
        {
            if (!units.HasValue)
            {
                return;
            }

            switch (units.Value)
            {
            case Units.Percents:
                sb.AppendFormat(CONST_Format, key, "PERCENTS");
                return;

            case Units.PriceUnits:
                sb.AppendFormat(CONST_Format, key, "PRICE_UNITS");
                return;
            }
            ;
        }
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        /// <summary>Call current weather data for one location</summary>
        /// <param name="q">**City name**. *Example: London*. You can call by city name, or by city name and country code. The API responds with a list of results that match a searching word. For the query value, type the city name and optionally the country code divided by comma; use ISO 3166 country codes.</param>
        /// <param name="id">**City ID**. *Example: `2172797`*. You can call by city ID. API responds with exact result. The List of city IDs can be downloaded [here](http://bulk.openweathermap.org/sample/). You can include multiple cities in parameter &amp;mdash; just separate them by commas. The limit of locations is 20. *Note: A single ID counts as a one API call. So, if you have city IDs. it's treated as 3 API calls.*</param>
        /// <param name="lat">**Latitude**. *Example: 35*. The latitude cordinate of the location of your interest. Must use with `lon`.</param>
        /// <param name="lon">**Longitude**. *Example: 139*. Longitude cordinate of the location of your interest. Must use with `lat`.</param>
        /// <param name="zip">**Zip code**. Search by zip code. *Example: 95050,us*. Please note if country is not specified then the search works for USA as a default.</param>
        /// <param name="units">**Units**. *Example: imperial*. Possible values: `standard`, `metric`, and `imperial`. When you do not use units parameter, format is `standard` by default.</param>
        /// <param name="lang">**Language**. *Example: en*. You can use lang parameter to get the output in your language. We support the following languages that you can use with the corresponded lang values: Arabic - `ar`, Bulgarian - `bg`, Catalan - `ca`, Czech - `cz`, German - `de`, Greek - `el`, English - `en`, Persian (Farsi) - `fa`, Finnish - `fi`, French - `fr`, Galician - `gl`, Croatian - `hr`, Hungarian - `hu`, Italian - `it`, Japanese - `ja`, Korean - `kr`, Latvian - `la`, Lithuanian - `lt`, Macedonian - `mk`, Dutch - `nl`, Polish - `pl`, Portuguese - `pt`, Romanian - `ro`, Russian - `ru`, Swedish - `se`, Slovak - `sk`, Slovenian - `sl`, Spanish - `es`, Turkish - `tr`, Ukrainian - `ua`, Vietnamese - `vi`, Chinese Simplified - `zh_cn`, Chinese Traditional - `zh_tw`.</param>
        /// <param name="mode">**Mode**. *Example: html*. Determines format of response. Possible values are `xml` and `html`. If mode parameter is empty the format is `json` by default.</param>
        /// <returns>Successful response</returns>
        /// <exception cref="ApiException">A server side error occurred.</exception>
        public async System.Threading.Tasks.Task <_200> CurrentWeatherDataAsync(string q, string id, string lat, string lon, string zip, Units?units, Lang?lang, Mode?mode, string AppId, System.Threading.CancellationToken cancellationToken)
        {
            var urlBuilder_ = new System.Text.StringBuilder();

            urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/weather?");
            if (q != null)
            {
                urlBuilder_.Append(System.Uri.EscapeDataString("q") + "=").Append(System.Uri.EscapeDataString(ConvertToString(q, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            if (id != null)
            {
                urlBuilder_.Append(System.Uri.EscapeDataString("id") + "=").Append(System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            if (lat != null)
            {
                urlBuilder_.Append(System.Uri.EscapeDataString("lat") + "=").Append(System.Uri.EscapeDataString(ConvertToString(lat, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            if (lon != null)
            {
                urlBuilder_.Append(System.Uri.EscapeDataString("lon") + "=").Append(System.Uri.EscapeDataString(ConvertToString(lon, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            if (zip != null)
            {
                urlBuilder_.Append(System.Uri.EscapeDataString("zip") + "=").Append(System.Uri.EscapeDataString(ConvertToString(zip, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            if (units != null)
            {
                urlBuilder_.Append(System.Uri.EscapeDataString("units") + "=").Append(System.Uri.EscapeDataString(ConvertToString(units, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            if (lang != null)
            {
                urlBuilder_.Append(System.Uri.EscapeDataString("lang") + "=").Append(System.Uri.EscapeDataString(ConvertToString(lang, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            if (mode != null)
            {
                urlBuilder_.Append(System.Uri.EscapeDataString("mode") + "=").Append(System.Uri.EscapeDataString(ConvertToString(mode, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            if (AppId != null)
            {
                urlBuilder_.Append(System.Uri.EscapeDataString("appid") + "=").Append(System.Uri.EscapeDataString(ConvertToString(AppId, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            urlBuilder_.Length--;

            var client_        = _httpClient;
            var disposeClient_ = false;

            try
            {
                using (var request_ = new System.Net.Http.HttpRequestMessage())
                {
                    request_.Method = new System.Net.Http.HttpMethod("GET");
                    request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json"));

                    PrepareRequest(client_, request_, urlBuilder_);
                    var url_ = urlBuilder_.ToString();
                    request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
                    PrepareRequest(client_, request_, url_);

                    var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);

                    var disposeResponse_ = true;
                    try
                    {
                        var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
                        if (response_.Content != null && response_.Content.Headers != null)
                        {
                            foreach (var item_ in response_.Content.Headers)
                            {
                                headers_[item_.Key] = item_.Value;
                            }
                        }

                        ProcessResponse(client_, response_);

                        var status_ = (int)response_.StatusCode;
                        if (status_ == 200)
                        {
                            var objectResponse_ = await ReadObjectResponseAsync <_200>(response_, headers_).ConfigureAwait(false);

                            if (objectResponse_.Object == null)
                            {
                                throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
                            }
                            return(objectResponse_.Object);
                        }
                        else
                        if (status_ == 404)
                        {
                            var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);

                            var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string));
                        }
                        else
                        {
                            var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);

                            throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null);
                        }
                    }
                    finally
                    {
                        if (disposeResponse_)
                        {
                            response_.Dispose();
                        }
                    }
                }
            }
            finally
            {
                if (disposeClient_)
                {
                    client_.Dispose();
                }
            }
            return(null);
        }
 /// <summary>Call current weather data for one location</summary>
 /// <param name="q">**City name**. *Example: London*. You can call by city name, or by city name and country code. The API responds with a list of results that match a searching word. For the query value, type the city name and optionally the country code divided by comma; use ISO 3166 country codes.</param>
 /// <param name="id">**City ID**. *Example: `2172797`*. You can call by city ID. API responds with exact result. The List of city IDs can be downloaded [here](http://bulk.openweathermap.org/sample/). You can include multiple cities in parameter &amp;mdash; just separate them by commas. The limit of locations is 20. *Note: A single ID counts as a one API call. So, if you have city IDs. it's treated as 3 API calls.*</param>
 /// <param name="lat">**Latitude**. *Example: 35*. The latitude cordinate of the location of your interest. Must use with `lon`.</param>
 /// <param name="lon">**Longitude**. *Example: 139*. Longitude cordinate of the location of your interest. Must use with `lat`.</param>
 /// <param name="zip">**Zip code**. Search by zip code. *Example: 95050,us*. Please note if country is not specified then the search works for USA as a default.</param>
 /// <param name="units">**Units**. *Example: imperial*. Possible values: `standard`, `metric`, and `imperial`. When you do not use units parameter, format is `standard` by default.</param>
 /// <param name="lang">**Language**. *Example: en*. You can use lang parameter to get the output in your language. We support the following languages that you can use with the corresponded lang values: Arabic - `ar`, Bulgarian - `bg`, Catalan - `ca`, Czech - `cz`, German - `de`, Greek - `el`, English - `en`, Persian (Farsi) - `fa`, Finnish - `fi`, French - `fr`, Galician - `gl`, Croatian - `hr`, Hungarian - `hu`, Italian - `it`, Japanese - `ja`, Korean - `kr`, Latvian - `la`, Lithuanian - `lt`, Macedonian - `mk`, Dutch - `nl`, Polish - `pl`, Portuguese - `pt`, Romanian - `ro`, Russian - `ru`, Swedish - `se`, Slovak - `sk`, Slovenian - `sl`, Spanish - `es`, Turkish - `tr`, Ukrainian - `ua`, Vietnamese - `vi`, Chinese Simplified - `zh_cn`, Chinese Traditional - `zh_tw`.</param>
 /// <param name="mode">**Mode**. *Example: html*. Determines format of response. Possible values are `xml` and `html`. If mode parameter is empty the format is `json` by default.</param>
 /// <returns>Successful response</returns>
 /// <exception cref="ApiException">A server side error occurred.</exception>
 public System.Threading.Tasks.Task <_200> CurrentWeatherDataAsync(string q, string id, string lat, string lon, string zip, Units?units, Lang?lang, Mode?mode, string AppId)
 {
     return(CurrentWeatherDataAsync(q, id, lat, lon, zip, units, lang, mode, AppId, System.Threading.CancellationToken.None));
 }
Beispiel #7
0
        private static string GetGetPointsQuery(BackendlessGeoQuery geoQuery, out Invoker.Api api)
        {
            string query = null;

            if (geoQuery != null)
            {
                double[] searchRectangle = geoQuery.SearchRectangle;
                if (searchRectangle != null)
                {
                    api = Invoker.Api.GEOSERVICE_GETRECT;

                    if (searchRectangle.Length == 4)
                    {
                        AddQuery(ref query, "nwlat=" + searchRectangle[0]);
                        AddQuery(ref query, "nwlon=" + searchRectangle[1]);
                        AddQuery(ref query, "selat=" + searchRectangle[2]);
                        AddQuery(ref query, "selon=" + searchRectangle[3]);
                    }
                }
                else
                {
                    api = Invoker.Api.GEOSERVICE_GETPOINTS;

                    Dictionary <string, string> relativeFindMetadataList = geoQuery.RelativeFindMetadata;
                    if (relativeFindMetadataList != null && relativeFindMetadataList.Count > 0)
                    {
                        api = Invoker.Api.GEOSERVICE_RELATIVEFIND;

                        string metadata = JsonMapper.ToJson(relativeFindMetadataList);
                        if (string.IsNullOrEmpty(metadata) == false)
                        {
                            AddQuery(ref query, "relativeFindMetadata=" + UnityEngine.WWW.EscapeURL(metadata));
                        }

                        AddQuery(ref query, "relativeFindPercentThreshold=" + geoQuery.RelativeFindPercentThreshold);
                    }

                    if (Double.NaN.Equals(geoQuery.Latitude) == false)
                    {
                        AddQuery(ref query, "lat=" + geoQuery.Latitude);
                    }

                    if (Double.NaN.Equals(geoQuery.Longitude) == false)
                    {
                        AddQuery(ref query, "lon=" + geoQuery.Longitude);
                    }

                    if (Double.NaN.Equals(geoQuery.Radius) == false)
                    {
                        AddQuery(ref query, "r=" + geoQuery.Radius);
                    }

                    Units?unit = geoQuery.Units;
                    if (unit != null)
                    {
                        AddQuery(ref query, "units=" + unit.ToString());
                    }
                }

                List <string> categoriesList = geoQuery.Categories;
                if (categoriesList != null && categoriesList.Count > 0)
                {
                    string categories = "";
                    foreach (string category in categoriesList)
                    {
                        if (string.IsNullOrEmpty(categories) == false)
                        {
                            categories += ",";
                        }
                        categories += category;
                    }
                    if (string.IsNullOrEmpty(categories) == false)
                    {
                        AddQuery(ref query, "categories=" + categories);
                    }
                }

                Dictionary <string, string> metadataList = geoQuery.Metadata;
                if (metadataList != null && metadataList.Count > 0)
                {
                    string metadata = JsonMapper.ToJson(metadataList);
                    if (string.IsNullOrEmpty(metadata) == false)
                    {
                        AddQuery(ref query, "metadata=" + UnityEngine.WWW.EscapeURL(metadata));
                    }
                }

                AddQuery(ref query, "includemetadata=" + geoQuery.IncludeMeta.ToString().ToLower());

                AddQuery(ref query, "pagesize=" + geoQuery.PageSize);

                AddQuery(ref query, "offset=" + geoQuery.Offset);
            }
            else
            {
                api = Invoker.Api.UNKNOWN;
            }

            return(query);
        }
Beispiel #8
0
 /// <summary>
 /// Exclude certain objects (returned as null)
 /// </summary>
 public DarkSkyResponse Download(double latitude, double longitude, DateTime?time, Units?units, Language?lang, bool extend, IEnumerable <Exclude> exclude)
 => Download(new DarkSkyRequest(this.ApiKey, latitude, longitude, time, units, lang, extend, exclude));
Beispiel #9
0
 /// <summary>
 /// Include extra data - (Currently only hourly is supported by the API) Returns hourly data for the next seven days, rather than the next two.
 /// </summary>
 public DarkSkyResponse Download(double latitude, double longitude, DateTime?dateTime, Units?units, Language?lang, bool extend)
 => Download(latitude, longitude, dateTime, units, lang, extend, null);
Beispiel #10
0
 /// <summary>
 /// Specify units and language
 /// </summary>
 public DarkSkyResponse Download(double latitude, double longitude, Units?units, Language?lang)
 => Download(latitude, longitude, null, units, lang, false, null);