-
Notifications
You must be signed in to change notification settings - Fork 0
Reworked wrapper #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Blagovest-Hristov
wants to merge
9
commits into
master
Choose a base branch
from
blago-branch
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Reworked wrapper #16
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bf2649c
Wrapper Added😎
Blagovest-Hristov 2fe1055
wrapper
Blagovest-Hristov 2bc479c
Wrapper update
Blagovest-Hristov 8c8c987
Revert "wrapper"
Blagovest-Hristov 944f082
uhhhh
Blagovest-Hristov 73b6c90
Merge branch 'master' into blago-branch
kaloyansarafov 5b58b1d
не
Matey-Nikolov 29beee0
Ig някакви подобрения по SexualPreferencesController?
Martin-Pashov 6139345
blago :)
Blagovest-Hristov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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>net7.0</TargetFramework> | ||
| <RootNamespace>DevDates_API_Wrapper</RootNamespace> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or 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,344 @@ | ||
| using System.Net.Http; | ||
| using System.Threading.Tasks; | ||
| using Newtonsoft.Json; | ||
|
|
||
| namespace DevDatesApiWrapper | ||
| { | ||
| public class DevDatesApiWrapper | ||
| { | ||
| private readonly HttpClient _httpClient; | ||
| private readonly string _baseUrl = "https://api.devdates.com/"; | ||
|
|
||
| public DevDatesApiWrapper() | ||
| { | ||
| _httpClient = new HttpClient(); | ||
| _httpClient.DefaultRequestHeaders.Add("Accept", "application/json"); | ||
| } | ||
|
|
||
| public async Task<User> GetUser(int id) | ||
| { | ||
| var response = await _httpClient.GetAsync($"{_baseUrl}users/{id}"); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<User>(json); | ||
| } | ||
|
|
||
| public async Task<Photo[]> GetPhotos(int id) | ||
| { | ||
| var response = await _httpClient.GetAsync($"{_baseUrl}users/{id}/photos"); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<Photo[]>(json); | ||
| } | ||
|
|
||
| public async Task<Interest[]> GetInterests(int id) | ||
| { | ||
| var response = await _httpClient.GetAsync($"{_baseUrl}users/{id}/interests"); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<Interest[]>(json); | ||
| } | ||
|
|
||
| public async Task<ConnectedService[]> GetConnectedServices(int id) | ||
| { | ||
| var response = await _httpClient.GetAsync($"{_baseUrl}users/{id}/connected-services"); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<ConnectedService[]>(json); | ||
| } | ||
|
|
||
| public async Task<SexualPreference[]> GetSexualPreferences(int id) | ||
| { | ||
| var response = await _httpClient.GetAsync($"{_baseUrl}users/{id}/sexual-preferences"); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<SexualPreference[]>(json); | ||
| } | ||
|
|
||
| public async Task<ShortUserInfo> GetShortUserInfo(int id) | ||
| { | ||
| var response = await _httpClient.GetAsync($"{_baseUrl}users/{id}/short-info"); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<ShortUserInfo>(json); | ||
| } | ||
|
|
||
| public async Task<DetailedUserInfo> GetDetailedUserInfo(int id) | ||
| { | ||
| var response = await _httpClient.GetAsync($"{_baseUrl}users/{id}/detailed-info"); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<DetailedUserInfo>(json); | ||
| } | ||
|
|
||
| public async Task<Photo> GetPhoto(int id, int photoId) | ||
| { | ||
| var response = await _httpClient.GetAsync($"{_baseUrl}users/{id}/photos/{photoId}"); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<Photo>(json); | ||
| } | ||
|
|
||
|
|
||
| public async Task<User> PostUser(int id) | ||
| { | ||
| var response = await _httpClient.PostAsync($"{_baseUrl}users/{id}", null); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<User>(json); | ||
|
|
||
| } | ||
|
|
||
| public async Task<Photo> PostPhoto(int id, int photoId) | ||
| { | ||
| var response = await _httpClient.PostAsync($"{_baseUrl}users/{id}/photos/{photoId}", null); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<Photo>(json); | ||
| } | ||
|
|
||
| public async Task<Interest> PostInterest(int id, int interestId) | ||
| { | ||
| var response = await _httpClient.PostAsync($"{_baseUrl}users/{id}/interests/{interestId}", null); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<Interest>(json); | ||
| } | ||
|
|
||
| public async Task<ConnectedService> PostConnectedService(int id, int connectedServiceId) | ||
| { | ||
| var response = await _httpClient.PostAsync($"{_baseUrl}users/{id}/connected-services/{connectedServiceId}", null); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<ConnectedService>(json); | ||
| } | ||
|
|
||
| public async Task<SexualPreference> PostSexualPreference(int id, int sexualPreferenceId) | ||
| { | ||
| var response = await _httpClient.PostAsync($"{_baseUrl}users/{id}/sexual-preferences/{sexualPreferenceId}", null); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<SexualPreference>(json); | ||
| } | ||
|
|
||
| public async Task<ShortUserInfo> PostShortUserInfo(int id) | ||
| { | ||
| var response = await _httpClient.PostAsync($"{_baseUrl}users/{id}/short-info", null); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<ShortUserInfo>(json); | ||
| } | ||
|
|
||
| public async Task<DetailedUserInfo> PostDetailedUserInfo(int id) | ||
| { | ||
| var response = await _httpClient.PostAsync($"{_baseUrl}users/{id}/detailed-info", null); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<DetailedUserInfo>(json); | ||
| } | ||
|
|
||
| public async Task<User> PutUser(int id) | ||
| { | ||
| var response = await _httpClient.PutAsync($"{_baseUrl}users/{id}", null); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<User>(json); | ||
|
|
||
| } | ||
|
|
||
| public async Task<Photo> PutPhoto(int id, int photoId) | ||
| { | ||
| var response = await _httpClient.PutAsync($"{_baseUrl}users/{id}/photos/{photoId}", null); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<Photo>(json); | ||
| } | ||
|
|
||
| public async Task<Interest> PutInterest(int id, int interestId) | ||
| { | ||
| var response = await _httpClient.PutAsync($"{_baseUrl}users/{id}/interests/{interestId}", null); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<Interest>(json); | ||
| } | ||
|
|
||
| public async Task<ConnectedService> PutConnectedService(int id, int connectedServiceId) | ||
| { | ||
| var response = await _httpClient.PutAsync($"{_baseUrl}users/{id}/connected-services/{connectedServiceId}", null); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<ConnectedService>(json); | ||
| } | ||
|
|
||
| public async Task<SexualPreference> PutSexualPreference(int id, int sexualPreferenceId) | ||
| { | ||
| var response = await _httpClient.PutAsync($"{_baseUrl}users/{id}/sexual-preferences/{sexualPreferenceId}", null); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<SexualPreference>(json); | ||
| } | ||
|
|
||
| public async Task<ShortUserInfo> PutShortUserInfo(int id) | ||
| { | ||
| var response = await _httpClient.PutAsync($"{_baseUrl}users/{id}/short-info", null); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<ShortUserInfo>(json); | ||
| } | ||
|
|
||
| public async Task<DetailedUserInfo> PutDetailedUserInfo(int id) | ||
| { | ||
| var response = await _httpClient.PutAsync($"{_baseUrl}users/{id}/detailed-info", null); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<DetailedUserInfo>(json); | ||
| } | ||
|
|
||
| public async Task<User> DeleteUser(int id) | ||
| { | ||
| var response = await _httpClient.DeleteAsync($"{_baseUrl}users/{id}"); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<User>(json); | ||
| } | ||
|
|
||
| public async Task<Photo> DeletePhoto(int id, int photoId) | ||
| { | ||
| var response = await _httpClient.DeleteAsync($"{_baseUrl}users/{id}/photos/{photoId}"); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<Photo>(json); | ||
| } | ||
|
|
||
| public async Task<Interest> DeleteInterest(int id, int interestId) | ||
| { | ||
| var response = await _httpClient.DeleteAsync($"{_baseUrl}users/{id}/interests/{interestId}"); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<Interest>(json); | ||
| } | ||
|
|
||
| public async Task<ConnectedService> DeleteConnectedService(int id, int connectedServiceId) | ||
| { | ||
| var response = await _httpClient.DeleteAsync($"{_baseUrl}users/{id}/connected-services/{connectedServiceId}"); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<ConnectedService>(json); | ||
| } | ||
|
|
||
| public async Task<SexualPreference> DeleteSexualPreference(int id, int sexualPreferenceId) | ||
| { | ||
| var response = await _httpClient.DeleteAsync($"{_baseUrl}users/{id}/sexual-preferences/{sexualPreferenceId}"); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<SexualPreference>(json); | ||
| } | ||
|
|
||
| public async Task<ShortUserInfo> DeleteShortUserInfo(int id) | ||
| { | ||
| var response = await _httpClient.DeleteAsync($"{_baseUrl}users/{id}/short-info"); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<ShortUserInfo>(json); | ||
| } | ||
|
|
||
| public async Task<DetailedUserInfo> DeleteDetailedUserInfo(int id) | ||
| { | ||
| var response = await _httpClient.DeleteAsync($"{_baseUrl}users/{id}/detailed-info"); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<DetailedUserInfo>(json); | ||
| } | ||
|
|
||
| public async Task<User> DeleteAll(int id) | ||
| { | ||
| var response = await _httpClient.DeleteAsync($"{_baseUrl}users/{id}/all"); | ||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var json = await response.Content.ReadAsStringAsync(); | ||
| return JsonConvert.DeserializeObject<User>(json); | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| public class User | ||
| { | ||
| public ShortUserInfo ShortInfo { get; set; } | ||
| public DetailedUserInfo DetailedInfo { get; set; } | ||
| public ConnectedService[] ConnectedServices { get; set; } | ||
| } | ||
|
|
||
| public record ShortUserInfo | ||
| { | ||
| public string Name { get; set; } | ||
| public int Age { get; set; } | ||
| public string Gender { get; set; } | ||
| public SexualPreference[] SexualPreferences { get; set; } | ||
| public Photo[] Photos { get; set; } | ||
| } | ||
|
|
||
| public record DetailedUserInfo | ||
| { | ||
| public ShortUserInfo? ShortInfo { get; set; } | ||
| public string Bio { get; set; } | ||
| public Interest[] Interests { get; set; } | ||
| } | ||
|
|
||
| public record ConnectedService | ||
| { | ||
| public string Name { get; set; } | ||
| public string Url { get; set; } | ||
| } | ||
|
|
||
| public record SexualPreference | ||
| { | ||
| public string Gender { get; set; } | ||
| public string Orientation { get; set; } | ||
| } | ||
|
|
||
| public record Photo | ||
| { | ||
| public string Url { get; set; } | ||
| public string Description { get; set; } | ||
| } | ||
|
|
||
| public record Interest | ||
| { | ||
| public string Name { get; set; } | ||
| public string Category { get; set; } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Няма нужда да имплементираш отново класовете, добави референция към другият проект и ги импортирай