-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: support ad-hoc calls * fix: code review comments 1. used Url.Combine to form new URL from base URL and relative URL 2. added more test cases * fix: select one value for each HTTP header * fix: added test cases for supported HTTP methods * tests: assert content in the request
- Loading branch information
Showing
5 changed files
with
324 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using JohnsonControls.Metasys.BasicServices; | ||
using System; | ||
using System.Net.Http; | ||
|
||
namespace MetasysServicesExampleApp.FeaturesDemo | ||
{ | ||
public class AdHocCallsDemo | ||
{ | ||
private MetasysClient client; | ||
private LogInitializer log; | ||
|
||
public AdHocCallsDemo(MetasysClient client) | ||
{ | ||
this.client = client; | ||
log = new LogInitializer(typeof(AdHocCallsDemo)); | ||
} | ||
|
||
public void Run() | ||
{ | ||
try | ||
{ | ||
Console.WriteLine("\nEnter the endpoint you want to make the request to (Example: \"https://hostname/api/v5/networkDevices?sort=itemReference\"): ."); | ||
string endpoint = Console.ReadLine(); | ||
Console.WriteLine($"\nMaking the call to {endpoint}..."); | ||
HttpRequestMessage httpRequest = new HttpRequestMessage(HttpMethod.Get, endpoint); | ||
|
||
var response = client.SendAsync(httpRequest).Result; | ||
var statusCode = ((int)response.StatusCode).ToString(); | ||
if (statusCode.StartsWith("2") || statusCode.StartsWith("3")) | ||
{ | ||
Console.WriteLine($"\n \nStatus - {response.StatusCode}"); | ||
Console.WriteLine("\nResponse content - "); | ||
var content = response.Content.ReadAsStringAsync().Result; | ||
Console.WriteLine("\n \n" + content); | ||
} | ||
else | ||
{ | ||
Console.WriteLine(string.Format("\n \nRequest failed with - {0}", response.StatusCode)); | ||
} | ||
} | ||
catch (Exception exception) | ||
{ | ||
log.Logger.Error(string.Format("An error occured while making the request - {0}", exception.Message)); | ||
Console.WriteLine("\n \nAn Error occurred. Press Enter to return to Main Menu"); | ||
} | ||
Console.ReadLine(); | ||
} | ||
} | ||
} |
Oops, something went wrong.