Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Assets/AppServices/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ For detailed instructions read my developer blog on [how to setup Azure App Serv
API | Description
--- | -----------
Login | Client-directed login using access token.
InvokeApi | Get custom API
InvokeApi | Invoke custom API (Easy API) using GET, POST, PUT, PATCH or DELETE

### MobileServiceTable
API | Description
Expand Down
12 changes: 11 additions & 1 deletion Assets/AppServices/client/IAzureMobileServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,18 @@ public interface IAzureMobileServiceClient
//void Login(MobileServiceAuthenticationProvider provider);

/// <summary>
/// TODO: Custom API
/// Invokes a custom API using GET HTTP method
/// </summary>
void InvokeApi<T>(string apiName, Action<IRestResponse<T>> callback = null) where T : new();

/// <summary>
/// Invokes a custom API for HTTP Methods: GET, POST, PUT, PATCH, DELETE
/// </summary>
void InvokeApi<T>(string apiName, Method httpMethod, Action<IRestResponse<T>> callback = null) where T : new();

/// <summary>
/// Invokes a custom API with body object
/// </summary>
void InvokeApi<T> (string apiName, Method httpMethod, T body, Action<IRestResponse<T>> callback = null) where T : new();
}
}
30 changes: 25 additions & 5 deletions Assets/AppServices/client/MobileServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,36 @@ public void Login(MobileServiceAuthenticationProvider provider)
//*/

/// <summary>
/// TODO: Implement custom API (using GET request)
/// GET custom API
/// </summary>
public void InvokeApi<T>(string apiName, Action<IRestResponse<T>> callback = null) where T : new()
{
string uri = URI_API + apiName;
ZumoRequest request = new ZumoRequest(this, uri, Method.GET);
Debug.Log( "Custom API Request Uri: " + uri );
this.ExecuteAsync(request, callback);
InvokeApi<T> (apiName, Method.GET, callback);
}

/// <summary>
/// Invokes custom API for HTTP Methods: GET, POST, PUT, PATCH, DELETE
/// </summary>
public void InvokeApi<T>(string apiName, Method httpMethod, Action<IRestResponse<T>> callback = null) where T : new()
{
string uri = URI_API + apiName;
ZumoRequest request = new ZumoRequest(this, uri, httpMethod);
Debug.Log( httpMethod.ToString() + " custom API Request Uri: " + uri );
this.ExecuteAsync(request, callback);
}

/// <summary>
/// Invokes custom API with body
/// </summary>
public void InvokeApi<T>(string apiName, Method httpMethod, T body, Action<IRestResponse<T>> callback = null) where T : new()
{
string uri = URI_API + apiName;
ZumoRequest request = new ZumoRequest(this, uri, httpMethod);
request.AddBody (body);
Debug.Log( httpMethod.ToString() + " custom API Request Uri: " + uri );
this.ExecuteAsync(request, callback);
}

/// <summary>
/// When you copy the URL is is 'http' by default, but its preferable to use 'https'
/// </summary>
Expand Down
14 changes: 7 additions & 7 deletions Assets/Scripts/HighscoresDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,15 @@ public void GetAllHighscores()

private void GetPageHighscores()
{
CustomQuery query = new CustomQuery ("", "score desc", _noPageResults, _skip, "id,username,score"); //CustomQuery.OrderBy ("score desc");
_table.Query<NestedResults<Highscore>>(query, OnReadNestedResultsCompleted); //Query(query);
CustomQuery query = new CustomQuery ("", "score desc", _noPageResults, _skip, "id,username,score");
_table.Query<NestedResults<Highscore>>(query, OnReadNestedResultsCompleted);
}

public void GetTopHighscores()
{
DateTime today = DateTime.Today;
string day = today.ToString("s");
string filter = string.Format("createdAt gt '{0}Z'", day); //string.Format("score gt {0}", 999);
string filter = string.Format("createdAt gt '{0}Z'", day);
Debug.Log ("filter:" + filter);
string orderBy = "score desc";
CustomQuery query = new CustomQuery(filter,orderBy,10);
Expand All @@ -263,7 +263,7 @@ public void GetTopHighscores()
public void GetUsernameHighscore()
{
Highscore score = GetScore ();
string filter = string.Format("username eq '{0}'", score.username); // string.Format("startswith(username,'{0}')", score.username);
string filter = string.Format("username eq '{0}'", score.username);
string orderBy = "score desc";
CustomQuery query = new CustomQuery(filter,orderBy);
Query(query);
Expand Down Expand Up @@ -308,12 +308,12 @@ private void OnLookupCompleted(IRestResponse<Highscore> response)
/// </summary>
public void Hello()
{
_client.InvokeApi<Message>("hello", OnCustomApiCompleted);
_client.InvokeApi<Message>("hello", Method.GET, OnCustomApiCompleted);
}

public void GenerateScores()
{
_client.InvokeApi<Message>("GenerateScores", OnCustomApiCompleted);
_client.InvokeApi<Message>("GenerateScores", Method.POST, OnCustomApiCompleted);
}

private void OnCustomApiCompleted(IRestResponse<Message> response)
Expand Down Expand Up @@ -472,7 +472,7 @@ public int GetNumberOfRowsForTableView(TableView tableView)

public float GetHeightForRowInTableView(TableView tableView, int row)
{
return (_cellPrefab.transform as RectTransform).rect.height; //50.0f;
return (_cellPrefab.transform as RectTransform).rect.height;
}

public TableViewCell GetCellForRowInTableView(TableView tableView, int row)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ table.insert(function (context) {
## Setup Azure App Services custom APIs with **Easy APIs**
With [Azure App Services](https://portal.azure.com/) you can create custom APIs using **Easy APIs**.

1. Create a 'hello' api to say hello! (Example Easy API message script below)
2. Create a 'GenerateScores' api to generate 10 random scores. (Example Easy API query script below)
1. Create a 'hello' api (using "get" method) to say hello! (Example Easy API message script below)
2. Create a 'GenerateScores' api (using "post" method) to generate 10 random scores. (Example Easy API query script below)

#### Easy API 'hello' script (*api/hello.js*)
```node
Expand All @@ -67,7 +67,7 @@ module.exports = {
```node
var util = require('util');
module.exports = {
"get": function (req, res, next) {
"post": function (req, res, next) {
var insert = "INSERT INTO Highscores (username,score) VALUES ";
var i = 10;
while (i--) {
Expand Down