Get Company Hubs


Static Host Value

    
            static string _host = "https://astuteincservices.com";
        
    

A method named LogMeIn() returns an instance of DGLogInRequest with your credentials.


C# HTTP

    
            static void GetCompanyHub(string token)
            {
                HttpClient apiClient = new HttpClient();
                string route = "/api/company";

                var json = JsonConvert.SerializeObject(LogMeIn());
                var strContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json");
                apiClient.DefaultRequestHeaders.Clear();
                apiClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

                var response = apiClient.PostAsync(_host + route + "/gethubs", strContent).Result;

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                    ProcessHubs(response.Content.ReadAsStringAsync().Result);
                else
                    Console.WriteLine($"{response.Content.ReadAsStringAsync().Result} - Not authorized");
            }

            static void ProcessHubs(string content)
            {
                var returnHubs = JsonConvert.DeserializeObject<List<DGCompanyHub>>(content);

                foreach (var readings in returnHubs)
                {
                    Console.WriteLine("-------------------");
                    Console.WriteLine(readings.IMEI);      
                    Console.WriteLine(readings.IsActive);  
                    Console.WriteLine(readings.DateStart);
                }
            }
        
    

C# Flurl

    
            static void FlurlGetCompanyHub(string token)
            {
                var response = _host.AppendPathSegment("/api/company/gethubs").WithOAuthBearerToken(token).PostJsonAsync(LogMeIn()).Result;

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                    ProcessHubs(response.Content.ReadAsStringAsync().Result);
                else
                    Console.WriteLine($"{response.Content.ReadAsStringAsync().Result} - Not authorized");
            }

            static void ProcessHubs(string content)
            {
                var returnHubs = JsonConvert.DeserializeObject<List<DGCompanyHub>>(content);

                foreach (var readings in returnHubs)
                {
                    Console.WriteLine("-------------------");
                    Console.WriteLine(readings.IMEI);      
                    Console.WriteLine(readings.IsActive);  
                    Console.WriteLine(readings.DateStart);
                }
            }