Skip to content

Commit

Permalink
* Modified DatabaseClient.GetDatabase to pass error message by refere…
Browse files Browse the repository at this point in the history
…nce if it meets any of one when it is trying to access the given spreadsheet.

* cleaned up code.
  • Loading branch information
kimsama committed Aug 9, 2016
1 parent aa465fc commit 013acac
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,10 @@ public DatabaseClient(string username, string password) {
var docService = new DocumentsService("database");
docService.RequestFactory = requestFactory;

//@kims
//docService.setUserCredentials(username, password);
documentService = docService;

var ssService = new SpreadsheetsService("database");

//@kims
//ssService.setUserCredentials(username, password);

ssService.RequestFactory = requestFactory;
spreadsheetService = ssService;
}
Expand All @@ -51,26 +46,25 @@ public IDatabase CreateDatabase(string name) {
}
}

public IDatabase GetDatabase(string name) {
/*
var feed = DocumentService.Query(new SpreadsheetQuery {TitleExact = true, Title = name });
if (feed.Entries.Count == 0)
return null;
return new Database(this, feed.Entries[0]);
*/
/// <summary>
/// @kims 2016.08.09. Added second parameter to pass error message by reference.
/// </summary>
/// <returns>Null, if any error has been occured.</returns>
public IDatabase GetDatabase(string name, ref string error) {

Google.GData.Spreadsheets.SpreadsheetQuery query = new Google.GData.Spreadsheets.SpreadsheetQuery();

// Make a request to the API and get all spreadsheets.
SpreadsheetsService service = spreadsheetService as SpreadsheetsService;

SpreadsheetFeed feed = service.Query(query);

if (feed.Entries.Count == 0)
{
//Debug.Log("There are no spreadsheets in your docs.");
error = @"There are no spreadsheets in your docs.";
return null;
}

//SpreadsheetEntry spreadsheet = null;
AtomEntry spreadsheet = null;
foreach (AtomEntry sf in feed.Entries)
{
Expand All @@ -80,7 +74,7 @@ public IDatabase GetDatabase(string name) {

if (spreadsheet == null)
{
//Debug.Log("There is no such spreadsheet with such title in your docs.");
error = @"There is no such spreadsheet with such title in your docs.";
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public interface IDatabaseClient {
/// </summary>
/// <param name="name"></param>
/// <returns>IDocument instance or null if not found</returns>
IDatabase GetDatabase(string name);
IDatabase GetDatabase(string name, ref string error);
}
}
10 changes: 7 additions & 3 deletions Assets/QuickSheet/GDataPlugin/Editor/GoogleMachineEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,15 @@ private void DoCellQuery(OnEachCell onCell)
if (string.IsNullOrEmpty(machine.WorkSheetName))
return;

var db = client.GetDatabase(machine.SpreadSheetName);
string error = string.Empty;
var db = client.GetDatabase(machine.SpreadSheetName, ref error);
if (db == null)
{
string message = string.Format(@"The given spreadsheet '{0}' or worksheet '{1}' does not exist. Note that the name is case sensitive.",
machine.SpreadSheetName, machine.WorkSheetName);
string message = string.Empty;
if (string.IsNullOrEmpty(error))
message = @"Unknown error.";
else
message = string.Format(@"{0}", error);
EditorUtility.DisplayDialog("Error", message, "OK");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public class $ClassName : BaseGoogleEditor<$WorkSheetClassName>
$WorkSheetClassName targetData = target as $WorkSheetClassName;

var client = new DatabaseClient("", "");
var db = client.GetDatabase(targetData.SheetName) ?? client.CreateDatabase(targetData.SheetName);
string error = string.Empty;
var db = client.GetDatabase(targetData.SheetName, ref error);
var table = db.GetTable<$DataClassName>(targetData.WorksheetName) ?? db.CreateTable<$DataClassName>(targetData.WorksheetName);

List<$DataClassName> myDataList = new List<$DataClassName>();
Expand Down

0 comments on commit 013acac

Please sign in to comment.