-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from kvithana/master
feat: add Tags endpoints
- Loading branch information
Showing
6 changed files
with
170 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { ListTagsRequest, ListTagsResponse, TagInputResourceIdentifier } from './interfaces'; | ||
import { UpClient } from '../helper/client'; | ||
|
||
const LIST_ENDPOINT = 'tags'; | ||
const TRANSACTION_ENDPOINT = 'transactions'; | ||
|
||
/** | ||
* Tags are custom labels that can be associated with transactions on Up. Within | ||
* the Up application, tags provide additional insight into spending. For | ||
* example, you could have a "Take Away" tag that you apply to purchases from | ||
* food delivery services. The Up API allows you to manage the tags associated | ||
* with transactions. Each transaction may have up to 6 tags. | ||
*/ | ||
export class TagsApi { | ||
constructor(private api: UpClient) {} | ||
|
||
/** | ||
* Retrieve a list of all tags currently in use. The returned list is not | ||
* paginated. | ||
*/ | ||
public async list(params: ListTagsRequest = {}): Promise<{ data: ListTagsResponse[] }> { | ||
const urlParams = []; | ||
if (params.pageSize) { | ||
urlParams.push(`page[size]=${params.pageSize}`); | ||
} | ||
|
||
return this.api.get<{ data: ListTagsResponse[] }>(`${LIST_ENDPOINT}?${urlParams.join('&')}`); | ||
} | ||
|
||
/** | ||
* Associates one or more tags with a specific transaction. No more than 6 | ||
* tags may be present on any single transaction. Duplicate tags are silently | ||
* ignored. | ||
* @param transactionId The unique identifier for the transaction. e.g. | ||
* 0a3c4bdd-1de5-4b9b-bf9e-53fb0b5f2cd7 | ||
* @param tags The tags to add to the transaction. | ||
*/ | ||
public async addTagsToTransaction( | ||
transactionId: string, | ||
tags: TagInputResourceIdentifier[] | ||
): Promise<void> { | ||
return this.api.post(TagsApi.buildTransactionTagsPath(transactionId), tags); | ||
} | ||
|
||
/** | ||
* Disassociates one or more tags from a specific transaction. Tags that are | ||
* not associated are silently ignored. | ||
* @param transactionId The unique identifier for the transaction. e.g. | ||
* 0a3c4bdd-1de5-4b9b-bf9e-53fb0b5f2cd7 | ||
* @param tags The tags to remove from the transaction. | ||
*/ | ||
public async removeTagsFromTransaction( | ||
transactionId: string, | ||
tags: TagInputResourceIdentifier[] | ||
): Promise<void> { | ||
return this.api.delete(TagsApi.buildTransactionTagsPath(transactionId), tags); | ||
} | ||
|
||
/** | ||
* Build API path to access the tags for a given transaction. | ||
* @param transactionId The unique identifier for the transaction. e.g. | ||
* 0a3c4bdd-1de5-4b9b-bf9e-53fb0b5f2cd7 | ||
*/ | ||
private static buildTransactionTagsPath(transactionId: string) { | ||
return `${TRANSACTION_ENDPOINT}/${transactionId}/relationships/tags`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* Provides information about a tag. | ||
*/ | ||
export interface TagResource { | ||
/** | ||
* The type of this resource: `tags` | ||
*/ | ||
type: string; | ||
/** | ||
* The label of the tag, which also acts as the tag’s unique identifier. | ||
*/ | ||
id: string; | ||
relationships: { | ||
transactions: { | ||
links?: { | ||
/** | ||
* The link to retrieve the related resource(s) in this relationship. | ||
*/ | ||
related: string; | ||
}; | ||
}; | ||
}; | ||
} | ||
|
||
/** | ||
* Uniquely identifies a single tag in the API. | ||
*/ | ||
export interface TagInputResourceIdentifier { | ||
/** | ||
* The type of this resource: `tags` | ||
*/ | ||
type: string; | ||
/** | ||
* The label of the tag, which also acts as the tag’s unique identifier. | ||
*/ | ||
id: string; | ||
} | ||
|
||
export interface ListTagsRequest { | ||
/** The number of records to return in each page. e.g. ?page[size]=30 */ | ||
pageSize?: number; | ||
} | ||
|
||
/** | ||
* Successful response to get all tags. This returns a paginated list of | ||
* tags, which can be scrolled by following the `prev` and `next` links if | ||
* present. | ||
*/ | ||
export interface ListTagsResponse { | ||
/** | ||
* The list of tags returned in this response. | ||
*/ | ||
data: TagResource; | ||
links: { | ||
/** | ||
* The link to the previous page in the results. If this value is `null` | ||
* there is no previous page. | ||
*/ | ||
prev: string | null; | ||
/** | ||
* The link to the next page in the results. If this value is `null` | ||
* there is no next page. | ||
*/ | ||
next: string | null; | ||
}; | ||
} | ||
|
||
/** | ||
* Request to add or remove tags associated with a transaction. | ||
*/ | ||
export interface UpdateTransactionTagsRequest { | ||
/** | ||
* The tags to add to or remove from the transaction. | ||
*/ | ||
data: TagInputResourceIdentifier; | ||
} |