Skip to content

Commit 3c8edd8

Browse files
committed
Initial commit
0 parents  commit 3c8edd8

File tree

78 files changed

+3846
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+3846
-0
lines changed

.gitignore

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/[Ll]ibrary/
2+
/[Tt]emp/
3+
/[Oo]bj/
4+
/[Bb]uild/
5+
/[Bb]uilds/
6+
/Assets/AssetStoreTools*
7+
8+
# Autogenerated VS/MD/Consulo solution and project files
9+
ExportedObj/
10+
.consulo/
11+
*.csproj
12+
*.unityproj
13+
*.sln
14+
*.suo
15+
*.tmp
16+
*.user
17+
*.userprefs
18+
*.pidb
19+
*.booproj
20+
*.svd
21+
22+
23+
# Unity3D generated meta files
24+
*.pidb.meta
25+
26+
# Unity3D Generated File On Crash Reports
27+
sysinfo.txt
28+
29+
# Builds
30+
*.apk
31+
*.unitypackage
32+
33+
**/SecretData.cs*

Assets/Scripts.meta

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/Creatubbles.meta

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/Creatubbles/Api.meta

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
//
2+
// CreatubblesApiClient.cs
3+
// CreatubblesApiClient
4+
//
5+
// Copyright (c) 2016 Creatubbles Pte. Ltd.
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
// THE SOFTWARE.
24+
25+
using System;
26+
using UnityEngine;
27+
using UnityEngine.Networking;
28+
29+
namespace Creatubbles.Api
30+
{
31+
public class CreatubblesApiClient
32+
{
33+
private IApiConfiguration configuration;
34+
public ISecureStorage secureStorage; // TODO - eventually make it private
35+
36+
public CreatubblesApiClient(IApiConfiguration configuration, ISecureStorage secureStorage)
37+
{
38+
this.configuration = configuration;
39+
this.secureStorage = secureStorage;
40+
}
41+
42+
// make request methods intance methods
43+
public UnityWebRequest CreatePostAuthenticationApplicationTokenRequest()
44+
{
45+
string url = RequestUrl("/oauth/token");
46+
WWWForm data = new WWWForm();
47+
data.AddField("grant_type", "client_credentials");
48+
data.AddField("client_id", configuration.AppId);
49+
data.AddField("client_secret", configuration.AppSecret);
50+
51+
UnityWebRequest request = UnityWebRequest.Post(url, data);
52+
request.downloadHandler = new DownloadHandlerBuffer();
53+
54+
return request;
55+
}
56+
57+
public UnityWebRequest CreatePostAuthenticationUserTokenRequest(string username, string password)
58+
{
59+
string url = RequestUrl("/oauth/token");
60+
WWWForm data = new WWWForm();
61+
data.AddField("grant_type", "password");
62+
data.AddField("client_id", configuration.AppId);
63+
data.AddField("client_secret", configuration.AppSecret);
64+
data.AddField("username", username);
65+
data.AddField("password", password);
66+
67+
UnityWebRequest request = UnityWebRequest.Post(url, data);
68+
request.downloadHandler = new DownloadHandlerBuffer();
69+
70+
return request;
71+
}
72+
73+
public UnityWebRequest CreateGetLandingUrlsRequest(string applicationToken)
74+
{
75+
string url = RequestUrl("/landing_urls");
76+
UnityWebRequest request = UnityWebRequest.Get(url);
77+
SetAuthorizationHeaderBearerToken(request, applicationToken);
78+
request.downloadHandler = new DownloadHandlerBuffer();
79+
80+
return request;
81+
}
82+
83+
public UnityWebRequest CreateGetLoggedInUserRequest(string userToken)
84+
{
85+
string url = RequestUrl("/users/me");
86+
UnityWebRequest request = UnityWebRequest.Get(url);
87+
SetAuthorizationHeaderBearerToken(request, userToken);
88+
request.downloadHandler = new DownloadHandlerBuffer();
89+
90+
return request;
91+
}
92+
93+
public UnityWebRequest CreateNewCreationRequest(string userToken, NewCreationData creationData)
94+
{
95+
string url = RequestUrl("/creations");
96+
WWWForm data = new WWWForm();
97+
if (creationData.name != null)
98+
{
99+
data.AddField("name", creationData.name);
100+
}
101+
if (creationData.creatorIds != null)
102+
{
103+
string creatorIds = String.Join(",", creationData.creatorIds);
104+
data.AddField("creator_ids", creatorIds);
105+
}
106+
if (creationData.HasCreationMonth)
107+
{
108+
data.AddField("created_at_month", creationData.creationMonth);
109+
}
110+
if (creationData.HasCreationYear)
111+
{
112+
data.AddField("created_at_year", creationData.creationYear);
113+
}
114+
if (creationData.reflectionText != null)
115+
{
116+
data.AddField("reflection_text", creationData.reflectionText);
117+
}
118+
if (creationData.reflectionVideoUrl != null)
119+
{
120+
data.AddField("reflection_video_url", creationData.reflectionVideoUrl);
121+
}
122+
123+
UnityWebRequest request = UnityWebRequest.Post(url, data);
124+
SetAuthorizationHeaderBearerToken(request, userToken);
125+
request.downloadHandler = new DownloadHandlerBuffer();
126+
127+
return request;
128+
}
129+
130+
public UnityWebRequest CreateGetCreationRequest(string userToken, string creationId)
131+
{
132+
string url = RequestUrl("/creations/" + creationId);
133+
UnityWebRequest request = UnityWebRequest.Get(url);
134+
SetAuthorizationHeaderBearerToken(request, userToken);
135+
request.downloadHandler = new DownloadHandlerBuffer();
136+
137+
return request;
138+
}
139+
140+
public UnityWebRequest CreatePostCreationUploadRequest(string userToken, string creationId, UploadExtension extension = UploadExtension.JPG)
141+
{
142+
string url = RequestUrl("/creations/" + creationId + "/uploads");
143+
WWWForm data = new WWWForm();
144+
data.AddField("extension", extension.StringValue());
145+
146+
UnityWebRequest request = UnityWebRequest.Post(url, data);
147+
SetAuthorizationHeaderBearerToken(request, userToken);
148+
request.downloadHandler = new DownloadHandlerBuffer();
149+
150+
return request;
151+
}
152+
153+
public UnityWebRequest CreatePutUploadFileRequest(string userToken, string url, string contentType, byte[] data)
154+
{
155+
UnityWebRequest request = UnityWebRequest.Put(url, data);
156+
request.SetRequestHeader("Content-Type", contentType);
157+
request.downloadHandler = new DownloadHandlerBuffer();
158+
159+
return request;
160+
}
161+
162+
// TODO - abortedWithMessage - argument included when upload fails; include the body returned by the failed upload attempt or ‘user’ in case the user aborted the upload
163+
// API doc: https://stateoftheart.creatubbles.com/api/#update-creation-upload
164+
public UnityWebRequest CreatePutUploadFinishedRequest(string userToken, string pingUrl, string abortedWithMessage = null)
165+
{
166+
UnityWebRequest request;
167+
if (abortedWithMessage != null)
168+
{
169+
WWWForm parameters = new WWWForm();
170+
parameters.AddField("aborted_with", abortedWithMessage);
171+
request = UnityWebRequest.Put(pingUrl, parameters.data);
172+
}
173+
else
174+
{
175+
request = new UnityWebRequest(pingUrl);
176+
}
177+
request.method = UnityWebRequest.kHttpVerbPUT;
178+
SetAuthorizationHeaderBearerToken(request, userToken);
179+
request.downloadHandler = new DownloadHandlerBuffer();
180+
181+
return request;
182+
}
183+
184+
private string RequestUrl(string path)
185+
{
186+
return configuration.BaseUrl + "/" + configuration.ApiVersion + path;
187+
}
188+
189+
private void SetAuthorizationHeaderBearerToken(UnityWebRequest request, string token)
190+
{
191+
request.SetRequestHeader("Authorization", "Bearer " + token);
192+
}
193+
}
194+
}

Assets/Scripts/Creatubbles/Api/CreatubblesApiClient.cs.meta

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/Creatubbles/Api/Data.meta

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//
2+
// CreationAttributesDto.cs
3+
// CreatubblesApiClient
4+
//
5+
// Copyright (c) 2016 Creatubbles Pte. Ltd.
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
// THE SOFTWARE.
24+
25+
using System;
26+
27+
namespace Creatubbles.Api
28+
{
29+
[Serializable]
30+
public class CreationAttributesDto
31+
{
32+
public string name;
33+
public bool approved;
34+
public string approval_status; // TODO - enum - Possible values: “approved”, “unapproved”, “rejected”
35+
public string created_at_age;
36+
// JsonUtility doesn't support dictionaries yet, need to use different deserializer to support below
37+
// public created_at_age_per_creator;
38+
// {
39+
// "oCRxzp9F": "at 14y",
40+
// "vff379a2": "at 9y"
41+
// },
42+
public string image; // TODO - expand to object - see iOS
43+
public int image_status; // TODO - enum - 1: “empty”; 2: “processing”; 3: “ready”
44+
public int bubbles_count;
45+
public int comments_count;
46+
public int views_count;
47+
public string last_bubbled_at; // TODO - DateTime
48+
public string last_commented_at; // TODO - DateTime
49+
public string last_submitted_at; // TODO - DateTime
50+
public string short_url;
51+
public string created_at; // TODO - DateTime
52+
// TODO - for more attributes see https://stateoftheart.creatubbles.com/api/#creation-details
53+
}
54+
}
55+

Assets/Scripts/Creatubbles/Api/Data/CreationAttributesDto.cs.meta

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// CreationDataType.cs
3+
// CreatubblesApiClient
4+
//
5+
// Copyright (c) 2016 Creatubbles Pte. Ltd.
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
// THE SOFTWARE.
24+
25+
namespace Creatubbles.Api
26+
{
27+
public enum CreationDataType
28+
{
29+
Image = 0,
30+
Url = 1,
31+
Data = 2
32+
}
33+
}

Assets/Scripts/Creatubbles/Api/Data/CreationDataType.cs.meta

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)