-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 PinealCtx | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Unity RestClient | ||
|
||
Send HTTP requests in unity through Restful. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace PinealCtx.RestClient.Attribute | ||
{ | ||
[System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.Field)] | ||
public class RestFormProperty : System.Attribute | ||
{ | ||
public RestFormProperty(string name) => Name = name; | ||
|
||
public string Name { get; } | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace PinealCtx.RestClient.Attribute | ||
{ | ||
[System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.Field)] | ||
public class RestHeaderProperty : System.Attribute | ||
{ | ||
public RestHeaderProperty(string name) => Name = name; | ||
|
||
public string Name { get; } | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace PinealCtx.RestClient.Attribute | ||
{ | ||
[System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.Field)] | ||
public class RestQueryProperty : System.Attribute | ||
{ | ||
public RestQueryProperty(string name) => Name = name; | ||
|
||
public string Name { get; } | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace PinealCtx.RestClient | ||
{ | ||
public enum Method | ||
{ | ||
Get, | ||
Post | ||
} | ||
|
||
public static class EnumExtensions | ||
{ | ||
public static string String(this Method enumValue) | ||
{ | ||
return enumValue switch | ||
{ | ||
Method.Get => "GET", | ||
Method.Post => "POST", | ||
_ => "GET" | ||
}; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace PinealCtx.RestClient | ||
{ | ||
public static class KnownContentTypes | ||
{ | ||
public const string Json = "application/json"; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace PinealCtx.RestClient | ||
{ | ||
public static class KnownHeaders | ||
{ | ||
public const string Authorization = "Authorization"; | ||
public const string Accept = "Accept"; | ||
public const string Allow = "Allow"; | ||
public const string Expires = "Expires"; | ||
public const string ContentDisposition = "Content-Disposition"; | ||
public const string ContentEncoding = "Content-Encoding"; | ||
public const string ContentLanguage = "Content-Language"; | ||
public const string ContentLength = "Content-Length"; | ||
public const string ContentLocation = "Content-Location"; | ||
public const string ContentRange = "Content-Range"; | ||
public const string ContentType = "Content-Type"; | ||
public const string LastModified = "Last-Modified"; | ||
public const string ContentMD5 = "Content-MD5"; | ||
public const string Host = "Host"; | ||
public const string UserAgent = "User-Agent"; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace PinealCtx.RestClient.Param | ||
{ | ||
public class BodyParam : IParam | ||
{ | ||
public string ContentType { get; set; } | ||
public byte[] Data { get; set; } | ||
|
||
public BodyParam(string contentType, byte[] data) | ||
{ | ||
ContentType = contentType; | ||
Data = data; | ||
} | ||
|
||
public ParamType ParamType() | ||
{ | ||
return Param.ParamType.Body; | ||
} | ||
|
||
public static BodyParam BuildJson(object obj) | ||
{ | ||
var json = JsonConvert.SerializeObject(obj); | ||
var bytes = new System.Text.UTF8Encoding().GetBytes(json); | ||
return new BodyParam(KnownContentTypes.Json, bytes); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using UnityEngine.Networking; | ||
|
||
namespace PinealCtx.RestClient.Param | ||
{ | ||
public class FormParam : IParam | ||
{ | ||
public FormParam(IMultipartFormSection section) => Section = section; | ||
|
||
public FormParam(string name, string value) : this(new MultipartFormDataSection(name, value)) | ||
{ | ||
} | ||
|
||
public FormParam(string name, byte[] value, string fileName = "", string contentType = "") : this( | ||
new MultipartFormFileSection(name, value, fileName, contentType)) | ||
{ | ||
} | ||
|
||
public FormParam(string name, FormFile file) : this(name, file.Data, file.FileName, file.ContentType) | ||
{ | ||
} | ||
|
||
public IMultipartFormSection Section { get; set; } | ||
|
||
public ParamType ParamType() => Param.ParamType.Form; | ||
} | ||
|
||
public class FormFile | ||
{ | ||
public byte[] Data { get; set; } | ||
public string FileName { get; set; } | ||
public string ContentType { get; set; } | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace PinealCtx.RestClient.Param | ||
{ | ||
public class HeaderParam : IParam | ||
{ | ||
public HeaderParam(string name, string value) | ||
{ | ||
Name = name; | ||
Value = value; | ||
} | ||
|
||
public string Name { get; set; } | ||
public string Value { get; set; } | ||
|
||
public ParamType ParamType() => Param.ParamType.Header; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace PinealCtx.RestClient.Param | ||
{ | ||
public interface IParam | ||
{ | ||
ParamType ParamType(); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace PinealCtx.RestClient.Param | ||
{ | ||
public enum ParamType | ||
{ | ||
Query, | ||
Header, | ||
Body, | ||
Form | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using UnityEngine.Networking; | ||
|
||
namespace PinealCtx.RestClient.Param | ||
{ | ||
public class QueryParam : IParam | ||
{ | ||
public QueryParam(string name, string value) | ||
{ | ||
Name = name; | ||
Value = value; | ||
} | ||
|
||
public string Name { get; set; } | ||
public string Value { get; set; } | ||
|
||
public ParamType ParamType() => Param.ParamType.Query; | ||
|
||
public override string ToString() | ||
{ | ||
return $"{UnityWebRequest.EscapeURL(Name)}={UnityWebRequest.EscapeURL(Value)}"; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.