コード例 #1
0
        static void Main(string[] args)
        {
            // Trust all SSL certs -- needed unless signed SSL certificates are configured.
            ServicePointManager.ServerCertificateValidationCallback =
                ((sender, certificate, chain, sslPolicyErrors) => true);

            // OAuth configuration
            var oauthUrl     = "https://test.edfi.education.mn.gov/EdFi.Ods.WebApi/";
            var clientKey    = "j57lM8oL5S7O";
            var clientSecret = "h9kgUASBEQhojU8HiSCsNPjz";

            // RestSharp dependency, install via NuGet
            var client = new RestClient("https://test.edfi.education.mn.gov/EdFi.Ods.WebApi/api/v2/2018/");


            // TokenRetriever makes the OAuth calls
            var tokenRetriever = new TokenRetriever(oauthUrl, clientKey, clientSecret);

            // Plug OAuth into RestSharp's authentication scheme
            client.Authenticator = new BearerTokenAuthenticator(tokenRetriever);

            // GET schools
            var api      = new SchoolsApi(client);
            var response = api.GetSchoolsAll(null, null); // offset, limit

            var httpReponseCode = response.StatusCode;    // returns System.Net.HttpStatusCode.OK

            Console.WriteLine("Response code is " + httpReponseCode);
            Console.WriteLine();

            // Create identity example setup
            //var IdentityApi = new identitiesApi(client, 2019);
            //var Identitiesresponse = IdentityApi.IdentitiesV2_Create(null);


            // Response data is serialized directly to typed model classes
            List <School> schools = response.Data;

            foreach (var school in schools)
            {
                Console.WriteLine(school.schoolId + ": " + school.nameOfInstitution);
            }

            Console.WriteLine();
            Console.WriteLine("Hit ENTER key to continue...");
            Console.ReadLine();
        }
コード例 #2
0
        public bool ConfigurationIsOk(string apiServerUrl, string apiServerKey, string apiServerSecret)
        {
            try
            {
                System.Net.ServicePointManager.ServerCertificateValidationCallback = (senderLocal, certificate, chain, sslPolicyErrors) => true;

                var oAuthUrl = Common.Helpers.UrlUtility.GetUntilOrEmpty(apiServerUrl.Trim(), "/api/");

                var client         = new RestClient(apiServerUrl);
                var tokenRetriever = new TokenRetriever(oAuthUrl, apiServerKey, apiServerSecret);
                client.Authenticator = new BearerTokenAuthenticator(tokenRetriever);

                var api     = new SchoolsApi(client);
                var apiCall = api.GetSchoolsAll(0, 1);

                return(apiCall.IsSuccessful);
            }
            catch (Exception e)
            {
                LogService.Error("Configuration for API failed.", e);
                return(false);
            }
        }
コード例 #3
0
        public IRestResponse DeleteSchool(string id)
        {
            var api = new SchoolsApi(EstablishApiClient());

            return(api.DeleteSchoolById(id));
        }
コード例 #4
0
        public IRestResponse CreateSchool(EdFi.Models.Resources.School school)
        {
            var api = new SchoolsApi(EstablishApiClient());

            return(api.PostSchools(school));
        }
コード例 #5
0
        public EdFi.Models.Resources.School GetSchoolBySchoolId(int schoolId)
        {
            var api = new SchoolsApi(EstablishApiClient());

            return(api.GetSchoolByKey(schoolId).Data);
        }
コード例 #6
0
        public EdFi.Models.Resources.School GetSchool(string id)
        {
            var api = new SchoolsApi(EstablishApiClient());

            return(api.GetSchoolsById(id).Data);
        }
