Skip to content

Commit d58e3d8

Browse files
author
David Warner
committed
Add missing awaits; add analysers
1 parent e690bc4 commit d58e3d8

20 files changed

+376
-372
lines changed

Xero.Api/Common/XeroReadEndpoint.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ public T UseFourDecimalPlaces(bool use4Dp)
7474
return Apply4Dp(use4Dp);
7575
}
7676

77-
public virtual async Task<IEnumerable<TResult>> FindAsync()
77+
public virtual Task<IEnumerable<TResult>> FindAsync()
7878
{
79-
return await GetAsync(ApiEndpointUrl, null).ConfigureAwait(false);
79+
return GetAsync(ApiEndpointUrl, null);
8080
}
8181

82-
public virtual async Task<TResult> FindAsync(Guid child)
82+
public virtual Task<TResult> FindAsync(Guid child)
8383
{
84-
return await FindAsync(child.ToString("D")).ConfigureAwait(false);
84+
return FindAsync(child.ToString("D"));
8585
}
8686

8787
public async Task<TResult> FindAsync(string child)

Xero.Api/Core/Endpoints/AttachmentsEndpoint.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public AttachmentsEndpoint(XeroHttpClient client)
2121
Client = client;
2222
}
2323

24-
public async Task<IEnumerable<Attachment>> ListAsync(AttachmentEndpointType type, Guid parent)
24+
public Task<IEnumerable<Attachment>> ListAsync(AttachmentEndpointType type, Guid parent)
2525
{
26-
return await Client.GetAsync<Attachment, AttachmentsResponse>(string.Format("/api.xro/2.0/{0}/{1}/Attachments", type, parent.ToString("D"))).ConfigureAwait(false);
26+
return Client.GetAsync<Attachment, AttachmentsResponse>(string.Format("/api.xro/2.0/{0}/{1}/Attachments", type, parent.ToString("D")));
2727
}
2828

2929
public async Task<Attachment> GetAsync(AttachmentEndpointType type, Guid parent, string fileName)

Xero.Api/Core/Endpoints/Base/XeroCreateEndpoint.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ protected XeroCreateEndpoint(XeroHttpClient client, string apiEndpointUrl)
1818
{
1919
}
2020

21-
public async Task<IEnumerable<TResult>> CreateAsync(IEnumerable<TResult> items)
21+
public Task<IEnumerable<TResult>> CreateAsync(IEnumerable<TResult> items)
2222
{
2323
var request = new TRequest();
2424
request.AddRange(items);
2525

26-
return await PutAsync(request).ConfigureAwait(false);
26+
return PutAsync(request);
2727
}
2828

2929
public async Task<TResult> CreateAsync(TResult item)

Xero.Api/Core/Endpoints/Base/XeroUpdateEndpoint.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ protected XeroUpdateEndpoint(XeroHttpClient client, string apiEndpointUrl)
1818
{
1919
}
2020

21-
public async Task<IEnumerable<TResult>> UpdateAsync(IEnumerable<TResult> items)
21+
public Task<IEnumerable<TResult>> UpdateAsync(IEnumerable<TResult> items)
2222
{
2323
var request = new TRequest();
2424
request.AddRange(items);
2525

26-
return await PostAsync(request).ConfigureAwait(false);
26+
return PostAsync(request);
2727
}
2828

2929
public virtual async Task<TResult> UpdateAsync(TResult item)

Xero.Api/Core/Endpoints/ContactGroupEndpoint.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public async Task ClearContactsAsync(ContactGroup contactGroup)
3535
await HandleResponseAsync(response).ConfigureAwait(false);
3636
}
3737

38-
public async Task AddContactAsync(ContactGroup contactGroup, Contact contact)
38+
public Task AddContactAsync(ContactGroup contactGroup, Contact contact)
3939
{
40-
await AddContactsAsync(contactGroup, new List<Contact>{contact}).ConfigureAwait(false);
40+
return AddContactsAsync(contactGroup, new List<Contact> { contact });
4141
}
4242

4343
public async Task AddContactsAsync(ContactGroup contactGroup, List<Contact> contacts)

