This commit is contained in:
Paul Schneider 2015-01-27 14:17:33 +01:00
commit 93c18633b9
28 changed files with 338 additions and 150 deletions

View file

@ -30,29 +30,48 @@ using Newtonsoft.Json;
namespace Yavsc.Helpers.Google
{
/// <summary>
/// Google base API client.
/// This class implements the identification values for a Google Api,
/// and provides some scope values.
/// </summary>
public class ApiClient
{
/// <summary>
/// The CLIENT Id.
/// </summary>
protected static string CLIENT_ID = "325408689282-6bekh7p3guj4k0f3301a6frf025cnrk1.apps.googleusercontent.com";
/// <summary>
/// The CLIENt SECREt
/// </summary>
protected static string CLIENT_SECRET = "MaxYcvJJCs2gDGvaELZbzwfL";
/// <summary>
/// The API KEY.
/// </summary>
protected static string API_KEY="AIzaSyBV_LQHb22nGgjNvFzZwnQHjao3Q7IewRw";
/* // to use in descendence
*
protected static string getPeopleUri = "https://www.googleapis.com/plus/v1/people";
private static string authUri = "https://accounts.google.com/o/oauth2/auth";
*/
/// <summary>
/// The Map tracks scope .
/// </summary>
protected static string scopeTracks = "https://www.googleapis.com/auth/tracks";
/// <summary>
/// The calendar scope.
/// </summary>
protected static string scopeCalendar = "https://www.googleapis.com/auth/calendar";
/// <summary>
/// The scope openid.
/// </summary>
protected static string[] scopeOpenid = {
"openid",
"profile",
"email"
};
// private static string dateFormat = "yyyy-MM-ddTHH:mm:ss";
}
}

View file

