private async Task <EntityElements <Share> > GetPostsAsync(string ownerURN, int sharesPerOwner = 100) { CheckTokenThenAddToHeaders(); var response = await _client.GetAsync($"{_apiHost}v2/shares?q=owners&owners={ownerURN}&sharesPerOwner={sharesPerOwner}"); var responseJson = await response.Content.ReadAsStringAsync(); var shares = EntityElements <Share> .FromJson(responseJson); if (!response.IsSuccessStatusCode) { throw new ApiException(ExceptionModel.FromJson(responseJson)); } return(shares); }
/// <summary> /// Get list of companies which authorized user have approved ADMINISTRATOR role on these companies, required r_organization permission /// </summary> /// <exception cref="ApiException"></exception> /// <returns></returns> public async Task <Organization[]> GetCompaniesAsync() { CheckTokenThenAddToHeaders(); var response = await _client.GetAsync($"{_apiHost}v2/organizationalEntityAcls?q=roleAssignee&role=ADMINISTRATOR"); var responseJson = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { throw new ApiException(ExceptionModel.FromJson(await response.Content.ReadAsStringAsync())); } var organizationalEntityAcls = EntityElements <OrganizationalAccess> .FromJson(responseJson); var ownCompaniesId = new List <long>(); foreach (var element in organizationalEntityAcls.Elements) { if (element.Role == "ADMINISTRATOR" && element.State == "APPROVED") { long id = long.Parse(element.OrganizationalTarget.Split(':').Last()); ownCompaniesId.Add(id); } } var companiesList = new List <Organization>(); foreach (var companyId in ownCompaniesId) { response = await _client.GetAsync($"{_apiHost}v2/organizations/{companyId}"); if (!response.IsSuccessStatusCode) { throw new ApiException(ExceptionModel.FromJson(await response.Content.ReadAsStringAsync())); } responseJson = await response.Content.ReadAsStringAsync(); companiesList.Add(Organization.FromJson(responseJson)); } return(companiesList.ToArray()); }