Пример #1
0
    public async Task <Matches> QueryInvoices(string?queryString = null,
                                              ulong?offset       = null,
                                              long?limit         = null,
                                              bool?strict        = null,
                                              string?semVer      = null,
                                              bool?yanked        = null)
    {
        var query    = GetDistinctInvoicesNamesQueryString(queryString, offset, limit, strict, semVer, yanked);
        var uri      = new Uri(_baseUri, $"{QUERY_PATH}?{query}");
        var response = await _httpClient.GetAsync(uri);

        await ExpectResponseCode(response, HttpStatusCode.OK, HttpStatusCode.Forbidden);

        if (response.StatusCode == HttpStatusCode.Forbidden)
        {
            throw new BindleProtocolException($"Bindle server returned status code {response.StatusCode}: {await response.Content.ReadAsStringAsync()}", response);
        }

        var content = await response.Content.ReadAsStringAsync();

        var syntax      = GetTomlSyntax(content);
        var tomlOptions = new TomlModelOptions()
        {
            ConvertPropertyName = name => TomlNamingHelper.PascalToCamelCase(name)
        };

        return(syntax.ToModel <Matches>(tomlOptions));
    }
Пример #2
0
    public async Task <Invoice> GetInvoice(string invoiceId, GetInvoiceOptions options = GetInvoiceOptions.None)
    {
        var query    = GetInvoiceQueryString(options);
        var uri      = new Uri(_baseUri, $"{INVOICE_PATH}/{invoiceId}{query}");
        var response = await _httpClient.GetAsync(uri);

        await ExpectResponseCode(response, HttpStatusCode.OK, HttpStatusCode.Forbidden);

        if (response.StatusCode == HttpStatusCode.Forbidden)
        {
            if ((options & GetInvoiceOptions.IncludeYanked) == 0)
            {
                throw new BindleYankedException();
            }
            else
            {
                throw new BindleProtocolException($"Bindle server returned status code {response.StatusCode}: {await response.Content.ReadAsStringAsync()}", response);
            }
        }

        var content = await response.Content.ReadAsStringAsync();

        var syntax      = GetTomlSyntax(content);
        var tomlOptions = new TomlModelOptions()
        {
            ConvertPropertyName = name => TomlNamingHelper.PascalToCamelCase(name)
        };

        return(syntax.ToModel <Invoice>(tomlOptions));
    }
Пример #3
0
    public async Task <MissingParcelsResponse> ListMissingParcels(string invoiceId)
    {
        var uri      = new Uri(_baseUri, $"{RELATIONSHIP_PATH}/missing/{invoiceId}");
        var response = await _httpClient.GetAsync(uri);

        await ExpectResponseCode(response, HttpStatusCode.OK);

        var content = await response.Content.ReadAsStringAsync();

        var syntax      = GetTomlSyntax(content);
        var tomlOptions = new TomlModelOptions()
        {
            ConvertPropertyName = name => TomlNamingHelper.PascalToCamelCase(name)
        };

        return(syntax.ToModel <MissingParcelsResponse>(tomlOptions));
    }
Пример #4
0
    public async Task <CreateInvoiceResult> CreateInvoice(Invoice invoice)
    {
        var invoiceToml = Toml.FromModel(invoice, new TomlModelOptions()
        {
            ConvertPropertyName = name => TomlNamingHelper.PascalToCamelCase(name)
        });

        var uri            = new Uri(_baseUri, INVOICE_PATH);
        var requestContent = new StringContent(invoiceToml, null, "application/toml");
        var response       = await _httpClient.PostAsync(uri, requestContent);

        await ExpectResponseCode(response, HttpStatusCode.Created, HttpStatusCode.Accepted);

        var content = await response.Content.ReadAsStringAsync();

        var syntax      = GetTomlSyntax(content);
        var tomlOptions = new TomlModelOptions()
        {
            ConvertPropertyName = name => TomlNamingHelper.PascalToCamelCase(name)
        };

        return(syntax.ToModel <CreateInvoiceResult>(tomlOptions));
    }