Skip to content

Commit

Permalink
begin to refactor this repository to the new jmpa-io sdk standard
Browse files Browse the repository at this point in the history
  • Loading branch information
jcleal committed Jan 3, 2025
1 parent 18ce4e1 commit a4ed423
Show file tree
Hide file tree
Showing 36 changed files with 639 additions and 1,106 deletions.
12 changes: 4 additions & 8 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
root = true

[*]
end_of_line = lf
indent_style = space
indent_size = 2
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
spaces_around_operators = true
spaces_around_brackets = false
indent_style = space
indent_size = 2

[{Makefile,go.mod,go.sum,*.go,.gitmodules}]
[Makefile*]
indent_style = tab
indent_size = 4

[Dockerfile]
indent_size = 4
3 changes: 3 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
ignore:
- cmd/example/
13 changes: 13 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
version: 2
updates:
- package-ecosystem: gomod
directory: /
schedule:
interval: daily
open-pull-requests-limit: 10
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
open-pull-requests-limit: 10
38 changes: 30 additions & 8 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,47 @@
name: CI/CD
on:
push:
paths:
- '.github/workflows/cicd.yml'
- 'bin/*'
- 'cf/**'
- 'cmd/**'
- 'templates/**'
- '**Dockerfile'
- 'Makefile*'
workflow_dispatch:
repository_dispatch:
types: [trigger]
types: [update-cicd]

permissions:
id-token: write
contents: read
actions: read

jobs:
lint:
uses: jmpa-io/depot/.github/workflows/lint.yml@main
uses: jmpa-io/pipelines/.github/workflows/10-lint.yml@main
secrets:
github-token: ${{ secrets.ADMIN_GITHUB_TOKEN }}
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_RUNNER_ROLE_NAME: ${{ secrets.AWS_RUNNER_ROLE_NAME }}
ADMIN_GITHUB_TOKEN: ${{ secrets.ADMIN_GITHUB_TOKEN }}

