Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #4 from LIMECAKE/csharp
Browse files Browse the repository at this point in the history
CSharp added
  • Loading branch information
AzelyFox authored Apr 22, 2020
2 parents e4e006f + 2db2e92 commit 1e4dfd3
Show file tree
Hide file tree
Showing 2 changed files with 318 additions and 0 deletions.
159 changes: 159 additions & 0 deletions CSHARP/Reviewer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Text;
using Newtonsoft.Json.Linq;

namespace Reviewer
{
public class Reviewer
{

public static void newReview(string key, Review review)
{
networkAsync(key, review);
}

private static async void networkAsync(string key, Review review)
{
try
{
UTF8Encoding encoding = new UTF8Encoding();

string postData = "service_key=" + key;
postData += "&review_user=" + review.getUser();
postData += "&review_tag=" + review.getTag();
postData += "&review_rating=" + review.getRating();
postData += "&review_title=" + review.getTitle();
postData += "&review_content=" + review.getContent();

byte[] data = encoding.GetBytes(postData);

WebRequest request = WebRequest.Create("https://api.devx.kr/Reviewer/v1/review_new.php");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.Headers["ContentLength"] = data.Length.ToString();

Stream stream = await request.GetRequestStreamAsync();
stream.Write(data, 0, data.Length);

WebResponse response = await request.GetResponseAsync();

stream = response.GetResponseStream();

if (stream == null)
{
try
{
Debug.WriteLine("CATCHER FAIL : response null");
}
catch (Exception e)
{

}
return;
}

StreamReader ar = new StreamReader(stream);

JObject resultObject = JObject.Parse(ar.ReadToEnd());

if (resultObject.GetValue("result").Value<int>() == 0)
{
try
{
Debug.WriteLine("CATCHER SUCCESS : " + resultObject.GetValue("review_index").Value<string>());
}
catch (Exception e)
{

}
}
else
{
Debug.WriteLine("CATCHER FAIL : " + resultObject.GetValue("error").Value<string>());
Debug.WriteLine("CATCHER FAIL : " + resultObject.GetValue("error_debug").Value<string>());
}
}
catch (Exception e)
{
try
{
Debug.WriteLine("CATCHER FAIL : " + e);
}
catch (Exception)
{
}
}
}
}

public class Review {
private readonly string TAG;
private readonly string USER;
private readonly double RATING;
private readonly string TITLE;
private readonly string CONTENT;

public class Builder {
public readonly string USER;
public readonly double RATING;
public string TAG = "";
public string TITLE = "";
public string CONTENT = "";

public Builder(string _user, double _rating) {
this.USER = _user;
this.RATING = _rating;
}

public Builder tag(string _tag) {
this.TAG = _tag;
return this;
}

public Builder title(string _title) {
this.TITLE = _title;
return this;
}

public Builder content(string _content) {
this.CONTENT = _content;
return this;
}

public Review build() {
return new Review(this);
}
}

private Review(Builder builder) {
TAG = builder.TAG;
USER = builder.USER;
RATING = builder.RATING;
TITLE = builder.TITLE;
CONTENT = builder.CONTENT;
}

public string getTag() {
return TAG;
}

public string getUser() {
return USER;
}

public double getRating() {
return RATING;
}

public string getTitle() {
return TITLE;
}

public string getContent() {
return CONTENT;
}
}
}
159 changes: 159 additions & 0 deletions CSHARP/ReviewerUnity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
using System;
using System.IO;
using System.Net;
using System.Text;
using Newtonsoft.Json.Linq;
using UnityEngine;

namespace ReviewerUnity
{
public class Reviewer
{

public static void newReview(string key, Review review)
{
networkAsync(key, review);
}

private static async void networkAsync(string key, Review review)
{
try
{
UTF8Encoding encoding = new UTF8Encoding();

string postData = "service_key=" + key;
postData += "&review_user=" + review.getUser();
postData += "&review_tag=" + review.getTag();
postData += "&review_rating=" + review.getRating();
postData += "&review_title=" + review.getTitle();
postData += "&review_content=" + review.getContent();

byte[] data = encoding.GetBytes(postData);

WebRequest request = WebRequest.Create("https://api.devx.kr/Reviewer/v1/review_new.php");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.Headers["ContentLength"] = data.Length.ToString();

Stream stream = await request.GetRequestStreamAsync();
stream.Write(data, 0, data.Length);

WebResponse response = await request.GetResponseAsync();

stream = response.GetResponseStream();

if (stream == null)
{
try
{
Debug.Log("CATCHER FAIL : response null");
}
catch (Exception e)
{

}
return;
}

StreamReader ar = new StreamReader(stream);

JObject resultObject = JObject.Parse(ar.ReadToEnd());

if (resultObject.GetValue("result").Value<int>() == 0)
{
try
{
Debug.Log("CATCHER SUCCESS : " + resultObject.GetValue("review_index").Value<string>());
}
catch (Exception e)
{

}
}
else
{
Debug.Log("CATCHER FAIL : " + resultObject.GetValue("error").Value<string>());
Debug.Log("CATCHER FAIL : " + resultObject.GetValue("error_debug").Value<string>());
}
}
catch (Exception e)
{
try
{
Debug.Log("CATCHER FAIL : " + e);
}
catch (Exception)
{
}
}
}
}

public class Review {
private readonly string TAG;
private readonly string USER;
private readonly double RATING;
private readonly string TITLE;
private readonly string CONTENT;

public class Builder {
public readonly string USER;
public readonly double RATING;
public string TAG = "";
public string TITLE = "";
public string CONTENT = "";

public Builder(string _user, double _rating) {
this.USER = _user;
this.RATING = _rating;
}

public Builder tag(string _tag) {
this.TAG = _tag;
return this;
}

public Builder title(string _title) {
this.TITLE = _title;
return this;
}

public Builder content(string _content) {
this.CONTENT = _content;
return this;
}

public Review build() {
return new Review(this);
}
}

private Review(Builder builder) {
TAG = builder.TAG;
USER = builder.USER;
RATING = builder.RATING;
TITLE = builder.TITLE;
CONTENT = builder.CONTENT;
}

public string getTag() {
return TAG;
}

public string getUser() {
return USER;
}

public double getRating() {
return RATING;
}

public string getTitle() {
return TITLE;
}

public string getContent() {
return CONTENT;
}
}
}

0 comments on commit 1e4dfd3

Please sign in to comment.