-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e4719f
commit 6a25456
Showing
12 changed files
with
407 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="nunit" Version="3.12.0" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0"/> | ||
</ItemGroup> | ||
|
||
</Project> |
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,18 @@ | ||
using NUnit.Framework; | ||
|
||
namespace OpenU.Api.Tests | ||
{ | ||
public class Tests | ||
{ | ||
[SetUp] | ||
public void Setup() | ||
{ | ||
} | ||
|
||
[Test] | ||
public void Test1() | ||
{ | ||
Assert.Pass(); | ||
} | ||
} | ||
} |
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,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.30330.147 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenU.Api", "OpenU.Api\OpenU.Api.csproj", "{A3648F04-249F-4BFF-B233-060BB107383E}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenU.Api.Tests", "OpenU.Api.Tests\OpenU.Api.Tests.csproj", "{8005C4B7-383E-40AB-AC60-5E1BAFBE78C2}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{A3648F04-249F-4BFF-B233-060BB107383E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{A3648F04-249F-4BFF-B233-060BB107383E}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{A3648F04-249F-4BFF-B233-060BB107383E}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{A3648F04-249F-4BFF-B233-060BB107383E}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{8005C4B7-383E-40AB-AC60-5E1BAFBE78C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{8005C4B7-383E-40AB-AC60-5E1BAFBE78C2}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{8005C4B7-383E-40AB-AC60-5E1BAFBE78C2}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{8005C4B7-383E-40AB-AC60-5E1BAFBE78C2}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {729680F8-FBCB-439B-B734-2A64E3438173} | ||
EndGlobalSection | ||
EndGlobal |
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,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<PackageId>Openu.Api</PackageId> | ||
<Version>1.0.0</Version> | ||
<Authors>Aviv Naaman</Authors> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace OpenU.Api | ||
{ | ||
class OpenuAbout | ||
{ | ||
public string ActivityHours { get; set; } | ||
public string Phone { get; set; } | ||
public string Email { get; set; } | ||
public string Address { get; set; } | ||
public int PostalAddress { get; set; } | ||
public int PostalCode { get; set; } | ||
} | ||
} |
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,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace OpenU.Api | ||
{ | ||
public class OpenuActivity | ||
{ | ||
public int? Id { get; set; } | ||
public DateTime Date { get; set; } | ||
public string Name { get; set; } | ||
public string Semester { get; set; } | ||
public int? Course { get; set; } | ||
public string StudyCenter { get; set; } | ||
} | ||
} |
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,107 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Net.Http.Headers; | ||
using System.Threading.Tasks; | ||
using Newtonsoft.Json; | ||
|
||
namespace OpenU.Api | ||
{ | ||
public class OpenUApi : IDisposable | ||
{ | ||
public OpenuCredentials Credentials { get; set; } | ||
public bool IsAuthenticated | ||
{ | ||
get | ||
{ | ||
return !String.IsNullOrWhiteSpace(token); | ||
} | ||
} | ||
|
||
private HttpClient httpClient; | ||
private string token; | ||
|
||
const string ApiBaseUrl = "https://sheilta.apps.openu.ac.il/Main/api/MobileApi"; | ||
|
||
public OpenUApi(OpenuCredentials credentials) | ||
{ | ||
Credentials = credentials; | ||
httpClient = new HttpClient(); | ||
} | ||
|
||
public async Task<OpenuLoginResult> AuthenticateAsync() | ||
{ | ||
if (Credentials == null) throw new NullReferenceException("Credentials cannot be null"); | ||
|
||
var data = new Dictionary<string, string>() | ||
{ | ||
{"username", Credentials.UserName }, | ||
{"studentId", Credentials.IdNumber }, | ||
{"password", Credentials.Password }, | ||
{"deviceId", "undefined" }, | ||
}; | ||
var httpResponse = await httpClient.PostAsync(ApiBaseUrl + "/Login", new FormUrlEncodedContent(data)); | ||
|
||
var result = JsonConvert.DeserializeObject<OpenuLoginResult>(await httpResponse.Content.ReadAsStringAsync()); | ||
if (result.Status == LoginStatus.Success) | ||
{ | ||
token = result.Token.Substring(4); // cut "sso " prefix of token from server | ||
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("sso", token); // add token to http client auth header | ||
} | ||
return result; | ||
} | ||
|
||
public void Logout() | ||
{ | ||
token = null; | ||
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(""); // remove auth header | ||
} | ||
|
||
public async Task<List<OpenuCourseListEntry>> GetCoursesAsync() | ||
{ | ||
if (!IsAuthenticated) throw new InvalidOperationException("Autentication is required for this action."); | ||
|
||
var httpResponse = await httpClient.GetAsync(ApiBaseUrl + "/Courses"); | ||
return JsonConvert.DeserializeObject<List<OpenuCourseListEntry>>(await httpResponse.Content.ReadAsStringAsync()); | ||
} | ||
|
||
|
||
|
||
public async Task<OpenuCourseDetails> GetCourseDetailsAsync(string courseId, string semester) | ||
{ | ||
if (!IsAuthenticated) throw new InvalidOperationException("Autentication is required for this action."); | ||
|
||
|
||
var data = new Dictionary<string, string>() | ||
{ | ||
{"id", courseId }, | ||
{"semester", semester }, | ||
}; | ||
var httpResponse = await httpClient.PostAsync(ApiBaseUrl + "/CourseDetails", new FormUrlEncodedContent(data)); | ||
return JsonConvert.DeserializeObject<OpenuCourseDetails>(await httpResponse.Content.ReadAsStringAsync()); | ||
} | ||
|
||
public async Task<List<OpenuMessage>> GetMessagesAsync() | ||
{ | ||
if (!IsAuthenticated) throw new InvalidOperationException("Autentication is required for this action."); | ||
|
||
var httpResponse = await httpClient.GetAsync(ApiBaseUrl + "/Messages"); | ||
return JsonConvert.DeserializeObject<List<OpenuMessage>>(await httpResponse.Content.ReadAsStringAsync()); | ||
} | ||
|
||
public async Task<List<OpenuActivity>> GetActivitiesAsync() | ||
{ | ||
if (!IsAuthenticated) throw new InvalidOperationException("Autentication is required for this action."); | ||
|
||
var httpResponse = await httpClient.GetAsync(ApiBaseUrl + "/Activities"); | ||
return JsonConvert.DeserializeObject<List<OpenuActivity>>(await httpResponse.Content.ReadAsStringAsync()); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Logout(); | ||
httpClient.Dispose(); | ||
} | ||
|
||
} | ||
} |
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,99 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace OpenU.Api | ||
{ | ||
public class OpenuCourseDetails | ||
{ | ||
public OpenuCourseInformation CourseInformation { get; set; } | ||
public OpenuGroupDetails GroupDetails { get; set; } | ||
public List<OpenuTask> Tasks { get; set; } | ||
} | ||
public class OpenuCourseInformation | ||
{ | ||
public OpenuCourseTutor Tutor { get; set; } | ||
public OpenuCourseCoordinator Coordinator { get; set; } | ||
public string DepartmentName { get; set; } | ||
public OpenuCourseStateInfo State { get; set; } | ||
} | ||
|
||
public class OpenuTask { | ||
public int Number { get; set; } | ||
public string Description { get; set; } | ||
public DateTime ExamDate { get; set; } | ||
public int Weight { get; set; } | ||
public string Mark { get; set; } | ||
public string ValidityDescription { get; set; } | ||
public string Validity { get; set; } | ||
public DateTime UpdateDate { get; set; } | ||
} | ||
|
||
public class OpenuGroupDetails | ||
{ | ||
public int StudyGroupID { get; set; } | ||
public string InstructionType { get; set; } | ||
public string MeetingDaysAndHours { get; set; } | ||
public List<OpenuMeeting> Meetings { get; set; } | ||
public OpenuStudyCenter StudyCenter { get; set; } | ||
} | ||
|
||
public class OpenuStudyCenter | ||
{ | ||
public int Id { get; set; } | ||
public string Description { get; set; } | ||
public string Address { get; set; } | ||
public string Phone { get; set; } | ||
public string ActivityDays { get; set; } | ||
|
||
} | ||
|
||
public class OpenuCourseTutor | ||
{ | ||
public string Name { get; set; } | ||
public string Phone { get; set; } | ||
public string Times { get; set; } | ||
public string Address { get; set; } | ||
} | ||
|
||
public class OpenuCourseCoordinator | ||
{ | ||
public string Name { get; set; } | ||
public string Phone { get; set; } | ||
public string GuidanceTimes { get; set; } | ||
public string SecretaryName { get; set; } | ||
public string SecretaryPhone { get; set; } | ||
|
||
} | ||
|
||
public class OpenuCourseStateInfo | ||
{ | ||
public string StateDescription { get; set; } | ||
public int? Score { get; set; } | ||
public int? FinalScore { get; set; } | ||
public int? WeightedScore { get; set; } | ||
} | ||
|
||
public class OpenuMeeting | ||
{ | ||
public int Id { get; set; } | ||
public char Day { get; set; } | ||
public DateTime? Date { get; set; } | ||
public string Hours { get; set; } | ||
public string Type { get; set; } | ||
public string Location { get; set; } | ||
public string Comment { get; set; } | ||
} | ||
public class OpenuPayment | ||
{ | ||
public int Seq { get; set; } | ||
public int Description { get; set; } | ||
public string Type { get; set; } | ||
public int Amount { get; set; } | ||
public DateTime RecordDate { get; set; } | ||
public int PaymentNumber { get; set; } | ||
public DateTime PaymentBegins { get; set; } | ||
public int? CreditNumber { get; set; } | ||
public string Pays { get; set; } | ||
} | ||
} |
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,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace OpenU.Api | ||
{ | ||
public class OpenuCourseListEntry | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
public string Semester { get; set; } | ||
public string StudyCenter { get; set; } | ||
public string Group { get; set; } | ||
public CourseType CourseType { get; set; } | ||
} | ||
|
||
public enum CourseType | ||
{ | ||
|
||
} | ||
} |
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,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace OpenU.Api | ||
{ | ||
public class OpenuCredentials | ||
{ | ||
public OpenuCredentials(string username, string password, string idNumber) | ||
{ | ||
UserName = username; | ||
Password = password; | ||
IdNumber = idNumber; | ||
} | ||
|
||
public string UserName { get; set; } | ||
public string Password { get; set; } | ||
public string IdNumber { get; set; } | ||
} | ||
} |
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,19 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace OpenU.Api | ||
{ | ||
public class OpenuLoginResult | ||
{ | ||
public string Token { get; set; } | ||
public string Message { get; set; } | ||
public LoginStatus Status { get; set; } | ||
} | ||
|
||
public enum LoginStatus | ||
{ | ||
Success = 1, | ||
Failure = 0 | ||
} | ||
} |
Oops, something went wrong.