@ -31,14 +31,36 @@ using System.Web;
namespace Yavsc.Helpers.Google
{
/// <summary>
/// Google Calendar API client.
/// </summary>
public class CalendarApi: ApiClient
{
/// <summary>
/// The get cal list URI.
/// </summary>
protected static string getCalListUri = "https://www.googleapis.com/calendar/v3/users/me/calendarList";
/// <summary>
/// The get cal entries URI.
/// </summary>
protected static string getCalEntriesUri = "https://www.googleapis.com/calendar/v3/calendars/{0}/events";
/// <summary>
/// The date format.
/// </summary>
private static string dateFormat = "yyyy-MM-ddTHH:mm:ss";
/// <summary>
/// The time zone. TODO Fixme with machine time zone
/// </summary>
private string timeZone = "+01:00";
/// <summary>
/// Gets the calendar list.
/// </summary>
/// <returns>The calendars.</returns>
/// <param name="cred">Cred.</param>
/// <param name="json">Json.</param>
public CalendarList GetCalendars (string cred, out string json)
{
CalendarList res = null;
@ -59,6 +81,15 @@ namespace Yavsc.Helpers.Google
return res;
}
/// <summary>
/// Gets a calendar.
/// </summary>
/// <returns>The calendar.</returns>
/// <param name="calid">Calid.</param>
/// <param name="mindate">Mindate.</param>
/// <param name="maxdate">Maxdate.</param>
/// <param name="upr">Upr.</param>
/// <param name="responseStr">Response string.</param>
public CalendarEntryList GetCalendar (string calid, DateTime mindate, DateTime maxdate, ProfileBase upr, out string responseStr)
{
string uri = string.Format (

View file

@ -30,9 +30,17 @@ using Newtonsoft.Json;
namespace Yavsc.Helpers.Google
{
/// <summary>
/// Entity query.
/// </summary>
public class EntityQuery {
/// <summary>
/// The entity identifiers.
/// </summary>
public string [] EntityIds;
/// <summary>
/// The minimum identifier.
/// </summary>
public string MinId;
}
}

View file

@ -29,8 +29,14 @@ using Newtonsoft.Json;
namespace Yavsc.Helpers.Google
{
/// <summary>
/// Google Map tracks Api client.
/// </summary>
public class MapTracks:ApiClient {
/// <summary>
/// The google map tracks path (uri of the service).
/// </summary>
protected static string googleMapTracksPath = "https://www.googleapis.com/tracks/v1/";
// entities/[create|list|delete]
// collections/[list|create|[add|remove]entities|delete]
@ -41,8 +47,12 @@ namespace Yavsc.Helpers.Google
// collections/[list|create|[add|remove]entities|delete]
// crumbs/[record|getrecent|gethistory|report|summarize|getlocationinfo|delete
static string [] CreateEntity( Entity[] entities ) {
/// <summary>
/// Creates the entity.
/// </summary>
/// <returns>The entity.</returns>
/// <param name="entities">Entities.</param>
public static string [] CreateEntity( Entity[] entities ) {
string [] ans = null;
using (SimpleJsonPostMethod< Entity[] ,string []> wr =
new SimpleJsonPostMethod< Entity[] ,string[]> (googleMapTracksPath + "entities/create"))
@ -51,6 +61,12 @@ namespace Yavsc.Helpers.Google
}
return ans;
}
/// <summary>
/// Lists the entities.
/// </summary>
/// <returns>The entities.</returns>
/// <param name="eq">Eq.</param>
static Entity[] ListEntities (EntityQuery eq)
{
Entity [] ans = null;

View file

@ -30,11 +30,18 @@ using Yavsc.Model;
namespace Yavsc.Helpers.Google
{
/// <summary>
/// Google People API.
/// </summary>
public class PeopleApi: ApiClient
{
private static string getPeopleUri = "https://www.googleapis.com/plus/v1/people";
/// <summary>
/// Gets the People object associated to the given Google Access Token
/// </summary>
/// <returns>The me.</returns>
/// <param name="gat">The Google Access Token object <see cref="AuthToken"/> class.</param>
public static People GetMe (AuthToken gat)
{
People me;
@ -57,13 +64,31 @@ namespace Yavsc.Helpers.Google
}
}
/// <summary>
/// Google O auth2 client.
/// </summary>
public class OAuth2:ApiClient
{
/// <summary>
/// The URI used to get tokens.
/// </summary>
protected static string tokenUri = "https://accounts.google.com/o/oauth2/token";
/// <summary>
/// The URI used to get authorized to.
/// </summary>
protected static string authUri = "https://accounts.google.com/o/oauth2/auth";
/// <summary>
/// Gets or sets the redirect URI sent to Google.
/// </summary>
/// <value>The redirect URI.</value>
public string RedirectUri { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="Yavsc.Helpers.Google.OAuth2"/> class.
/// </summary>
/// <param name="redirectUri">Redirect URI.</param>
public OAuth2 (string redirectUri)
{
RedirectUri = redirectUri;
@ -84,7 +109,11 @@ namespace Yavsc.Helpers.Google
CLIENT_ID, RedirectUri, scope, state);
GetAuthResponse (bresp, prms);
}
/// <summary>
/// Gets the cal authorization.
/// </summary>
/// <param name="bresp">Bresp.</param>
/// <param name="state">State.</param>
public void GetCalAuth (HttpResponseBase bresp, string state)
{
string scope = string.Join ("%20", scopeOpenid);
@ -130,7 +159,13 @@ namespace Yavsc.Helpers.Google
HttpUtility.UrlEncode (code));
return postdata;
}
/// <summary>
/// Gets the Google Authorization token.
/// </summary>
/// <returns>The token.</returns>
/// <param name="rq">Rq.</param>
/// <param name="state">State.</param>
/// <param name="message">Message.</param>
public AuthToken GetToken (HttpRequestBase rq, string state, out string message)
{
string code = OAuth2.GetCodeFromRequest (rq, state, out message);
@ -138,12 +173,6 @@ namespace Yavsc.Helpers.Google
return GetTokenPosting (postdata);
}
[Obsolete ("Use GetToken instead.")]
public static AuthToken GetTokenFromBody (string postdata)
{
throw new NotImplementedException ();
}
internal static AuthToken GetTokenPosting (string postdata)
{
HttpWebRequest webreq = WebRequest.CreateHttp (tokenUri);
@ -174,6 +203,13 @@ namespace Yavsc.Helpers.Google
return gat;
}
/// <summary>
/// Gets the code from the Google request.
/// </summary>
/// <returns>The code from request.</returns>
/// <param name="rq">Rq.</param>
/// <param name="state">State.</param>
/// <param name="message">Message.</param>
public static string GetCodeFromRequest (HttpRequestBase rq, string state, out string message)
{
message = "";
@ -194,6 +230,11 @@ namespace Yavsc.Helpers.Google
return code;
}
/// <summary>
/// Gets fresh google credential.
/// </summary>
/// <returns>The fresh google credential.</returns>
/// <param name="pr">Pr.</param>
public static string GetFreshGoogleCredential (ProfileBase pr)
{
string token = (string)pr.GetPropertyValue ("gtoken");