Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.1.0 #72

Merged
merged 11 commits into from
Feb 14, 2020
6 changes: 4 additions & 2 deletions Assets/Config/config-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"repeatRate":10,
"repeatTime":"hours",
"plannerBackgroundColour":"#FFFFFF",
"plannerTextColour": "#000000"
"plannerTextColour": "#000000",
"apiKey": ""
},
"someone@gmail.com": {
"title": "Tom's Calendar",
Expand Down Expand Up @@ -79,7 +80,8 @@
"titleColour": "#FFFFFF",
"repeatRate": 2,
"repeatTime": "hours",
"groupId": "groupId"
"groupId": "groupId",
"apiKey": ""
},
"trains": {
"title": "Trains",
Expand Down
1 change: 1 addition & 0 deletions Assets/Scripts/Dialog/Popup Dialog/AddNewRecipeDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ private IEnumerator UploadNewRecipeRoutine()

json.Add("name", recipeName.text);
json.Add("ingredients", ingredientsArray);
json.Add("apiKey", Config.instance.GetWidgetConfig()[FindObjectOfType<FoodPlanner>().GetWidgetConfigKey()]["apiKey"]);

UnityWebRequest request = Postman.CreatePostRequest(Endpoints.RECIPES_ADD, json);
yield return request.SendWebRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private IEnumerator PopulateRecipesRoutine()
{
ClearExistingRecipes();

UnityWebRequest request = Postman.CreateGetRequest(Endpoints.RECIPES);
UnityWebRequest request = Postman.CreateGetRequest(Endpoints.RECIPES(Config.instance.GetWidgetConfig()[FindObjectOfType<FoodPlanner>().GetWidgetConfigKey()]["apiKey"]));
yield return request.SendWebRequest();
string response = request.downloadHandler.text;

Expand Down
11 changes: 8 additions & 3 deletions Assets/Scripts/Requests/Endpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
public class Endpoints
{
private static readonly string RECIPE_MANAGER = "https://home-dashboard-recipe-manager.herokuapp.com";

public static readonly string TODOIST_TASKS = "https://api.todoist.com/rest/v1/tasks";
public static readonly string RECIPES = RECIPE_MANAGER + "/recipes";
public static readonly string RECIPES_ADD = RECIPE_MANAGER + "/recipes/add";
public static readonly string PLANNER = RECIPE_MANAGER + "/planner";
public static readonly string PLANNER_ADD = RECIPE_MANAGER + "/planner/add";

public static string RECIPES(string apiKey)
{
return RECIPE_MANAGER + "/recipes?apiKey=" + apiKey;
}

public static string TRAIN_DEPARTURES(string stationCode, int numberOfResults, string apiKey)
{
return "https://home-dashboard-train-manager.herokuapp.com/departures?stationCode=" + stationCode + "&numberOfResults=" + numberOfResults + "&apiKey=" + apiKey;
Expand All @@ -34,9 +39,9 @@ public static string WEATHER(string apiKey, string latitude, string longitude)
return "https://api.darksky.net/forecast/" + apiKey + "/" + latitude + "," + longitude + "?units=uk";
}

public static string SPLITWISE(string groupId)
public static string SPLITWISE(string groupId, string apiKey)
{
return "https://home-dashboard-splitwise-mngr.herokuapp.com/group?groupId=" + groupId;
return "https://home-dashboard-splitwise-mngr.herokuapp.com/group?groupId=" + groupId + "&apiKey=" + apiKey;
}
}
}
2 changes: 1 addition & 1 deletion Assets/Widgets/Food Planner/FoodPlanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private IEnumerator AddToShoppingListRoutine()
foreach (PlannerEntry entry in plannerEntries)
{
// Get the ingredients by recipe
UnityWebRequest request = Postman.CreateGetRequest(Endpoints.RECIPES + "?name=" + entry.GetRecipeName());
UnityWebRequest request = Postman.CreateGetRequest(Endpoints.RECIPES(Config.instance.GetWidgetConfig()[GetWidgetConfigKey()]["apiKey"]) + "&name=" + entry.GetRecipeName());
yield return request.SendWebRequest();

JSONNode json = JSON.Parse(request.downloadHandler.text);
Expand Down
178 changes: 178 additions & 0 deletions Assets/Widgets/Food Planner/Planner Entry/Planner Entry.prefab
Original file line number Diff line number Diff line change
@@ -1,5 +1,105 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &1010729676822046605
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5339644471310249574}
- component: {fileID: 2001669543973521186}
- component: {fileID: 6129861246054940873}
m_Layer: 5
m_Name: Clear
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &5339644471310249574
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1010729676822046605}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 5691326883058657595}
m_Father: {fileID: 1013217550476370056}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 1.0588, y: 0.2427}
m_SizeDelta: {x: -2.1178, y: -0.4853}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &2001669543973521186
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1010729676822046605}
m_CullTransparentMesh: 0
--- !u!114 &6129861246054940873
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1010729676822046605}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 0
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_SelectedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_SelectedTrigger: Selected
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 0}
m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 1013217550476370057}
m_MethodName: ClearRecipe
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!1 &1013217548956904210
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -364,6 +464,7 @@ RectTransform:
m_Children:
- {fileID: 1013217549811931801}
- {fileID: 1013217548956904211}
- {fileID: 5339644471310249574}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
Expand Down Expand Up @@ -425,3 +526,80 @@ MonoBehaviour:
recipe: {fileID: 1013217549817886997}
recipeBackground: {fileID: 1013217550476370058}
dayBackground: {fileID: 1013217549811931802}
--- !u!1 &5526285332960553496
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5691326883058657595}
- component: {fileID: 3123804056909923364}
- component: {fileID: 3125227728032329774}
m_Layer: 5
m_Name: Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &5691326883058657595
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5526285332960553496}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.1, y: 0.075, z: 0.1}
m_Children: []
m_Father: {fileID: 5339644471310249574}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: -0.0000020861626, y: -0.000003889203}
m_SizeDelta: {x: 3.2728, y: 3.9257}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &3123804056909923364
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5526285332960553496}
m_CullTransparentMesh: 0
--- !u!114 &3125227728032329774
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5526285332960553496}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 0, b: 0, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 12800000, guid: d9f34d8218de7804b9cbc0e3167c9854, type: 3}
m_FontSize: 2
m_FontStyle: 1
m_BestFit: 0
m_MinSize: 0
m_MaxSize: 282
m_Alignment: 4
m_AlignByGeometry: 1
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: X
41 changes: 37 additions & 4 deletions Assets/Widgets/Food Planner/Planner Entry/PlannerEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,22 @@ public class PlannerEntry : MonoBehaviour
[SerializeField] private Image recipeBackground;
[SerializeField] private Image dayBackground;

