Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mehtaarn000/vcurrency

API wrapper (written in V) for https://api.exchangeratesapi.io/
https://github.com/mehtaarn000/vcurrency

Last synced: 3 months ago
JSON representation

API wrapper (written in V) for https://api.exchangeratesapi.io/

Awesome Lists containing this project

README

        

# vcurrency

API wrapper (written in V) for https://api.exchangeratesapi.io/

## Installation
Use:

`v install mehtaarn000.vcurrency`

## Functions

The `get_data` function takes two arguments: `options (type map)` and `symbols (type array of strings)`.

`get_data` takes arguments: `start_date`, `end_date` (which can both be an empty string to get latest data), and `base` (default "EUR").

The `symbols` array should have all the symbols that you would like to get from the API. For example, "USD", "INR", "NZD" (default is all symbols).

## Example usage

Get raw JSON from the API (not reccommended):

```v
module main

import mehtaarn000.vcurrency

fn main() {
data := vcurrency.get_data(map{"start_date" : "2021-02-25", "end_date" : "2021-02-26", "base" : "INR"}, ["USD", "CNY"])

// To get the response
println(data.json)

// To parse the json data
println(data.json["rates"])

// To get the generated url
println(data.url)

}
```

Use the `convert` function:
`convert` takes three arguments. `base` (type string), `amount` (type f64), and `symbols` (type []string). It returns a `map[string]f64`.
```v
module main

import mehtaarn000.vcurrency

fn main() {
data := vcurrency.convert("USD", 100, ["EUR", "INR"])
println(data)
}
```

Or, Use the `convert_on_date` function to convert a value based on the given date:
`convert_on_date` takes four arguments `base` (type string), `date` (type string in YYYY-MM-DD), `amount` (type f64), and `symbols` (type []string). It returns a `map[string]f64`.
```v
module main

import mehtaarn000.vcurrency

fn main() {
data := vcurrency.convert_on_date("USD", "2020-01-05", 100, ["EUR", "INR", "CZK"])
println(data)
}
```