Permalink
Browse files

Added CopyleaksCloud.CreateByText() method.

  • Loading branch information...
Copyleaks committed Oct 5, 2016
1 parent 65f50a4 commit 632b0497dada0b1596e9f0305721b1a615c7e42a
View
Binary file not shown.
Binary file not shown.
@@ -335,6 +335,58 @@ public CopyleaksProcess CreateByOcr(FileInfo localfile, string ocrLanguageId, Pr
}
}
/// <summary>
/// Submitting text to plagiarism scan
/// </summary>
/// <param name="text">Text to be scanned. The text MUST be encoded with UTF-8.</param>
/// <param name="options">Process Options: include http callback and add custom fields to the process</param>
/// <exception cref="UnauthorizedAccessException">The login-token is undefined or expired</exception>
/// <exception cref="ArgumentOutOfRangeException">The input URL scheme is different than HTTP or HTTPS</exception>
/// <returns>The newly created process</returns>
public CopyleaksProcess CreateByText(string text, ProcessOptions options = null)
{
if (this.Token == null)
throw new UnauthorizedAccessException("Empty token!");
else
this.Token.Validate();
if (text.Trim() == "")
throw new ArgumentOutOfRangeException(nameof(text), "Empty text not allowed.");
using (HttpClient client = new HttpClient())
{
client.SetCopyleaksClient(HttpContentTypes.Json, this.Token);
HttpResponseMessage msg;
HttpContent content = new StringContent(text, Encoding.UTF8, HttpContentTypes.PlainText);
if (options != null)
options.AddHeaders(client);
msg = client.PostAsync(string.Format("{0}/{1}/{2}", Resources.ServiceVersion, this.Product.ToName(), "create-by-text"), content).Result;
if (!msg.IsSuccessStatusCode)
throw new CommandFailedException(msg);
string json = msg.Content.ReadAsStringAsync().Result;
CreateResourceResponse response;
try
{
var dateTimeConverter = new IsoDateTimeConverter { DateTimeFormat = "dd/MM/yyyy HH:mm:ss" };
response = JsonConvert.DeserializeObject<CreateResourceResponse>(json, dateTimeConverter);
}
catch (Exception e)
{
throw new Exception("JSON=" + json, e);
}
if (options == null)
return new CopyleaksProcess(this.Token, this.Product, response, null);
else
return new CopyleaksProcess(this.Token, this.Product, response, options.CustomFields);
}
}
/// <summary>
/// Get a list of supported languages for OCR scanning.
/// </summary>
@@ -29,5 +29,6 @@ public static class HttpContentTypes
public static readonly string Json = "application/json";
public static readonly string Xml = "application/xml";
public static readonly string UrlEncoded = "application/x-www-form-urlencoded";
public static readonly string PlainText = "text/plain";
}
}
@@ -0,0 +1,48 @@
/********************************************************************************
The MIT License(MIT)
Copyright(c) 2016 Copyleaks LTD (https://copyleaks.com)
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.
********************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
namespace Copyleaks.SDK.API.Models
{
public static class OcrLanguages
{
private static List<OcrLanguage> SupportedLanguagesList { get; set; }
static OcrLanguages()
{
SupportedLanguagesList = new List<OcrLanguage>();
foreach (var value in Enum.GetValues(typeof(eOcrLanguage)).Cast<eOcrLanguage>())
SupportedLanguagesList.Add(new OcrLanguage(value));
}
public static OcrLanguage[] SupportedLanguages
{
get
{
return SupportedLanguagesList.ToArray();
}
}
}
}
@@ -0,0 +1,76 @@
/********************************************************************************
The MIT License(MIT)
Copyright(c) 2016 Copyleaks LTD (https://copyleaks.com)
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.
********************************************************************************/
namespace Copyleaks.SDK.API.Models
{
public enum eOcrLanguage
{
Afrikaans,
Albanian,
Basque,
Brazilian,
Bulgarian,
Byelorussian,
Catalan,
Chinese_Simplified,
Chinese_Traditional,
Croatian,
Czech,
Danish,
Dutch,
English,
Esperanto,
Estonian,
Finnish,
French,
Galician,
German,
Greek,
Hungarian,
Icelandic,
Indonesian,
Italian,
Japanese,
Korean,
Latin,
Latvian,
Lithuanian,
Macedonian,
Malay,
Moldavian,
Norwegian,
Polish,
Portuguese,
Romanian,
Russian,
Serbian,
Slovak,
Slovenian,
Spanish,
Swedish,
Tagalog,
Turkish,
Ukrainian
}
}
Binary file not shown.
View
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<package >
<metadata>
<id>Copyleaks API</id>
<version>2.0.1</version>
<authors>Copyleaks</authors>
<owners>Copyleaks</owners>
<licenseUrl>https://copyleaks.com/Legal/TermsOfUse</licenseUrl>
<projectUrl>https://github.com/Copyleaks/API/tree/master/CopyleaksAPI</projectUrl>
<iconUrl>https://copyleaks.com/images/nuget/copyleaks-icon-32.png</iconUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>Copyleaks is a popular advanced online plagiarism checker. This library provides access to Copyleaks cloud and scans your content for copyright infringement.</description>
<releaseNotes></releaseNotes>
<copyright>All rights reserved to Copyleaks Ltd.</copyright>
<tags>plagiarism copyright copyrights Copyleaks infringement checker detector</tags>
<dependencies>
</dependencies>
</metadata>
</package>
View
@@ -116,7 +116,8 @@ static void Main(string[] args)
Environment.Exit(1);
}
createdProcess = copyleaks.CreateByUrl(uri, scanOptions);
//createdProcess = copyleaks.CreateByUrl(uri, scanOptions);
createdProcess = copyleaks.CreateByText("Hello World", scanOptions);
}
else
{
Binary file not shown.
Oops, something went wrong.

0 comments on commit 632b049

Please sign in to comment.