private string configKey;
private string apiKey;

private IEnumerator Start()
{
configKey = FindObjectOfType<FoodPlanner>().GetWidgetConfigKey();
apiKey = Config.instance.GetWidgetConfig()[configKey]["apiKey"];

string label = "";
foreach (char c in day.ToString().Substring(0, 3).ToUpper())
{
label += c + "\n";
}
dayText.text = label;

JSONObject json = new JSONObject();
json.Add("day", day.ToString());

UnityWebRequest request = Postman.CreateGetRequest(Endpoints.PLANNER + "?day=" + day.ToString());
UnityWebRequest request = Postman.CreateGetRequest(Endpoints.PLANNER + "?day=" + day.ToString() + "&apiKey=" + Config.instance.GetWidgetConfig()[configKey]["apiKey"]);
yield return request.SendWebRequest();

recipe.text = JSON.Parse(request.downloadHandler.text)["planner"]["recipe"];
Expand Down Expand Up @@ -62,6 +65,7 @@ public IEnumerator SelectRecipeRoutine()
JSONObject json = new JSONObject();
json.Add("recipe", string.IsNullOrEmpty(recipe.text) ? " " : recipe.text);
json.Add("day", day.ToString());
json.Add("apiKey", apiKey);

UnityWebRequest request = Postman.CreatePostRequest(Endpoints.PLANNER_ADD, json);
yield return request.SendWebRequest();
Expand All @@ -70,6 +74,35 @@ public IEnumerator SelectRecipeRoutine()
}
}

/// <summary>
/// Quick method to clear the entry
/// </summary>
public void ClearRecipe()
{
StartCoroutine(ClearRecipeRoutine());
}

private IEnumerator ClearRecipeRoutine()
{
JSONObject json = new JSONObject();
json.Add("recipe", " ");
json.Add("day", day.ToString());
json.Add("apiKey", apiKey);

UnityWebRequest request = Postman.CreatePostRequest(Endpoints.PLANNER_ADD, json);
yield return request.SendWebRequest();

JSONNode response = JSON.Parse(request.downloadHandler.text);
if(response["status"] == 200)
{
recipe.text = "";
}
else
{
WidgetLogger.instance.Log("Could not clear recipe: " + response["message"]);
}
}

public string GetRecipeName()
{
return recipe.text;
Expand Down
4 changes: 3 additions & 1 deletion Assets/Widgets/Splitwise/Splitwise.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ public class Splitwise : Widget
[SerializeField] private Text allSettledUp;

private string groupId;
private string apiKey;

public override void ReloadConfig()
{
JSONNode config = Config.instance.GetWidgetConfig()[this.GetWidgetConfigKey()];
groupId = config["groupId"];
apiKey = config["apiKey"];
}

public override void Run()
Expand All @@ -31,7 +33,7 @@ public override void Run()

private IEnumerator RunRoutine()
{
UnityWebRequest request = Postman.CreateGetRequest(Endpoints.SPLITWISE(groupId));
UnityWebRequest request = Postman.CreateGetRequest(Endpoints.SPLITWISE(groupId, apiKey));
yield return request.SendWebRequest();

bool ok = request.error == null ? true : false;
Expand Down
2 changes: 1 addition & 1 deletion ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ PlayerSettings:
16:10: 1
16:9: 1
Others: 1
bundleVersion: 5.0.2
bundleVersion: 5.1.0
preloadedAssets: []
metroInputSource: 0
wsaTransparentSwapchain: 0
Expand Down
4 changes: 2 additions & 2 deletions ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m_EditorVersion: 2019.3.0f6
m_EditorVersionWithRevision: 2019.3.0f6 (27ab2135bccf)
m_EditorVersion: 2019.3.1f1
m_EditorVersionWithRevision: 2019.3.1f1 (89d6087839c2)