summaryrefslogtreecommitdiffstats
path: root/ExampleNet45
diff options
context:
space:
mode:
Diffstat (limited to 'ExampleNet45')
-rw-r--r--ExampleNet45/App.config6
-rw-r--r--ExampleNet45/ExampleNet45.csproj69
-rw-r--r--ExampleNet45/Program.cs131
-rw-r--r--ExampleNet45/Properties/AssemblyInfo.cs36
-rw-r--r--ExampleNet45/packages.config4
5 files changed, 246 insertions, 0 deletions
diff --git a/ExampleNet45/App.config b/ExampleNet45/App.config
new file mode 100644
index 0000000..8227adb
--- /dev/null
+++ b/ExampleNet45/App.config
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <startup>
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
+ </startup>
+</configuration>
diff --git a/ExampleNet45/ExampleNet45.csproj b/ExampleNet45/ExampleNet45.csproj
new file mode 100644
index 0000000..35f6172
--- /dev/null
+++ b/ExampleNet45/ExampleNet45.csproj
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectGuid>{3B3F2699-F720-4498-8044-262EFE110A22}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>ExampleNet45</RootNamespace>
+ <AssemblyName>ExampleNet45</AssemblyName>
+ <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
+ <TargetFrameworkProfile />
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </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="SendGrid">
+ <HintPath>..\src\SendGrid\bin\Debug\net452\SendGrid.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Net.Http" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Program.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="App.config" />
+ <None Include="packages.config" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/ExampleNet45/Program.cs b/ExampleNet45/Program.cs
new file mode 100644
index 0000000..572ce7a
--- /dev/null
+++ b/ExampleNet45/Program.cs
@@ -0,0 +1,131 @@
+using System;
+using System.Threading.Tasks;
+using Newtonsoft.Json;
+using SendGrid;
+using SendGrid.Helpers.Mail;
+using System.Collections.Generic;
+
+namespace Example
+{
+ internal class Example
+ {
+ private static void Main()
+ {
+ Execute().Wait();
+ }
+
+ static async Task Execute()
+ {
+ string apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY");
+ Client client = new Client(apiKey);
+
+ string data = @"{
+ 'personalizations': [
+ {
+ 'to': [
+ {
+ 'email': 'elmer@sendgrid.com'
+ }
+ ],
+ 'subject': 'Hello World from the SendGrid C# Library!'
+ }
+ ],
+ 'from': {
+ 'email': 'dx@sendgrid.com'
+ },
+ 'content': [
+ {
+ 'type': 'text/plain',
+ 'value': 'Hello, Email!'
+ }
+ ]
+ }";
+ Object json = JsonConvert.DeserializeObject<Object>(data);
+ Response response = await client.RequestAsync(Client.Methods.POST,
+ json.ToString(),
+ urlPath: "mail/send");
+ Console.WriteLine(response.StatusCode);
+ Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+ Console.WriteLine(response.Headers);
+ Console.ReadLine();
+
+ Email from = new Email("dx@sendgrid");
+ string subject = "Hello World from the SendGrid CSharp Library Helper!";
+ Email to = new Email("elmer@sendgrid.com");
+ Content content = new Content("text/plain", "Hello, Email from the helper!");
+ Mail mail = new Mail(from, subject, to, content);
+
+ response = await client.RequestAsync(Client.Methods.POST,
+ mail.Get(),
+ urlPath: "mail/send");
+ Console.WriteLine(response.StatusCode);
+ Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+ Console.WriteLine(response.Headers);
+ Console.ReadLine();
+
+ // GET Collection
+ string queryParams = @"{
+ 'limit': 100
+ }";
+ response = await client.RequestAsync(method: Client.Methods.GET,
+ urlPath: "asm/groups",
+ queryParams: queryParams);
+ Console.WriteLine(response.StatusCode);
+ Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+ Console.WriteLine(response.Headers.ToString());
+ Console.WriteLine("\n\nPress any key to continue to POST.");
+ Console.ReadLine();
+
+ // POST
+ string requestBody = @"{
+ 'description': 'Suggestions for products our users might like.',
+ 'is_default': false,
+ 'name': 'Magic Products'
+ }";
+ json = JsonConvert.DeserializeObject<object>(requestBody);
+ response = await client.RequestAsync(method: Client.Methods.POST,
+ urlPath: "asm/groups",
+ requestBody: json.ToString());
+ var ds_response = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(response.Body.ReadAsStringAsync().Result);
+ string group_id = ds_response["id"].ToString();
+ Console.WriteLine(response.StatusCode);
+ Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+ Console.WriteLine(response.Headers.ToString());
+ Console.WriteLine("\n\nPress any key to continue to GET single.");
+ Console.ReadLine();
+
+ // GET Single
+ response = await client.RequestAsync(method: Client.Methods.GET,
+ urlPath: string.Format("asm/groups/{0}", group_id));
+ Console.WriteLine(response.StatusCode);
+ Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+ Console.WriteLine(response.Headers.ToString());
+ Console.WriteLine("\n\nPress any key to continue to PATCH.");
+ Console.ReadLine();
+
+ // PATCH
+ requestBody = @"{
+ 'name': 'Cool Magic Products'
+ }";
+ json = JsonConvert.DeserializeObject<object>(requestBody);
+
+ response = await client.RequestAsync(method: Client.Methods.PATCH,
+ urlPath: string.Format("asm/groups/{0}", group_id),
+ requestBody: json.ToString());
+ Console.WriteLine(response.StatusCode);
+ Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+ Console.WriteLine(response.Headers.ToString());
+
+ Console.WriteLine("\n\nPress any key to continue to PUT.");
+ Console.ReadLine();
+
+ // DELETE
+ response = await client.RequestAsync(method: Client.Methods.DELETE,
+ urlPath: string.Format("asm/groups/{0}", group_id));
+ Console.WriteLine(response.StatusCode);
+ Console.WriteLine(response.Headers.ToString());
+ Console.WriteLine("\n\nPress any key to exit.");
+ Console.ReadLine();
+ }
+ }
+}
diff --git a/ExampleNet45/Properties/AssemblyInfo.cs b/ExampleNet45/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..3bde8af
--- /dev/null
+++ b/ExampleNet45/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+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("ExampleNet45")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("ExampleNet45")]
+[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("3b3f2699-f720-4498-8044-262efe110a22")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/ExampleNet45/packages.config b/ExampleNet45/packages.config
new file mode 100644
index 0000000..9d64bf3
--- /dev/null
+++ b/ExampleNet45/packages.config
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
+</packages> \ No newline at end of file