gofixerio

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2019 License: MIT Imports: 7 Imported by: 3

README

gofixerio — Simple wrapper for https://fixer.io API

Installation

go get https://github.com/LordotU/go-fixerio

Testing

FIXERIO_API_KEY="your API key here" go test

Note: all tests are written for free subscription plan!

Usage

The simplest example is:

	import (
		"log"

		"https://github.com/LordotU/go-fixerio"
	)

	func main() {
		fixerio := gofixerio.New("your API key here", "EUR", false)

		latestRates, err := fixerio.GetLatest()
		if err != nil {
			log.Panic(err)
		}

		log.Printf("%+v", latestRates)
	}

Documentation

Overview

Package gofixerio providers simple wrapper for "Foreign exchange rates and currency conversion JSON API" (https://fixer.io).

Using this package is easy as 1-2-3:

fixerio := gofixerio.New("your API key here", "EUR", "false")
latestRates, err := fixerio.GetLatest()
if err != nil {
        log.Panic(err)
}
log.Printf("%+v", latestRates)

Index

Examples

Constants

View Source
const BaseURL = "data.fixer.io"

BaseURL is the main URL for accessing https://fixer.io API

Variables

This section is empty.

Functions

This section is empty.

Types

type FixerIO

type FixerIO struct {
	APIKey string
	Base   string // optional
	Secure bool   // optional
}

FixerIO represents a client instance

func New

func New(APIKey string, Base string, Secure bool) (*FixerIO, error)

New eturns pointer to a new instance of FixerIO

Example
package main

import (
	"log"

	gofixerio "github.com/LordotU/go-fixerio"
)

func main() {
	fixerio, _ := gofixerio.New("your API key here", "EUR", false)

	latestRates, err := fixerio.GetLatest([]string{})
	if err != nil {
		log.Panic(err)
	}

	log.Printf("%+v", latestRates)
}
Output:

func (*FixerIO) GetConversion

func (f *FixerIO) GetConversion(from string, to string, amount float64, date string) (*ResponseConversion, error)

GetConversion returns pointer to ResponseConversion struct which contains conversion data for given from, to, amount and date args

func (*FixerIO) GetFluctuation

func (f *FixerIO) GetFluctuation(startDate string, endDate string) (*ResponseFluctuation, error)

GetFluctuation returns pointer to ResponseTimeseries struct which contains fluctuation rates map (map[string][string]float64) for given startDate and endDate arg

func (*FixerIO) GetHistorical

func (f *FixerIO) GetHistorical(date string, symbols []string) (*ResponseHistorical, error)

GetHistorical returns pointer to ResponseHistorical struct which contains historical rates map (map[string]float64) for given date and symbols args

func (*FixerIO) GetLatest

func (f *FixerIO) GetLatest(symbols []string) (*ResponseLatest, error)

GetLatest returns pointer to ResponseLatest struct which contains latest rates map (map[string]float64) for given symbols arg

func (*FixerIO) GetSymbols

func (f *FixerIO) GetSymbols() (*ResponseSymbols, error)

GetSymbols returns pointer to ResponseSymbols struct which contains symbols map (map[string]string)

func (*FixerIO) GetTimeseries

func (f *FixerIO) GetTimeseries(startDate string, endDate string) (*ResponseTimeseries, error)

GetTimeseries returns pointer to ResponseTimeseries struct which contains timeseries rates map (map[string][string]float64) for given startDate and endDate arg

func (*FixerIO) SetBase

func (f *FixerIO) SetBase(base string) *FixerIO

SetBase sets new base currency for all subsequent requests

type ResponseConversion

type ResponseConversion struct {
	ResponseSuccess
	Query      conversionQuery `json:"query"`
	Info       conversionInfo  `json:"info"`
	Historical bool            `json:"historical"`
	Date       string          `json:"date"`
	Result     float64         `json:"result"`
}

ResponseConversion represents GetConversion response

type ResponseError

type ResponseError struct {
	ResponseSuccess
	Error ResponseErrorDetail `json:"error"`
}

ResponseError represents errored response

type ResponseErrorDetail

type ResponseErrorDetail struct {
	Code int    `json:"code"`
	Type string `json:"type"`
	Info string `json:"info"`
}

ResponseErrorDetail represents details of errored response

type ResponseFluctuation

type ResponseFluctuation struct {
	ResponseSuccess
	Fluctuation bool        `json:"fluctuation"`
	StartDate   string      `json:"start_date"`
	EndDate     string      `json:"end_date"`
	Base        string      `json:"base"`
	Rates       ratesNested `json:"rates"`
}

ResponseFluctuation represents GetFluctuation response

type ResponseHistorical

type ResponseHistorical struct {
	ResponseSuccess
	ResponseLatest
	Historical bool `json:"historical"`
}

ResponseHistorical represents GetHistorical response

type ResponseLatest

type ResponseLatest struct {
	ResponseSuccess
	Timestamp int    `json:"timestamp"`
	Base      string `json:"base"`
	Date      string `json:"date"`
	Rates     rates  `json:"rates"`
}

ResponseLatest represents GetLatest response

type ResponseSuccess

type ResponseSuccess struct {
	Success bool `json:"success"`
}

ResponseSuccess represents the success of the request

type ResponseSymbols

type ResponseSymbols struct {
	ResponseSuccess
	Symbols symbols `json:"symbols"`
}

ResponseSymbols represents GetSymbols response

type ResponseTimeseries

type ResponseTimeseries struct {
	ResponseSuccess
	Timeseries bool        `json:"timeseries"`
	StartDate  string      `json:"start_date"`
	EndDate    string      `json:"end_date"`
	Base       string      `json:"base"`
	Rates      ratesNested `json:"rates"`
}

ResponseTimeseries represents GetTimeseries response

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL