Skip to content

Commit

Permalink
Added TimeZone Api
Browse files Browse the repository at this point in the history
No tests added to MapsApiTest
No backward compatibility to deprecated MapsAPIEngine.
  • Loading branch information
Michael Vivet committed Feb 22, 2013
1 parent 8032590 commit 1f3897f
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 4 deletions.
20 changes: 16 additions & 4 deletions GoogleMapsApi.Test/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
using GoogleMapsApi.Entities.Directions.Response;
using GoogleMapsApi.Entities.Elevation.Request;
using GoogleMapsApi.Entities.Geocoding.Request;
using GoogleMapsApi.Entities.Geocoding.Response;
using GoogleMapsApi.Entities.TimeZone.Request;
using GoogleMapsApi.Entities.TimeZone.Response;
using NUnit.Framework;
using Status = GoogleMapsApi.Entities.Geocoding.Response.Status;

/////////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -178,7 +180,6 @@ public void Directions_WithWayPoints()
StringAssert.Contains("Philadelphia", result.Routes.First().Legs.First().EndAddress);
}


[Test]
public void Directions_Correct_OverviewPath()
{
Expand All @@ -197,7 +198,6 @@ public void Directions_Correct_OverviewPath()
Assert.AreEqual(13, polyline.Points.Count());
}


[Test]
public void DirectionsAsync_SumOfStepDistancesCorrect()
{
Expand Down Expand Up @@ -236,7 +236,19 @@ public void ElevationAsync_ReturnsCorrectElevation()
Assert.AreEqual(Entities.Elevation.Response.Status.OK, result.Status);
Assert.AreEqual(14.782454490661619, result.Results.First().Elevation);
}
}

[Test]
public void TimeZone_Correct_OverviewPath()
{
TimeZoneRequest request = new TimeZoneRequest();
request.Location = new Location(55.866413, 12.501063);
request.Language = "en";

TimeZoneResponse result = GoogleMaps.TimeZone.Query(request);

Assert.AreEqual(GoogleMapsApi.Entities.TimeZone.Response.Status.OK, result.Status);
}
}

