kevbite / CompaniesHouse.NET

A simple .NET client wrapper for CompaniesHouse API
MIT License
37 stars 44 forks source link

Downloading files #69

Closed AlwaysVbNet closed 4 years ago

AlwaysVbNet commented 6 years ago

Kev, at the moment I'm downloading the files like the code below. How could I download a PDF file via your DLL? I've noticed that the method GetCompanyFilingHistoryAsync fetches information and provides a URL within each item in the Links list. Do you provide any method to download those files? What do you suggest?

Dim baseAddress As New Uri("http://document-api.companieshouse.gov.uk")
Dim client As HttpClient = New HttpClient With {.BaseAddress = baseAddress}
client.DefaultRequestHeaders.Authorization = New Headers.AuthenticationHeaderValue("Basic", System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("xxxxxxxxxxxxx")))
client.DefaultRequestHeaders.Add("Accept", "application/pdf")          
Dim Content = client.GetByteArrayAsync("document/FIxRR8teCKodjkBLRDHv2Cb8y0-nQ7T5G3BEXfWtOu4/content").Result
kevbite commented 6 years ago

Hello, At the moment we don't have anything built into our API wrapper for this yet, however, if it's something you'd like including I don't think it would be much effort to include this within our library.

It's all documented on their website - https://developer.companieshouse.gov.uk/document/docs/

The code that you provided should work perfectly fine as a short-term solution if you need to write them physically to disk you can just use the method on File class within the System.IO namespace File.WriteAllBytes(string, byte[]) more info can be found here

AlwaysVbNet commented 6 years ago

Cool. It would be a nice add on. Also it would be great if a prospective function could provide the option to return a base64 string like above or write to file.

kevbite commented 6 years ago

We'll most likely pass back a Stream, in which you can use to write to a file. I'll make sure I update the readme with some details.

Linking #70 & #71