Skip to content

sendgrid/csharp-http-client#1 Adding port of the http client to Aspne… #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ CSharpHTTPClient/packages/
CSharpHTTPClient/CSharpHTTPClient.sln.VisualState.xml
*.PublicKey
*.pfx
project.lock.json
48 changes: 48 additions & 0 deletions NetCore/CSharpHTTPClient.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{005FE017-F738-4C16-9548-89C39600F1EA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FCEEA0BD-11CB-4DB8-94D0-E705B99B071D}"
ProjectSection(SolutionItems) = preProject
global.json = global.json
EndProjectSection
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SendGrid.CSharp.HTTP.Client", "src\SendGrid.CSharp.HTTP.Client\SendGrid.CSharp.HTTP.Client.xproj", "{DE550D30-B53D-4256-AEBD-31FE5F4A43BA}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Example", "src\Example\Example.xproj", "{0D6C6178-0950-41CA-AEB4-546F3FCFE9EE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{6A21EE25-6B85-4D59-924A-4891D7576EB7}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "UnitTest", "test\UnitTest\UnitTest.xproj", "{661B8EEA-0919-4B66-ABB6-449432053CBA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DE550D30-B53D-4256-AEBD-31FE5F4A43BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DE550D30-B53D-4256-AEBD-31FE5F4A43BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DE550D30-B53D-4256-AEBD-31FE5F4A43BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DE550D30-B53D-4256-AEBD-31FE5F4A43BA}.Release|Any CPU.Build.0 = Release|Any CPU
{0D6C6178-0950-41CA-AEB4-546F3FCFE9EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0D6C6178-0950-41CA-AEB4-546F3FCFE9EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0D6C6178-0950-41CA-AEB4-546F3FCFE9EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0D6C6178-0950-41CA-AEB4-546F3FCFE9EE}.Release|Any CPU.Build.0 = Release|Any CPU
{661B8EEA-0919-4B66-ABB6-449432053CBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{661B8EEA-0919-4B66-ABB6-449432053CBA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{661B8EEA-0919-4B66-ABB6-449432053CBA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{661B8EEA-0919-4B66-ABB6-449432053CBA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{DE550D30-B53D-4256-AEBD-31FE5F4A43BA} = {005FE017-F738-4C16-9548-89C39600F1EA}
{0D6C6178-0950-41CA-AEB4-546F3FCFE9EE} = {005FE017-F738-4C16-9548-89C39600F1EA}
{661B8EEA-0919-4B66-ABB6-449432053CBA} = {6A21EE25-6B85-4D59-924A-4891D7576EB7}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions NetCore/global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"projects": [ "src", "test" ],
"sdk": {

}
}
118 changes: 118 additions & 0 deletions NetCore/src/Example/Example.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
using System;
using System.Collections.Generic;
using SendGrid.CSharp.HTTP.Client;
using System.Web.Script.Serialization;

// This is a working example, using the SendGrid API
// You will need a SendGrid account and an active API Key
// They key should be stored in an environment variable called SENDGRID_APIKEY
namespace Example
{
class Example
{
static void Main(string[] args)
{
String host = "https://e9sk3d3bfaikbpdq7.stoplight-proxy.io";
Dictionary<String, String> globalRequestHeaders = new Dictionary<String, String>();
string apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User);
globalRequestHeaders.Add("Authorization", "Bearer " + apiKey);
globalRequestHeaders.Add("Content-Type", "application/json");

String version = "v3";
dynamic client = new Client(host: host, requestHeaders: globalRequestHeaders, version: version);

// GET Collection
string queryParams = @"{
'limit': 100
}";
Dictionary<String, String> requestHeaders = new Dictionary<String, String>();
requestHeaders.Add("X-Test", "test");
dynamic response = client.version("v3").api_keys.get(queryParams: queryParams, requestHeaders: requestHeaders);
// Console.WriteLine(response.StatusCode);
// Console.WriteLine(response.ResponseBody.ReadAsStringAsync().Result);
// Console.WriteLine(response.ResponseHeaders.ToString());

var dssResponseBody = response.DeserializeResponseBody(response.ResponseBody);
foreach ( var value in dssResponseBody["result"])
{
Console.WriteLine("name: {0}, api_key_id: {1}",value["name"], value["api_key_id"]);
}

var dssResponseHeaders = response.DeserializeResponseHeaders(response.ResponseHeaders);
foreach (var pair in dssResponseHeaders)
{
Console.WriteLine("{0}: {1}", pair.Key, pair.Value);
}

Console.WriteLine("\n\nPress any key to continue to POST.");
Console.ReadLine();

// POST
string requestBody = @"{
'name': 'My API Key 5',
'scopes': [
'mail.send',
'alerts.create',
'alerts.read'
]
}";
requestHeaders.Clear();
requestHeaders.Add("X-Test", "test2");
response = client.api_keys.post(requestBody: requestBody, requestHeaders: requestHeaders);
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.ResponseBody.ReadAsStringAsync().Result);
Console.WriteLine(response.ResponseHeaders.ToString());
JavaScriptSerializer jss = new JavaScriptSerializer();
var ds_response = jss.Deserialize<Dictionary<string, dynamic>>(response.ResponseBody.ReadAsStringAsync().Result);
string api_key_id = ds_response["api_key_id"];

Console.WriteLine("\n\nPress any key to continue to GET single.");
Console.ReadLine();

// GET Single
response = client.api_keys._(api_key_id).get();
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.ResponseBody.ReadAsStringAsync().Result);
Console.WriteLine(response.ResponseHeaders.ToString());

Console.WriteLine("\n\nPress any key to continue to PATCH.");
Console.ReadLine();

// PATCH
requestBody = @"{
'name': 'A New Hope'
}";
response = client.api_keys._(api_key_id).patch(requestBody: requestBody);
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.ResponseBody.ReadAsStringAsync().Result);
Console.WriteLine(response.ResponseHeaders.ToString());

Console.WriteLine("\n\nPress any key to continue to PUT.");
Console.ReadLine();

// PUT
requestBody = @"{
'name': 'A New Hope',
'scopes': [
'user.profile.read',
'user.profile.update'
]
}";
response = client.api_keys._(api_key_id).put(requestBody: requestBody);
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.ResponseBody.ReadAsStringAsync().Result);
Console.WriteLine(response.ResponseHeaders.ToString());

Console.WriteLine("\n\nPress any key to continue to DELETE.");
Console.ReadLine();

// DELETE
response = client.api_keys._(api_key_id).delete();
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.ResponseHeaders.ToString());

Console.WriteLine("\n\nPress any key to exit.");
Console.ReadLine();
}
}
}
18 changes: 18 additions & 0 deletions NetCore/src/Example/Example.xproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>0d6c6178-0950-41ca-aeb4-546f3fcfe9ee</ProjectGuid>
<RootNamespace>Example</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
23 changes: 23 additions & 0 deletions NetCore/src/Example/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Example")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Example")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("0d6c6178-0950-41ca-aeb4-546f3fcfe9ee")]
21 changes: 21 additions & 0 deletions NetCore/src/Example/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": "1.0.0-*",
"description": "Example Console Application",
"authors": [ "ecelletti" ],

"buildOptions": {
"emitEntryPoint": true
},

"dependencies": {
"SendGrid.CSharp.HTTP.Client": "1.0.0-*"
},

"commands": {
"Example": "Example"
},

"frameworks": {
"net451": {}
}
}
Loading