Skip to content

Commit 2e0c079

Browse files
committed
Basic Unity REST implementation
1 parent f5acf44 commit 2e0c079

8 files changed

Lines changed: 157 additions & 109 deletions

File tree

Allow2.cs

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
//
2+
// Allow2Unity
3+
//
4+
// Created by Andrew Longhorn in early 2019.
5+
// Copyright © 2019 Allow2 Pty Ltd. All rights reserved.
6+
//
7+
// LICENSE:
8+
// See LICENSE file in root directory
9+
//
10+
11+
using Application;
12+
using UnityEngine;
13+
using UnityEngine.Networking;
14+
15+
namespace Allow2
16+
{
17+
18+
/// <summary>
19+
/// Access functionality of the Allow2 platform easily.
20+
/// </summary>
21+
public static class Allow2
22+
{
23+
24+
public static string deviceToken = "Not Set";
25+
public static EnvType env = EnvType.Production;
26+
27+
//
28+
// cannot instantiate this class
29+
//
30+
//protected Allow2() {
31+
//}
32+
33+
public static string apiUrl
34+
{
35+
get
36+
{
37+
switch (env)
38+
{
39+
//case EnvType.Sandbox:
40+
//return "https://sandbox-api.allow2.com"
41+
case EnvType.Staging:
42+
return "https://staging-api.allow2.com";
43+
default:
44+
return "https://api.allow2.com";
45+
}
46+
}
47+
}
48+
49+
public static string serviceUrl
50+
{
51+
get
52+
{
53+
switch (env)
54+
{
55+
//case EnvType.Sandbox:
56+
//return "https://sandbox-service.allow2.com"
57+
case EnvType.Staging:
58+
return "https://staging-service.allow2.com";
59+
default:
60+
return "https://service.allow2.com";
61+
}
62+
}
63+
}
64+
65+
//public static void Pair(string user, // ie: "fred@gmail.com",
66+
// string pass, // ie: "my super secret password",
67+
// string deviceToken, // ie: "346-34269hcubi-187gigi8g-14i3ugkug",
68+
// string deviceName // ie: "Fred's iPhone"
69+
// ) {
70+
// WWWForm form = new WWWForm();
71+
// form.AddField("user", user);
72+
// form.AddField("pass", pass);
73+
// form.AddField("deviceToken", deviceToken);
74+
// form.AddField("name", deviceName);
75+
76+
// using (UnityWebRequest www = UnityWebRequest.Post(apiUrl + "/api/pairDevice", form))
77+
// {
78+
// yield return www.SendWebRequest();
79+
80+
// if (www.isNetworkError || www.isHttpError)
81+
// {
82+
// Debug.Log(www.error);
83+
// }
84+
// else
85+
// {
86+
// Debug.Log(www.downloadHandler.text);
87+
// }
88+
// }
89+
//}
90+
91+
//public static void Check(int userId,
92+
// string pairToken, // ie: "98hbieg87-ilulieugil-dilufkucy"
93+
// string deviceToken, // ie: "iug893-kjg-fiug23"
94+
// string timezone, // ie: "Australia/Brisbane"
95+
// int childId,
96+
// int[] activities,
97+
// bool log = false,
98+
// bool staging = false // INTERNAL USE ONLY!
99+
// ) {
100+
// UnityWebRequest www = UnityWebRequest.Get("http://www.my-server.com");
101+
// yield return www.SendWebRequest();
102+
103+
// if (www.isNetworkError || www.isHttpError)
104+
// {
105+
// Debug.Log(www.error);
106+
// }
107+
// else
108+
// {
109+
// // Show results as text
110+
// Debug.Log(www.downloadHandler.text);
111+
112+
// // Or retrieve results as binary data
113+
// byte[] results = www.downloadHandler.data;
114+
// }
115+
//}
116+
}
117+
}

Allow2.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Allow2/Allow2.cs

Lines changed: 0 additions & 35 deletions
This file was deleted.

Allow2/Allow2.csproj

Lines changed: 0 additions & 44 deletions
This file was deleted.

Allow2/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.

Allow2/packages.config

Lines changed: 0 additions & 4 deletions
This file was deleted.

EnumeratedTypes.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
namespace Application
3+
{
4+
public enum EnvType { Production, /*Sandbox,*/ Staging }
5+
6+
public enum Activity {
7+
Internet = 1,
8+
Computer = 2,
9+
Gaming = 3,
10+
Message = 4,
11+
JunkFood = 5,
12+
Lollies = 6,
13+
Electricity = 7,
14+
ScreenTime = 8,
15+
Social = 9,
16+
PhoneTime = 10
17+
}
18+
}

EnumeratedTypes.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)