Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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/
- Host: GitHub
- URL: https://github.com/mehtaarn000/vcurrency
- Owner: mehtaarn000
- License: mit
- Created: 2021-03-01T21:15:30.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-07-05T18:49:35.000Z (over 3 years ago)
- Last Synced: 2024-04-23T16:38:44.423Z (7 months ago)
- Language: V
- Size: 15.6 KB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-v - vcurrency - API wrapper (written in V) for [https://api.exchangeratesapi.io](https://api.exchangeratesapi.io). (Libraries / Web)
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 mainimport 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 mainimport 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 mainimport mehtaarn000.vcurrency
fn main() {
data := vcurrency.convert_on_date("USD", "2020-01-05", 100, ["EUR", "INR", "CZK"])
println(data)
}
```