Skip to content

Commit f890c58

Browse files
authored
Merge pull request #3 from Wish-Org:feat/Add-Organization
Add organization API with tests and update version to 2.7.0
2 parents 945b788 + c0368dd commit f890c58

6 files changed

Lines changed: 102 additions & 1 deletion

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
3+
namespace HelpScoutSharp.Tests;
4+
5+
[TestClass]
6+
public class OrganizationService_Tests
7+
{
8+
private OrganizationService _service;
9+
10+
[TestInitialize]
11+
public async Task Initialize()
12+
{
13+
HelpScoutHttpClient.RateLimitBreachBehavior = RateLimitBreachBehavior.WaitAndRetryOnce;
14+
var authSvc = new AuthenticationService();
15+
var token = await authSvc.GetApplicationTokenAsync(TestHelper.ApplicationId, TestHelper.ApplicationSecret);
16+
_service = new OrganizationService(token.access_token);
17+
}
18+
19+
[TestMethod]
20+
public async Task GetOrganizationAsync_Works()
21+
{
22+
var res = await _service.ListAsync();
23+
var organization = await _service.GetAsync(res.entities[0].id);
24+
Assert.IsTrue(organization.id > 0);
25+
}
26+
27+
[TestMethod]
28+
public async Task ListOrganizationsAsync_Works()
29+
{
30+
var res = await _service.ListAsync(new ListOrganizationsOptions());
31+
Assert.IsTrue(res.page.size > 0);
32+
}
33+
}

HelpScoutSharp/HelpScoutSharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<Version>2.6.3</Version>
4+
<Version>2.7.0</Version>
55
<Company>Better Reports</Company>
66
<Product>Help Scout API Client for .NET</Product>
77
<Authors>Better Reports</Authors>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace HelpScoutSharp;
2+
3+
public class ListOrganizationsOptions : ListOptions
4+
{
5+
public string sort { get; set; }
6+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace HelpScoutSharp;
2+
3+
public class Organization : IHasId
4+
{
5+
public long id { get; set; }
6+
7+
public string name { get; set; }
8+
9+
public string website { get; set; }
10+
11+
public string description { get; set; }
12+
13+
public string location { get; set; }
14+
15+
public string logoUrl { get; set; }
16+
17+
public string[] domains { get; set; }
18+
19+
public string[] phones { get; set; }
20+
21+
public string brandColor { get; set; }
22+
23+
public long customerCount { get; set; }
24+
25+
public long conversationCount { get; set; }
26+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace HelpScoutSharp;
2+
3+
public class OrganizationPage : IPage<Organization>
4+
{
5+
public class Embedded
6+
{
7+
public Organization[] organizations { get; set; }
8+
}
9+
10+
public Embedded _embedded { get; set; }
11+
12+
public Page page { get; set; }
13+
14+
public Organization[] entities => _embedded.organizations;
15+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Flurl;
2+
3+
namespace HelpScoutSharp;
4+
5+
public class OrganizationService : ServiceBase, IListableService<Organization, ListOrganizationsOptions>
6+
{
7+
public OrganizationService(string accessToken)
8+
: base(accessToken, "organizations")
9+
{
10+
}
11+
12+
public async Task<Organization> GetAsync(long organizationId)
13+
{
14+
return await _client.GetAsync<Organization>(new Url(_serviceUri).AppendPathSegment(organizationId).ToUri());
15+
}
16+
17+
public async Task<IPage<Organization>> ListAsync(ListOrganizationsOptions options = null)
18+
{
19+
return await _client.GetAsync<OrganizationPage>(_serviceUri, options);
20+
}
21+
}

0 commit comments

Comments
 (0)