Xero.Api/Core/Endpoints/FilesEndpoint.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public IFilesEndpoint Page(int page)
7070
FolderId = newFolder
7171
};
7272

73-
var response = await Client.PutAsync("files.xro/1.0/Files/" + id, file, true).ConfigureAwait(false);
73+
var response = await Client.PutAsync("files.xro/1.0/Files/" + id, file, true).ConfigureAwait(false);
7474
return await HandleFileResponseAsync(response).ConfigureAwait(false);
7575
}
7676

@@ -91,7 +91,6 @@ public async Task<byte[]> GetContentAsync(Guid id, string contentType)
9191
var response = await Client.GetRawAsync("files.xro/1.0/Files/" + id + "/Content", contentType).ConfigureAwait(false);
9292

9393
return await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
94-
9594
}
9695

9796
private async Task<Model.File> HandleFileResponseAsync(HttpResponseMessage response)

Xero.Api/Core/Endpoints/FoldersEndpoint.cs

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -21,94 +21,94 @@ public interface IFoldersEndpoint : IXeroUpdateEndpoint<FoldersEndpoint, Folder,
2121
}
2222

2323
public class FoldersEndpoint : XeroUpdateEndpoint<FoldersEndpoint, Folder, FolderRequest, FolderResponse>, IFoldersEndpoint
24-
{
25-
internal FoldersEndpoint(XeroHttpClient client)
26-
: base(client, "files.xro/1.0/Folders")
2724
{
25+
internal FoldersEndpoint(XeroHttpClient client)
26+
: base(client, "files.xro/1.0/Folders")
27+
{
2828

29-
}
29+
}
3030

31-
public async Task<FilePageResponse> AddAsync(string folderName)
32-
{
33-
var endpoint = "files.xro/1.0/Folders";
31+
public async Task<FilePageResponse> AddAsync(string folderName)
32+
{
33+
var endpoint = "files.xro/1.0/Folders";
3434

35-
var response = await Client.PostAsync(endpoint, new Folder{Name = folderName}, true).ConfigureAwait(false);
35+
var response = await Client.PostAsync(endpoint, new Folder { Name = folderName }, true).ConfigureAwait(false);
3636

37-
return await HandleFolderResponseAsync(response).ConfigureAwait(false);
38-
}
37+
return await HandleFolderResponseAsync(response).ConfigureAwait(false);
38+
}
3939

40-
public new async Task<IEnumerable<Folder>> FindAsync()
41-
{
42-
var response = await Client.GetAsync("files.xro/1.0/Folders", "").ConfigureAwait(false);
43-
var result = await HandleFoldersResponseAsync(response).ConfigureAwait(false);
40+
public new async Task<IEnumerable<Folder>> FindAsync()
41+
{
42+
var response = await Client.GetAsync("files.xro/1.0/Folders", "").ConfigureAwait(false);
43+
var result = await HandleFoldersResponseAsync(response).ConfigureAwait(false);
4444

4545

46-
var resultingFolders = from i in result
47-
select new Folder() { Id = i.Id, Name = i.Name, IsInbox = i.IsInbox, FileCount = i.FileCount };
46+
var resultingFolders = from i in result
47+
select new Folder { Id = i.Id, Name = i.Name, IsInbox = i.IsInbox, FileCount = i.FileCount };
4848

49-
return resultingFolders.ToList();
50-
}
49+
return resultingFolders.ToList();
50+
}
5151

52-
public async Task RemoveAsync(Guid id)
53-
{
54-
var response = await Client.DeleteAsync("files.xro/1.0/Folders/" + id).ConfigureAwait(false);
55-
await HandleFolderResponseAsync(response).ConfigureAwait(false);
56-
}
52+
public async Task RemoveAsync(Guid id)
53+
{
54+
var response = await Client.DeleteAsync("files.xro/1.0/Folders/" + id).ConfigureAwait(false);
55+
await HandleFolderResponseAsync(response).ConfigureAwait(false);
56+
}
5757

58-
public async Task<FoldersResponse> RenameAsync(Guid id, string name)
59-
{
60-
var folder = new Folder
61-
{
62-
Name = name
63-
};
64-
65-
var response = await Client.PutAsync("files.xro/1.0/Folders/" + id, folder, true).ConfigureAwait(false);
66-
var result = await HandleFoldersResponseAsync(response).ConfigureAwait(false);
67-
return result?[0];
68-
}
58+
public async Task<FoldersResponse> RenameAsync(Guid id, string name)
59+
{
60+
var folder = new Folder
61+
{
62+
Name = name
63+
};
6964

70-
private async Task<FilePageResponse> HandleFolderResponseAsync(HttpResponseMessage response)
71-
{
72-
if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Created)
73-
{
74-
var body = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
65+
var response = await Client.PutAsync("files.xro/1.0/Folders/" + id, folder, true).ConfigureAwait(false);
66+
var result = await HandleFoldersResponseAsync(response).ConfigureAwait(false);
67+
return result?[0];
68+
}
7569

76-
var result = Client.JsonMapper.From<FilePageResponse>(body);
70+
private async Task<FilePageResponse> HandleFolderResponseAsync(HttpResponseMessage response)
71+
{
72+
if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Created)
73+
{
74+
var body = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
7775

78-
return result;
79-
}
76+
var result = Client.JsonMapper.From<FilePageResponse>(body);
8077

81-
await Client.HandleErrorsAsync(response).ConfigureAwait(false);
78+
return result;
79+
}
8280

83-
return null;
84-
}
81+
await Client.HandleErrorsAsync(response).ConfigureAwait(false);
8582

