Skip to content

Commit 8fd001e

Browse files
Added archive method
1 parent 17b44b0 commit 8fd001e

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ The following API methods have been implemented:
9090
- `product` Product register
9191
- `purchaseInvoices` Purchase invoices
9292
- `chartOfAccounts` Chart of Accounts
93+
- `archive` Archive of files
9394

9495
### Bookkeeping examples
9596

@@ -149,7 +150,8 @@ const product = await fivaldi.products.updateProductAllFields({
149150
});
150151

151152
// Update only the product fields that are given
152-
const product = await fivaldi.products.updateProduct({ purchaseCostPrice: 155 });
153+
const
154+
product = await fivaldi.products.updateProduct({ purchaseCostPrice: 155 });
153155

154156
// Create product language description (translation)
155157
const product = await fivaldi.products.createProductDescription(
@@ -205,6 +207,12 @@ const purchaseInvoiceComment = await fivaldi.purchaseInvoices.createPurchaseInvo
205207
const chartOfAccounts = await fivaldi.chartOfAccounts.getChartOfAccounts();
206208
```
207209

210+
### Archive of files example
211+
```ts
212+
// Get download url for the file with file id
213+
const downloadUrl = await fivaldi.archive.getFileUrl('123');
214+
```
215+
208216
## Resources
209217

210218
- Fivaldi website: https://www.visma.fi/visma-fivaldi/
@@ -216,4 +224,5 @@ const chartOfAccounts = await fivaldi.chartOfAccounts.getChartOfAccounts();
216224

217225
- 0.0.1 First release
218226
- 0.1.0 Added Chart of Accounts method and fixed error logic
219-
- 0.1.1 Updated dependencies
227+
- 0.1.1 Updated dependencies
228+
- 0.2.0 Added Archive of files method

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rantalainen/fivaldi-api-client",
3-
"version": "0.1.2",
3+
"version": "0.2.0",
44
"description": "Third party Fivaldi API client.",
55
"main": "dist/index.js",
66
"scripts": {

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import got, { Method, OptionsOfJSONResponseBody } from 'got';
22
import { IFivaldiApiClientOptions, IGetCompaniesParams, IGetCompaniesResponse } from './interfaces';
3+
import { ArchiveMethods } from './methods/archive.methods';
34
import { BookkeepingMethods } from './methods/bookkeeping.methods';
45
import { ChartOfAccountsMethods } from './methods/chart-of-accounts.methods';
56
import { ProductMethods } from './methods/products.methods';
@@ -13,6 +14,7 @@ export class FivaldiApiClient {
1314
readonly products: ProductMethods;
1415
readonly purchaseInvoices: PurchaseInvoicesMethods;
1516
readonly chartOfAccounts: ChartOfAccountsMethods;
17+
readonly archive: ArchiveMethods;
1618

1719
constructor(options: IFivaldiApiClientOptions) {
1820
options.apiBaseUrl = options.apiBaseUrl || 'https://api.fivaldi.net/customer/api';
@@ -32,6 +34,7 @@ export class FivaldiApiClient {
3234
this.products = new ProductMethods(this);
3335
this.purchaseInvoices = new PurchaseInvoicesMethods(this);
3436
this.chartOfAccounts = new ChartOfAccountsMethods(this);
37+
this.archive = new ArchiveMethods(this);
3538
}
3639

3740
async request(method: Method, url: string, body?: any, params?: any): Promise<any> {
@@ -59,7 +62,8 @@ export class FivaldiApiClient {
5962
let response: any;
6063
// If there is a body, parse and return it
6164
if (result.body) {
62-
response = JSON.parse(result.body);
65+
if (typeof result.body === 'object') response = JSON.parse(result.body);
66+
else response = result.body;
6367
} else {
6468
// Else just return the empty body
6569
response = result.body;

src/methods/archive.methods.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { FivaldiApiClient } from '../index';
2+
import { Methods } from '../methods';
3+
4+
export class ArchiveMethods extends Methods {
5+
constructor(apiClient: FivaldiApiClient) {
6+
super(apiClient, '/archive');
7+
}
8+
9+
/** Gets download url for a file. */
10+
async getFileUrl(fileId: string): Promise<String> {
11+
return await super.request('GET', `/files/${fileId}`);
12+
}
13+
}

0 commit comments

Comments
 (0)