static class Utils
{
Expand Down
56 changes: 56 additions & 0 deletions GoogleMapsApi/Entities/TimeZone/Request/TimeZoneRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using GoogleMapsApi.Engine;
using GoogleMapsApi.Entities.Common;

namespace GoogleMapsApi.Entities.TimeZone.Request
{
public class TimeZoneRequest : SignableRequest
{
protected internal override string BaseUrl
{
get { return "maps.googleapis.com/maps/api/timezone/"; }
}

/// <summary>
/// location: a comma-separated lat,lng tuple (eg. location=-33.86,151.20), representing the location to look up
/// </summary>
public Location Location { get; set; } // required

/// <summary>
/// Timestamp specifies the desired time as seconds since midnight, January 1, 1970 UTC. The Time Zone API uses the timestamp to determine whether or not Daylight Savings should be applied. Times before 1970 can be expressed as negative values.
/// </summary>
public DateTime TimeStamp { get; set; } // required

/// <summary>
/// The language in which to return results. See the list of supported domain languages. Note that we often update supported languages so this list may not be exhaustive. Defaults to en
/// </summary>
public string Language { get; set; } // optional

/// <summary>
/// The language in which to return results. See the list of supported domain languages. Note that we often update supported languages so this list may not be exhaustive. Defaults to en.
/// </summary>
public override bool IsSSL
{
get { return true; }
set { throw new NotSupportedException("This operation is not supported, TimeZoneRequest must use SSL"); }
}

protected override QueryStringParametersList GetQueryStringParameters()
{
if (Location == null)
throw new ArgumentException("Location is required");

if (TimeStamp == null)
throw new ArgumentException("TimeStamp is required");

var _parameters = base.GetQueryStringParameters();

_parameters.Add("location", this.Location.LocationString);
_parameters.Add("timestamp", UnixTimeConverter.DateTimeToUnixTimestamp(this.TimeStamp).ToString());

if (!string.IsNullOrWhiteSpace(Language)) _parameters.Add("language", Language);

return _parameters;
}
}
}
21 changes: 21 additions & 0 deletions GoogleMapsApi/Entities/TimeZone/Response/Status.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Runtime.Serialization;

namespace GoogleMapsApi.Entities.TimeZone.Response
{
[DataContract]
public enum Status
{
[EnumMember(Value = "OK")]
OK, // indicates that no errors occurred; the place was successfully detected and at least one result was returned.
[EnumMember(Value = "ZERO_RESULTS")]
ZERO_RESULTS, // indicates that the search was successful but returned no results. This may occur if the search was passed a latlng in a remote location.
[EnumMember(Value = "OVER_QUERY_LIMIT")]
OVER_QUERY_LIMIT, // indicates that you are over your quota.
[EnumMember(Value = "REQUEST_DENIED")]
REQUEST_DENIED, // indicates that your request was denied, generally because of lack of a sensor parameter.
[EnumMember(Value = "INVALID_REQUEST")]
INVALID_REQUEST, // generally indicates that the query parameter (location or radius) is missing.
[EnumMember(Value = "UNKNOWN_ERROR")]
UNKNOWN_ERROR // indicates an unknown error
}
}
56 changes: 56 additions & 0 deletions GoogleMapsApi/Entities/TimeZone/Response/TimeZoneResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Runtime.Serialization;
using GoogleMapsApi.Entities.Common;
using GoogleMapsApi.Entities.TimeZone.Request;

namespace GoogleMapsApi.Entities.TimeZone.Response
{
[DataContract]
public class TimeZoneResponse : IResponseFor<TimeZoneRequest>
{
/// <summary>
/// "status" contains metadata on the request.
/// </summary>
public Status Status { get; set; }

[DataMember(Name = "status")]
internal string StatusStr
{
get
{
return Status.ToString();
}
set
{
Status = (Status)Enum.Parse(typeof(Status), value);
}
}

/// <summary>
/// DstOffset: the offset for daylight-savings time in seconds. This will be zero if the time zone is not in Daylight Savings Time during the specified timestamp.
/// </summary>
[DataMember(Name = "dstOffset")]
public double OffSet { get; set; }

/// <summary>
/// RawOffset: the offset from UTC (in seconds) for the given location. This does not take into effect daylight savings.
/// </summary>
[DataMember(Name = "rawOffset")]
public double RawOffSet { get; set; }

/// <summary>
/// TimeZoneId: a string containing the ID of the time zone, such as "America/Los_Angeles" or "Australia/Sydney".
/// </summary>
[DataMember(Name = "timeZoneId")]
public string TimeZoneId { get; set; }

/// <summary>
/// TimeZoneName: a string containing the long form name of the time zone. This field will be localized if the language parameter is set. eg. "Pacific Daylight Time" or "Australian.
/// </summary>
[DataMember(Name = "timeZoneName")]
public string TimeZoneName { get; set; }
}
}



11 changes: 11 additions & 0 deletions GoogleMapsApi/GoogleMaps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
using GoogleMapsApi.Entities.PlacesDetails.Response;
using GoogleMapsApi.Entities.PlacesText.Request;
using GoogleMapsApi.Entities.PlacesText.Response;
using GoogleMapsApi.Entities.TimeZone.Request;
using GoogleMapsApi.Entities.TimeZone.Response;

namespace GoogleMapsApi
{
Expand Down Expand Up @@ -65,6 +67,15 @@ public static EngineFacade<PlacesTextRequest, PlacesTextResponse> PlacesText
}
}

/// <summary>Perform places text search operations.</summary>
public static EngineFacade<TimeZoneRequest, TimeZoneResponse> TimeZone
{
get
{
return EngineFacade<TimeZoneRequest, TimeZoneResponse>.Instance;
}
}

/// <summary>Perform places details operations.</summary>
public static EngineFacade<PlacesDetailsRequest, PlacesDetailsResponse> PlacesDetails
{
Expand Down
3 changes: 3 additions & 0 deletions GoogleMapsApi/GoogleMapsApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@
<Compile Include="Entities\Places\Response\PlacesResponse.cs" />
<Compile Include="Entities\Places\Response\Result.cs" />
<Compile Include="Entities\Places\Response\Status.cs" />
<Compile Include="Entities\TimeZone\Request\TimeZoneRequest.cs" />
<Compile Include="Entities\TimeZone\Response\Status.cs" />
<Compile Include="Entities\TimeZone\Response\TimeZoneResponse.cs" />
<Compile Include="GoogleMaps.cs" />
<Compile Include="MapsAPI.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down

0 comments on commit 1f3897f

Please sign in to comment.