Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 156 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,156 @@
Sample/Sample/obj
################
## Visual Studio
#################

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates

# Build results

[Dd]ebug/
x64/
build/
[Bb]in
[Oo]bj

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc


# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
*.ncrunch*
.*crunch*.local.xml

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.Publish.xml
*.pubxml

# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
packages

# Windows Azure Build Output
csx
*.build.csdef

# Windows Store app package directory
AppPackages/

# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings
*.user
/.nuget


# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
App_Data/*.mdf
App_Data/*.ldf

#############
## Windows detritus
#############

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Mac crap
.DS_Store

60 changes: 35 additions & 25 deletions CoconutAPI/CoconutAPI.cs
Original file line number Diff line number Diff line change
@@ -1,48 +1,58 @@
using System;
using RestSharp;
using System.Web.Script.Serialization;
using System.Collections.Generic;
using System.Net;
using Newtonsoft.Json;
using RestSharp.Authenticators;

namespace Coconut
{
public class CoconutAPI
{
RestClient Cli;
JavaScriptSerializer Json;
public interface ICoconutAPI
{
/// <summary>
/// Create a Job
/// </summary>
/// <param name="data">A string representing the config content</param>
/// <returns>CoconutJob instance</returns>
CoconutJob Submit(string data);
}

public class CoconutAPI : ICoconutAPI
{
private RestClient _cli;

/// <summary>
/// Create an CoconutClient instance
/// Create an CoconutAPI instance
/// </summary>
/// <param name="APIKey"></param>
/// <param name="apiKey"></param>
/// <example>
/// CoconutClient Coconut = new CoconutClient("k-myapikey");
/// CoconutAPI Coconut = new CoconutAPI("k-myapikey");
/// </example>
public CoconutAPI (string APIKey)
public CoconutAPI (string apiKey)
{
Cli = new RestClient("https://api.coconut.co");
Cli.Authenticator = new HttpBasicAuthenticator(APIKey, "");
Cli.AddDefaultHeader("Accept", "application/json");
Cli.UserAgent = "Coconut/2.0.0 (dotnet)";

Json = new JavaScriptSerializer();
_cli = new RestClient("https://api.coconut.co")
{
Authenticator = new HttpBasicAuthenticator(apiKey, "")
};
_cli.AddDefaultHeader("Accept", "application/json");
_cli.UserAgent = "Coconut/2.0.0 (dotnet)";
}


/// <summary>
/// Create a Job
/// </summary>
/// <param name="Data">A string representing the config content</param>
/// <param name="data">A string representing the config content</param>
/// <returns>CoconutJob instance</returns>
public CoconutJob Submit(string Data)
public CoconutJob Submit(string data)
{
return Json.Deserialize<CoconutJob>(Request("v1/job", Method.POST, Data));
return JsonConvert.DeserializeObject<CoconutJob>(Request("v1/job", Method.POST, data));
}

private string Request(string path, RestSharp.Method method, string Data) {
private string Request(string path, RestSharp.Method method, string data)
{
var request = new RestRequest(path, method);
request.AddParameter("text/plain", Data, ParameterType.RequestBody);
request.AddParameter("text/plain", data, ParameterType.RequestBody);

RestResponse response = Cli.Execute(request);
var response = _cli.Execute(request);
var code = response.StatusCode;

if(code == HttpStatusCode.Created || code == HttpStatusCode.OK || code == HttpStatusCode.NoContent)
Expand All @@ -51,8 +61,8 @@ private string Request(string path, RestSharp.Method method, string Data) {
}
else
{
string ErrorMessage = Json.Deserialize<CoconutError> (response.Content).Message;
throw new CoconutException(ErrorMessage);
var errorMessage = JsonConvert.DeserializeObject<CoconutError> (response.Content).Message;
throw new CoconutException(errorMessage);
}

}
Expand Down
18 changes: 13 additions & 5 deletions CoconutAPI/CoconutAPI.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -28,17 +28,25 @@
<ConsolePause>False</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="RestSharp, Version=105.2.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\RestSharp.105.2.3\lib\net45\RestSharp.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Web.Extensions" />
<Reference Include="RestSharp">
<HintPath>..\RestSharp.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="Models.cs" />
<Compile Include="Exceptions.cs" />
<Compile Include="CoconutAPI.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
Binary file removed CoconutAPI/bin/Debug/CoconutAPI.dll
Binary file not shown.
Binary file removed CoconutAPI/bin/Debug/CoconutAPI.dll.mdb
Binary file not shown.
Binary file removed CoconutAPI/bin/Debug/RestSharp.dll
Binary file not shown.
Binary file removed CoconutAPI/bin/Release/CoconutAPI.dll
Binary file not shown.
Binary file removed CoconutAPI/bin/Release/RestSharp.dll
Binary file not shown.

This file was deleted.

This file was deleted.

Binary file removed CoconutAPI/obj/Debug/CoconutAPI.dll
Binary file not shown.
Binary file removed CoconutAPI/obj/Debug/CoconutAPI.dll.mdb
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file removed CoconutAPI/obj/Release/CoconutAPI.dll
Binary file not shown.
5 changes: 5 additions & 0 deletions CoconutAPI/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
<package id="RestSharp" version="105.2.3" targetFramework="net45" />
</packages>
Binary file removed RestSharp.dll
Binary file not shown.