test:
uses: jmpa-io/depot/.github/workflows/test.yml@main
uses: jmpa-io/pipelines/.github/workflows/20-test.yml@main
with:
with-code-coverage: true
secrets:
github-token: ${{ secrets.ADMIN_GITHUB_TOKEN }}
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_RUNNER_ROLE_NAME: ${{ secrets.AWS_RUNNER_ROLE_NAME }}
ADMIN_GITHUB_TOKEN: ${{ secrets.ADMIN_GITHUB_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

post-to-slack:
needs: [lint, test]
if: always()
uses: jmpa-io/depot/.github/workflows/post-to-slack.yml@main
uses: jmpa-io/pipelines/.github/workflows/99-post-to-slack.yml@main
secrets:
github-token: ${{ secrets.ADMIN_GITHUB_TOKEN }}
slack-webhook: ${{ secrets.SLACK_GITHUB_WEBHOOK_URL }}
WEBHOOK: ${{ secrets.SLACK_GITHUB_NOTIFICATIONS_WEBHOOK }}

18 changes: 18 additions & 0 deletions .github/workflows/dependabot-automerge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: Dependabot | Auto-merge
on:
pull_request:
types: [opened, synchronize]
repository_dispatch:
types: [update-dependabot-automerge]

permissions:
contents: write
pull-requests: write
checks: read
statuses: read

jobs:
dependabot-automerge:
if: startsWith(github.head_ref, 'dependabot/')
uses: jmpa-io/pipelines/.github/workflows/00-dependabot-automerge.yml@main
25 changes: 14 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# ignore general files.
.DS_store
.DS_Store
.vscode/

# ignore test files.
out
test.sh
# ignore generated files.
/out
package.yml
coverage.*
dist/
*.zip
*.pem
traces.txt

# ignore log files.
super-linter.log
# ignore test files.
/test.sh

# ignore folders generated via CI/CD.
/depot
/bin/[0-9][0-9]-*.sh
/cf/[0-9][0-9]-*.yml
/.github/templates/[0-9][0-9]-*
# ignore compiled binaries in root.
/main
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

# Default PROJECT, if not given by another Makefile.
ifndef PROJECT
PROJECT=pocketsmith-go
endif

# Targets.
example: binary-go-example
run: example
PHONY += run

---: ## ---

# Includes the common Makefile.
# NOTE: this recursively goes back and finds the `.git` directory and assumes
# this is the root of the project. This could have issues when this assumtion
# is incorrect.
include $(shell while [[ ! -d .git ]]; do cd ..; done; pwd)/Makefile.common.mk

29 changes: 23 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
<!-- markdownlint-disable MD041 MD010 -->
[![pocketsmith-go](https://github.com/jmpa-io/pocketsmith-go/actions/workflows/cicd.yml/badge.svg)](https://github.com/jmpa-io/pocketsmith-go/actions/workflows/cicd.yml)
[![pocketsmith-go](https://github.com/jmpa-io/pocketsmith-go/actions/workflows/README.yml/badge.svg)](https://github.com/jmpa-io/pocketsmith-go/actions/workflows/README.yml)

<p align="center">
<img src="img/logo.png"/>
</p>

# `pocketsmith-go`
## `pocketsmith-go`

```diff
+ 📚 A Go abstraction over the Pocketsmith API:
+ https://developers.pocketsmith.com/docs.
+ 📚 A Go abstraction over the Pocketsmith API: https://developers.pocketsmith.com/docs.
```

<a href="LICENSE" target="_blank"><img src="https://img.shields.io/github/license/jmpa-io/pocketsmith-go.svg" alt="GitHub License"></a>
[![CI/CD](https://github.com/jmpa-io/pocketsmith-go/actions/workflows/cicd.yml/badge.svg)](https://github.com/jmpa-io/pocketsmith-go/actions/workflows/cicd.yml)
[![Automerge](https://github.com/jmpa-io/pocketsmith-go/actions/workflows/.github/workflows/dependabot-automerge.yml/badge.svg)](https://github.com/jmpa-io/pocketsmith-go/actions/workflows/.github/workflows/dependabot-automerge.yml)
[![Codecov](https://codecov.io/github/jmpa-io/pocketsmith-go/graph/badge.svg?token=8LXBLNQSOW)](https://codecov.io/github/jmpa-io/pocketsmith-go)

## `API Coverage`

The following API endpoints are currently covered by this package:

// TODO

## `Usage`

// TODO

## `License`

This work is published under the MIT license.

Please see the [`LICENSE`](./LICENSE) file for details.
21 changes: 21 additions & 0 deletions account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package pocketsmith

import "time"

// Account defines a PocketSmith account.
// https://developers.pocketsmith.com/reference#get_accounts-id
type Account struct {
ID int `json:"id"`
Title string `json:"title"`
Type string `json:"type"`
IsNetWorth bool `json:"is_net_worth"`
CurrencyCode string `json:"currency_code"`
CurrentBalance float64 `json:"current_balance"`
CurrentBalanceInBaseCurrency float64 `json:"current_balance_in_base_currency"`
CurrentBalanceExchangeRate float64 `json:"current_balance_exchange_rate"`
CurrentBalanceDate string `json:"current_balance_date"`
PrimaryTransactionAccount TransactionAccount `json:"primary_transaction_account"`
TransactionAccounts []TransactionAccount `json:"transaction_accounts"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
24 changes: 4 additions & 20 deletions accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,8 @@ import (
"fmt"
"net/http"
"strings"
"time"
)

// Account defines a PocketSmith account.
// https://developers.pocketsmith.com/reference#get_accounts-id
type Account struct {
ID int `json:"id"`
Title string `json:"title"`
Type string `json:"type"`
IsNetWorth bool `json:"is_net_worth"`
CurrencyCode string `json:"currency_code"`
CurrentBalance float64 `json:"current_balance"`
CurrentBalanceInBaseCurrency float64 `json:"current_balance_in_base_currency"`
CurrentBalanceExchangeRate float64 `json:"current_balance_exchange_rate"`
CurrentBalanceDate string `json:"current_balance_date"`
PrimaryTransactionAccount TransactionAccount `json:"primary_transaction_account"`
TransactionAccounts []TransactionAccount `json:"transaction_accounts"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}

// CreateAccountOptions defines the options for creating an account for a user.
type CreateAccountOptions struct {
InstitutionID int `json:"institution_id"`
Expand Down Expand Up @@ -97,7 +78,10 @@ type ListAccountTransactionsOptions struct {
// ListTransactionAccountTransactions, using the given account id, lists the
// transactions for an account.
// https://developers.pocketsmith.com/reference/get_accounts-id-transactions-1
func (c *Client) ListAccountTransactions(accountId int, options *ListAccountTransactionsOptions) ([]Transaction, error) {
func (c *Client) ListAccountTransactions(
accountId int,
options *ListAccountTransactionsOptions,
) ([]Transaction, error) {
var transactions []Transaction
cr := clientRequest{
method: http.MethodGet,
Expand Down
25 changes: 25 additions & 0 deletions attachment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package pocketsmith

import "time"

// Attachment defines a PocketSmith attachment.
// https://developers.pocketsmith.com/reference#get_attachments-id
type Attachment struct {
ID int `json:"id"`
Title string `json:"title"`
FileName string `json:"file_name"`
Type string `json:"type"`
ContentType string `json:"content_type"`
ContentTypeMeta struct {
Title string `json:"title"`
Description string `json:"description"`
Extension string `json:"extension"`
} `json:"content_type_meta"`
OriginalURL string `json:"original_url"`
Variants struct {
ThumbURL string `json:"thumb_url"`
LargeURL string `json:"large_url"`
} `json:"variants"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
45 changes: 17 additions & 28 deletions attachments.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,8 @@ package pocketsmith
import (
"fmt"
"net/http"
"time"
)

// Attachment defines a PocketSmith attachment.
// https://developers.pocketsmith.com/reference#get_attachments-id
type Attachment struct {
ID int `json:"id"`
Title string `json:"title"`
FileName string `json:"file_name"`
Type string `json:"type"`
ContentType string `json:"content_type"`
ContentTypeMeta struct {
Title string `json:"title"`
Description string `json:"description"`
Extension string `json:"extension"`
} `json:"content_type_meta"`
OriginalURL string `json:"original_url"`
Variants struct {
ThumbURL string `json:"thumb_url"`
LargeURL string `json:"large_url"`
} `json:"variants"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}

// CreateAttachmentOptions defines the options for creating an attachment for a
// user.
type CreateAttachmentOptions struct {
Expand All @@ -38,7 +15,10 @@ type CreateAttachmentOptions struct {

// CreateAttachment, using the given user id, creates an attachment for a user.
// https://developers.pocketsmith.com/reference#post_users-id-attachments
func (c *Client) CreateAttachment(userId int, options *CreateAttachmentOptions) (attachment *Attachment, err error) {
func (c *Client) CreateAttachment(
userId int,
options *CreateAttachmentOptions,
) (attachment *Attachment, err error) {
cr := clientRequest{
method: http.MethodPost,
path: fmt.Sprintf("/users/%v/attachments", userId),
Expand All @@ -50,7 +30,9 @@ func (c *Client) CreateAttachment(userId int, options *CreateAttachmentOptions)

// CreateAttachmentForAuthedUser, using the token attached to the client,
// creates an attachment for the authed user.
func (c *Client) CreateAttachmentForAuthedUser(options *CreateAttachmentOptions) (*Attachment, error) {
func (c *Client) CreateAttachmentForAuthedUser(
options *CreateAttachmentOptions,
) (*Attachment, error) {
return c.CreateAttachment(c.user.ID, options)
}

Expand All @@ -72,7 +54,10 @@ type ListAttachmentsOptions struct {

// ListAttachments, using the given user id, lists the attachments for a user.
// https://developers.pocketsmith.com/reference#get_users-id-attachments
func (c *Client) ListAttachments(userId int, options *ListAttachmentsOptions) ([]Attachment, error) {
func (c *Client) ListAttachments(
userId int,
options *ListAttachmentsOptions,
) ([]Attachment, error) {
cr := clientRequest{
method: http.MethodGet,
path: fmt.Sprintf("/users/%v/attachments", userId),
Expand All @@ -85,7 +70,9 @@ func (c *Client) ListAttachments(userId int, options *ListAttachmentsOptions) ([

// ListAttachmentsForAuthedUser, using the token attached to the client, lists
// the attachment for the authed user.
func (c *Client) ListAttachmentsForAuthedUser(options *ListAttachmentsOptions) ([]Attachment, error) {
func (c *Client) ListAttachmentsForAuthedUser(
options *ListAttachmentsOptions,
) ([]Attachment, error) {
return c.ListAttachments(c.user.ID, options)
}

Expand All @@ -98,7 +85,9 @@ type AssignAttachmentToTransactionOptions struct {

// AssignAttachmentToTransaction assigns an attachment to a transaction.
// https://developers.pocketsmith.com/reference#post_transactions-id-attachments
func (c *Client) AssignAttachmentToTransaction(options *AssignAttachmentToTransactionOptions) (*Attachment, error) {
func (c *Client) AssignAttachmentToTransaction(
options *AssignAttachmentToTransactionOptions,
) (*Attachment, error) {
cr := clientRequest{
method: http.MethodPost,
path: fmt.Sprintf("/transactions/%v/attachments", options.TransactionID),
Expand Down
Loading

0 comments on commit a4ed423

Please sign in to comment.