Skip to content

Commit

Permalink
Rename package
Browse files Browse the repository at this point in the history
  • Loading branch information
Oli Girling committed Oct 4, 2023
1 parent 210e192 commit 37f4a2f
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 10 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Running Code Coverage

on: [push]
jobs:

test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go:
- '1.21'
- '1.20'
- '1.19'
- '1.18'
- '1.17'

steps:
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- uses: actions/checkout@v3
- run: go test -v -coverprofile=profile.cov

- name: Send coverage
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: profile.cov
flag-name: Go-${{ matrix.go }}
parallel: true

# notifies that all test jobs are finished.
finish:
needs: test
runs-on: ubuntu-latest
steps:
- uses: shogo82148/actions-goveralls@v1
with:
parallel-finished: true
135 changes: 135 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# CurrencyApi Golang wrapper

[![PyPI version](https://badge.fury.io/go/currencyapi.svg)](https://pkg.go.dev/github.com/houseofapis/currencyapi) [![Coverage Status](https://coveralls.io/repos/github/houseofapis/currencyapi-go/badge.svg?branch=main)](https://coveralls.io/github/houseofapis/currencyapi-go?branch=main)

<a href="https://currencyapi.net" title="CurrencyApi">CurrencyApi.net</a> provides live currency rates via a REST API. A live currency feed for over 152 currencies, including physical (USD, GBP, EUR + more) and cryptos (Bitcoin, Litecoin, Ethereum + more). A JSON and XML currency api updated every 60 seconds.

Expand All @@ -24,3 +25,137 @@ Golang wrapper for <a href="https://currencyapi.net" title="CurrencyApi">Currenc
- Working on Go 1.21
- Free or Paid account with CurrencyApi.net

#### Test Coverage

- 100% coverage

## Installation

```bash
go get github.com/houseofapis/currencyapi
```
then import the package with:

```golang
import (
...
"github.com/houseofapis/currencyapi"
...
)
```

## Usage

### Instantiating

```golang
client := currencyapi.Client("API_KEY")
```

### Live rates:

```golang
params := map[string]string{
"output": "JSON",
"base": "USD",
}

body, err := client.Rates(params)
```

**Available params for rates endpoint**

| Methods | Description |
| --- | --- |
| `base` | The base currency you wish you receive the currency conversions for. This will output all currency conversions for that currency. **Default: USD**. |
| `output` | Response output in either JSON or XML. **Default: JSON**. |

<br>

### List of available currencies:

```golang
params := map[string]string{
"output": "XML"
}

body, err := client.Currencies(params)
```

**Available methods for currencies endpoint**

| Methods | Description |
| --- | --- |
| `output` | Response output in either JSON or XML. **Default: JSON**. |

<br>

### Convert:

```golang
params := map[string]string{
"output": "JSON",
"from": "USD",
"to": "GBP",
"amount": 15.99,
}

body, err := client.Convert(params)
```

**Available methods for convert endpoint**

| Methods | Description |
| --- | --- |
| `amount` | The value of the currency you want to convert from. This should be a number and can contain a decimal place. **Required**. |
| `from` | The currency you want to convert. This will be a three letter ISO 4217 currency code from one of the currencies we have rates for. **Required**. |
| `to` | The currency you want to convert the amount 'to'. Again this will be a three letter currency code from the ones we offer. **Required**. |
| `output` | Response output in either JSON or XML. **Default: JSON**. |

<br>

### Historical:

```golang
params := map[string]string{
"output": "JSON",
"base": "GBP",
"date": "2019-01-01"
}

body, err := client.History(params)
```

**Available methods for historical endpoint**

| Methods | Description |
| --- | --- |
| `date` | The historical date you wish to receive the currency conversions for. This should be formatted as YYYY-MM-DD. **Required**. |
| `base` | The base currency you wish you receive the currency conversions for. This will output all currency conversions for that currency. **Default: USD**. |
| `output` | Response output in either JSON or XML. **Default: JSON**. |

<br>

### Timeframe:

```golang
params := map[string]string{
"output": "JSON",
"base": "GBP",
"start_date": "2019-01-01"
"end_date": "2019-01-05"
}

body, err := client.Timeframe(params)
```

**Available methods for timeframe endpoint**

| Methods | Description |
| --- | --- |
| `start_date` | The historical date you wish to receive the currency conversions from. This should be formatted as YYYY-MM-DD. **Required**. |
| `end_date` | The historical date you wish to receive the currency conversions until. This should be formatted as YYYY-MM-DD. **Required**. |
| `base` | The base currency you wish you receive the currency conversions for. This will output all currency conversions for that currency. **Default: USD**. |
| `output` | Response output in either JSON or XML. **Default: JSON**. |


2 changes: 1 addition & 1 deletion currencyapinet.go → currencyapi.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package currencyapinet
package currencyapi

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion currencyapinet_test.go → currencyapi_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package currencyapinet
package currencyapi

import (
"encoding/json"
Expand Down
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
module currencyapinet
module github.com/houseofapis/currencyapi

go 1.21.1

require (
github.com/stretchr/testify v1.8.4
gopkg.in/h2non/gock.v1 v1.1.2
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/h2non/gock v1.2.0 // indirect
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
gopkg.in/h2non/gock.v1 v1.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/h2non/gock v1.2.0 h1:K6ol8rfrRkUOefooBC8elXoaNGYkpp7y2qcxGG6BzUE=
github.com/h2non/gock v1.2.0/go.mod h1:tNhoxHYW2W42cYkYb1WqzdbYIieALC99kpYr7rH/BQk=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4=
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/h2non/gock.v1 v1.1.2 h1:jBbHXgGBK/AoPVfJh5x4r/WxIrElvbLel8TCZkkZJoY=
gopkg.in/h2non/gock.v1 v1.1.2/go.mod h1:n7UGz/ckNChHiK05rDoiC4MYSunEC/lyaUm2WWaDva0=
Expand Down
4 changes: 2 additions & 2 deletions myapp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package main
import (
"fmt"
"log"
"currencyapinet"
"github.com/houseofapis/currencyapi"
)

func main() {
client := currencyapinet.Client("PY9VM5DrVNptjWjQ2dXGp3sgQI61W7jmTiex")
client := currencyapi.Client("PY9VM5DrVNptjWjQ2dXGp3sgQI61W7jmTiex")

ratesParams := map[string]string{
"output": "XML",
Expand Down

0 comments on commit 37f4a2f

Please sign in to comment.