コード例 #7
0
        public static void Main(string[] args)
        {
            // Trust all SSL certs -- needed unless signed SSL certificates are configured.
            System.Net.ServicePointManager.ServerCertificateValidationCallback =
                ((sender, certificate, chain, sslPolicyErrors) => true);

            // Explicitly configures outgoing network calls to use the latest version of TLS where possible.
            // Due to our reliance on some older libraries, the.NET framework won't necessarily default
            // to the latest unless we explicitly request it. Some hosting environments will not allow older versions
            // of TLS, and thus calls can fail without this extra configuration.
            System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12;

            // Oauth configuration
            var oauthUrl     = "https://test.edfi.education.mn.gov/edfi.ods.webapi";
            var clientKey    = "populatedSandbox";
            var clientSecret = "populatedSandboxSecret";

            // TokenRetriever makes the oauth calls.  It has RestSharp dependency, install via NuGet
            var tokenRetriever = new TokenRetriever(oauthUrl, clientKey, clientSecret);

            // Plug Oauth access token. Tokens will need to be refreshed when they expire
            var configuration = new Configuration
            {
                AccessToken = tokenRetriever.ObtainNewBearerToken(),
                BasePath    = "https://test.edfi.education.mn.gov/edfi.ods.webapi/data/v3"
            };

            Console.WriteLine("GET MN extension StudentSchoolAssociations");
            var mnssaApi         = new StudentSchoolAssociationsApi(configuration);
            var mnssaResponse    = mnssaApi.GetStudentSchoolAssociationsWithHttpInfo(null, null);
            var httpResponseCode = mnssaResponse.StatusCode;
            var mnssas           = mnssaResponse.Data;

            Console.WriteLine($"Response code is {httpResponseCode}");

            if (httpResponseCode == 200 && mnssas != null && mnssas.Count > 0)
            {
                foreach (var mnssa in mnssas)
                {
                    Console.WriteLine($"{mnssa.StudentReference.StudentUniqueId} / {mnssa.SchoolReference.SchoolId}");
                }
            }

            Console.WriteLine();
            Console.WriteLine("GET Schools via MN SISVendor profile");
            var schoolsApi      = new SchoolsApi(configuration);
            var schoolsResponse = schoolsApi.GetSchoolsWithHttpInfo(null, null);

            httpResponseCode = schoolsResponse.StatusCode;
            var schools = schoolsResponse.Data;

            Console.WriteLine($"Response code is {httpResponseCode}");

            if (httpResponseCode == 200 && schools != null && schools.Count > 0)
            {
                foreach (var school in schools.OrderBy(x => x.SchoolId))
                {
                    Console.WriteLine($"{school.SchoolId}: {school.NameOfInstitution}");
                }
            }

            Console.WriteLine();
            Console.WriteLine("GET Core Ed-Fi Descriptor: GiftedTalentedParticipation");
            var descriptorApi      = new GiftedTalentedParticipationDescriptorsApi(configuration);
            var descriptorResponse = descriptorApi.GetGiftedTalentedParticipationDescriptorsWithHttpInfo(null, null);

            httpResponseCode = descriptorResponse.StatusCode;
            var descriptors = descriptorResponse.Data;

            Console.WriteLine($"Response code is {httpResponseCode}");

            if (httpResponseCode == 200 && descriptors != null && descriptors.Count > 0)
            {
                foreach (var descriptor in descriptors.OrderBy(x => x.CodeValue))
                {
                    Console.WriteLine($"{descriptor.CodeValue}: {descriptor.ShortDescription}");
                }
            }

            Console.WriteLine();
            Console.WriteLine("GET MN Extension Descriptor: EarlyChildhoodScreeningExitStatus");
            var mnDescriptorApi      = new EarlyChildhoodScreeningExitStatusDescriptorsApi(configuration);
            var mnDescriptorResponse = mnDescriptorApi.GetEarlyChildhoodScreeningExitStatusDescriptorsWithHttpInfo(null, null);

            httpResponseCode = mnDescriptorResponse.StatusCode;
            var mnDescriptors = mnDescriptorResponse.Data;

            Console.WriteLine($"Response code is {httpResponseCode}");

            if (httpResponseCode == 200 && mnDescriptors != null && mnDescriptors.Count > 0)
            {
                foreach (var descriptor in mnDescriptors.OrderBy(x => x.CodeValue))
                {
                    Console.WriteLine($"{descriptor.CodeValue}: {descriptor.ShortDescription}");
                }
            }

            Console.WriteLine();
            Console.WriteLine("Hit ENTER key to continue...");
            Console.ReadLine();
        }