public async Task <Team> GetTeamAsync(long teamId)
    {
        if (teamId <= 0)
        {
            throw new ArgumentOutOfRangeException(nameof(teamId));
        }

        string str = await _httpClient.GetStringAsync(string.Format(TeamByIdQueryTemplate, teamId));

        ReadDocument doc = JsonConvert.DeserializeObject <ReadDocument>(str);

        return(doc.UnpackTeams().FirstOrDefault());
    }
    public async Task <IEnumerable <Team> > GetActiveTeamsForUser(int userId)
    {
        if (userId <= 0)
        {
            throw new ArgumentOutOfRangeException(nameof(userId));
        }

        string str = await _httpClient.GetStringAsync(string.Format(ActiveTeamsQueryTemplate, userId));

        ReadDocument doc = JsonConvert.DeserializeObject <ReadDocument>(str);

        return(doc.UnpackTeams().ToList());
    }
    public async Task <long> CreateTeam(CreateTeamRequest team)
    {
        WriteDocument doc = new WriteDocument
        {
            Template = new Template()
        };

        doc.Template.Data.Add(new Data()
        {
            Name = "name", Value = team.Name
        });
        doc.Template.Data.Add(new Data()
        {
            Name = "sport_id", Value = team.SportId
        });
        doc.Template.Data.Add(new Data()
        {
            Name = "location_country", Value = team.LocationCountry
        });
        doc.Template.Data.Add(new Data()
        {
            Name = "time_zone", Value = team.IANATimeZone
        });
        doc.Template.Data.Add(new Data()
        {
            Name = "location_postal_code", Value = team.LocationPostalCode
        });

        HttpResponseMessage resp = await _httpClient.PostAsJsonAsync("/teams", doc);

        string str = await resp.Content.ReadAsStringAsync();

        ReadDocument rDoc = JsonConvert.DeserializeObject <ReadDocument>(str);

        if (resp.IsSuccessStatusCode)
        {
            return(rDoc.UnpackTeams().First().Id);
        }
        else
        {
            throw new HttpRequestException(rDoc.Collection.Error.Message);
        }
    }