-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathProgram.cs
More file actions
118 lines (100 loc) · 4.23 KB
/
Program.cs
File metadata and controls
118 lines (100 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
namespace HubSpot.NET.Examples
{
using HubSpot.NET.Core;
using System;
using System.IO;
public class Examples
{
// enable args to be presented from CLI for automated test execution
static void Main(string[] args)
{
/**
* Initialize the API with your API Key
* You can find or generate this under Integrations -> HubSpot API key
*/
string hapiKey = string.Empty; // YOUR KEY GOES HERE ... or supply it as args[0] either way.
string clientId = string.Empty; // args[1]
string clientSecret = string.Empty; // args[2]
string appId = string.Empty; // args[3]
if(args.Length >= 1)
{
hapiKey = args[0];
if(args.Length > 3)
{
clientId = args[1];
clientSecret = args[2];
appId = args[3];
}
}
else
{
bool authChosen = false;
Console.WriteLine("How would you like to authenticate your requests? HAPIKey or OAuth?");
string authType;
while (authChosen == false)
{
authType = Console.ReadLine().ToLowerInvariant();
switch (authType)
{
case "hapikey":
Console.WriteLine("Please enter the HAPIKey:");
bool valid = Guid.TryParse(Console.ReadLine(), out Guid guidResult);
hapiKey = valid ? guidResult.ToString() : string.Empty;
if (string.IsNullOrWhiteSpace(hapiKey))
{
Console.WriteLine("That is not a valid HAPIKey. Please try again");
break;
}
authChosen = true;
break;
case "oauth":
Console.WriteLine("Please enter the ClientID for your app:");
clientId = Console.ReadLine();
Console.WriteLine("Please enter the ClientSecret for your app:");
clientSecret = Console.ReadLine();
Console.WriteLine("Please enter the AppId for your app:");
appId = Console.ReadLine();
authChosen = true;
break;
default:
Console.WriteLine("That is not a valid selection. Please choose HAPIKey or OAuth.");
break;
}
}
}
while(string.IsNullOrWhiteSpace(hapiKey) || !Guid.TryParse(hapiKey, out Guid result))
{
Console.WriteLine("Invalid API Key, try again");
hapiKey = Console.ReadLine();
}
var hapiApi = new HubSpotApi(hapiKey);
RunApiKeyExamples(hapiApi);
if(string.IsNullOrWhiteSpace(clientId) || string.IsNullOrWhiteSpace(clientSecret) || string.IsNullOrWhiteSpace(appId))
{
Console.WriteLine("Invalid clientId, Secret, or AppID. Skipping OAuth related tests...");
}
else
{
var oauthApi = new HubSpotApi(clientId, clientSecret, appId);
RunOAuthExamples(oauthApi);
}
var key = Console.ReadKey();
}
private static void RunApiKeyExamples(HubSpotApi hapiApi)
{
//EmailSubscriptions.Example(hapiApi);
//Deals.Example(hapiApi);
//Contacts.Example(hapiApi);
Companies.Example(hapiApi);
//CompanyProperties.Example(hapiApi);
//Pipelines.Example(hapiApi);
}
private static void RunOAuthExamples(HubSpotApi oauthApi)
{
OAuth.Example(oauthApi);
Timeline.Example(oauthApi);
}
private static string GetContactString()
=> File.ReadAllText("ContactExample.txt");
}
}