86-
private async Task<FoldersResponse[]> HandleFoldersResponseAsync(HttpResponseMessage response)
87-
{
88-
if (response.StatusCode == HttpStatusCode.OK)
89-
{
90-
var body = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
83+
return null;
84+
}
9185

92-
var result = Client.JsonMapper.From<FoldersResponse[]>(body);
86+
private async Task<FoldersResponse[]> HandleFoldersResponseAsync(HttpResponseMessage response)
87+
{
88+
if (response.StatusCode == HttpStatusCode.OK)
89+
{
90+
var body = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
9391

94-
return result;
95-
}
92+
var result = Client.JsonMapper.From<FoldersResponse[]>(body);
9693

97-
await Client.HandleErrorsAsync(response).ConfigureAwait(false);
94+
return result;
95+
}
9896

99-
return null;
97+
await Client.HandleErrorsAsync(response).ConfigureAwait(false);
98+
99+
return null;
100+
}
100101
}
101-
}
102102

103-
public class FolderResponse : XeroResponse<Folder>
104-
{
105-
public override IList<Folder> Values
103+
public class FolderResponse : XeroResponse<Folder>
106104
{
107-
get { throw new NotImplementedException(); }
105+
public override IList<Folder> Values
106+
{
107+
get { throw new NotImplementedException(); }
108+
}
108109
}
109-
}
110110

111-
public class FolderRequest : XeroRequest<Folder>
112-
{
113-
}
111+
public class FolderRequest : XeroRequest<Folder>
112+
{
113+
}
114114
}

Xero.Api/Core/Endpoints/HistoryAndNotesEndpoint.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public HistoryAndNotesEndpoint(XeroHttpClient client)
2525
Client = client;
2626
}
2727

28-
public async Task<IEnumerable<HistoryRecord>> FindAsync(HistoryAndNotesEndpointRetrieveType type, Guid parent)
28+
public Task<IEnumerable<HistoryRecord>> FindAsync(HistoryAndNotesEndpointRetrieveType type, Guid parent)
2929
{
30-
return await Client.GetAsync<HistoryRecord, HistoryRecordsResponse>($"api.xro/2.0/{type}/{parent:D}/history").ConfigureAwait(false);
30+
return Client.GetAsync<HistoryRecord, HistoryRecordsResponse>($"api.xro/2.0/{type}/{parent:D}/history");
3131
}
3232

3333
public async Task<HistoryRecord> CreateNoteAsync(HistoryAndNotesEndpointCreateType type, Guid parent, HistoryRecord note)

0 commit comments

Comments
 (0)