wbdata

package module
v1.3.19 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2021 License: MIT Imports: 16 Imported by: 1

README

World Bank Open Data API in Go

GoDoc Build Status codecov Go Report Card

Installing

go get -u github.com/jkkitakita/wbdata-go

Example

package main

import (
	"fmt"

	"github.com/jkkitakita/wbdata-go"
)

func main () {
	client := wbdata.NewClient(nil)
	summary, countries, _ := client.Countries.List(
		&wbdata.ListCountryParams{
			RegionID: "EAS",
		},
		&wbdata.PageParams{
			Page:    1,
			PerPage: 1,
		},
	)

	fmt.Printf("Summary is: %#v\n", summary)
	fmt.Printf("Countries[0] is: %#v\n", countries[0])
	// Output:
	// Summary is: &wbdata.PageSummary{Page:1, Pages:38, PerPage:1, Total:38}
	// Countries[0] is: &wbdata.Country{ID:"ASM", Name:"American Samoa", CapitalCity:"Pago Pago", Iso2Code:"AS", Longitude:"-170.691", Latitude:"-14.2846", Region:wbdata.CountryRegion{ID:"EAS", Iso2Code:"Z4", Value:"East Asia & Pacific"}, IncomeLevel:wbdata.IncomeLevel{ID:"UMC", Iso2Code:"XT", Value:"Upper middle income"}, LendingType:wbdata.LendingType{ID:"LNX", Iso2Code:"XX", Value:"Not classified"}, AdminRegion:wbdata.CountryRegion{ID:"EAP", Iso2Code:"4E", Value:"East Asia & Pacific (excluding high income)"}}
}

ref. example_test.go

Documentation

Index

Examples

Constants

View Source
const (
	// FilterParamsUnknown is type of filter params for unknown
	FilterParamsUnknown FilterParamsType = iota
	// FilterParamsDate is type of filter params for date
	FilterParamsDate
	// FilterParamsDateRange is type of filter params for date range
	FilterParamsDateRange
	// FilterParamsYearToDate is type of filter params for year-to-date
	FilterParamsYearToDate
	// FilterParamsMRV is type of filter params for most recent values
	FilterParamsMRV

	// FrequencyUnknown is frequency type of unknown
	FrequencyUnknown FrequencyType = iota
	// FrequencyMonthly is frequency type of monthly (M)
	FrequencyMonthly
	// FrequencyQuarterly is frequency type of quarterly (Q)
	FrequencyQuarterly
	// FrequencyYearly is frequency type of yearly (Y)
	FrequencyYearly
)
View Source
const (
	// OutputFormatJSON is output format for json
	OutputFormatJSON OutputFormat = "json"
	// OutputFormatJSONP is output format for jsonP
	OutputFormatJSONP = "jsonP"
	// OutputFormatJSONStat is output format for json-stat
	OutputFormatJSONStat = "jsonstat"
	// OutputFormatXML is output format for xml
	OutputFormatXML = "xml"
)
View Source
const (
	// ErrInvalidServer is an error message for "Internal Server Error"
	ErrInvalidServer = "Internal Server Error"
)

Variables

This section is empty.

Functions

func SetLanguage added in v1.0.3

func SetLanguage(lang *Language) func(*Client)

SetLanguage sets local language to request URL

Types

type APIError

type APIError struct {
	URL     string
	Code    int
	Message string
}

APIError is a struct for API's error

func NewAPIError

func NewAPIError(url string, code int, msg string) *APIError

NewAPIError returns an APIError struct

func (*APIError) Error

func (ae *APIError) Error() string

type Client

type Client struct {

	// BaseURL is URL for API requests. Defaults to the World Bank Open Data API
	BaseURL *url.URL

	// Language is Local Language for response
	Language string

	// OutputFormat is output format
	OutputFormat OutputFormat

	// Logger
	Logger *log.Logger

	// UserAgent is user agent used when communicating with the World Bank Open Data API
	UserAgent string

	// Services to talk to different APIs
	Countries       *CountriesService
	Indicators      *IndicatorsService
	IndicatorValues *IndicatorValuesService
	IncomeLevels    *IncomeLevelsService
	LendingTypes    *LendingTypesService
	Regions         *RegionsService
	Sources         *SourcesService
	Topics          *TopicsService
	Languages       *LanguagesService
	// contains filtered or unexported fields
}

A Client manages communication with the World Bank Open Data API

func NewClient

func NewClient(httpClient *http.Client, options ...func(*Client)) *Client

NewClient returns a new World Bank Open Data API client.

func NewTestClient

func NewTestClient(t testing.TB, update bool) (*Client, func())

NewTestClient returns a new World Bank Open Data API client for Test using go-vcr.

func (*Client) NewRequest

func (c *Client) NewRequest(
	method,
	urlStr string,
	queryParams map[string]string,
	body interface{},
) (*http.Request, error)

NewRequest returns a new World Bank Open Data API http request.

type CountriesService

type CountriesService service

CountriesService ...

func (*CountriesService) Get

func (c *CountriesService) Get(countryID string) (*PageSummary, *Country, error)

Get returns summary and a country

Example
client := wbdata.NewClient(nil)
summary, country, _ := client.Countries.Get("jpn")

fmt.Printf("Summary is: %#v\n", summary)
fmt.Printf("Country is: %#v\n", country)
Output:

Summary is: &wbdata.PageSummary{Page:1, Pages:1, PerPage:50, Total:1}
Country is: &wbdata.Country{ID:"JPN", Name:"Japan", CapitalCity:"Tokyo", Iso2Code:"JP", Longitude:"139.77", Latitude:"35.67", Region:wbdata.CountryRegion{ID:"EAS", Iso2Code:"Z4", Value:"East Asia & Pacific"}, IncomeLevel:wbdata.IncomeLevel{ID:"HIC", Iso2Code:"XD", Value:"High income"}, LendingType:wbdata.LendingType{ID:"LNX", Iso2Code:"XX", Value:"Not classified"}, AdminRegion:wbdata.CountryRegion{ID:"", Iso2Code:"", Value:""}}

func (*CountriesService) List

func (c *CountriesService) List(
	params *ListCountryParams,
	pages *PageParams,
) (*PageSummary, []*Country, error)

List returns summary and countries with params

Example
client := wbdata.NewClient(nil)
summary, countries, _ := client.Countries.List(
	&wbdata.ListCountryParams{
		RegionID: "EAS",
	},
	&wbdata.PageParams{
		Page:    1,
		PerPage: 10,
	})

summary.Pages = 30
summary.Total = 300

fmt.Printf("Summary is: %#v\n", summary)
fmt.Printf("Countries[0] is: %#v\n", countries[0])
Output:

Summary is: &wbdata.PageSummary{Page:1, Pages:30, PerPage:10, Total:300}
Countries[0] is: &wbdata.Country{ID:"ASM", Name:"American Samoa", CapitalCity:"Pago Pago", Iso2Code:"AS", Longitude:"-170.691", Latitude:"-14.2846", Region:wbdata.CountryRegion{ID:"EAS", Iso2Code:"Z4", Value:"East Asia & Pacific"}, IncomeLevel:wbdata.IncomeLevel{ID:"UMC", Iso2Code:"XT", Value:"Upper middle income"}, LendingType:wbdata.LendingType{ID:"LNX", Iso2Code:"XX", Value:"Not classified"}, AdminRegion:wbdata.CountryRegion{ID:"EAP", Iso2Code:"4E", Value:"East Asia & Pacific (excluding high income)"}}

type Country

type Country struct {
	ID          string
	Name        string
	CapitalCity string
	Iso2Code    string
	Longitude   string
	Latitude    string
	Region      CountryRegion
	IncomeLevel IncomeLevel
	LendingType LendingType
	AdminRegion CountryRegion
}

Country contains information for an country field

type CountryRegion

type CountryRegion struct {
	ID       string
	Iso2Code string
	Value    string
}

CountryRegion is a struct for region when using the Countries API

type DateParam added in v1.3.0

type DateParam struct {
	Date      string
	DateRange *DateRange
}

DateParam is struct for date params

type DateRange added in v1.2.0

type DateRange struct {
	Start string
	End   string
}

DateRange is a struct for API's query params about date

type ErrorMessage

type ErrorMessage struct {
	ID    string `json:"id"`
	Key   string `json:"key"`
	Value string `json:"value"`
}

ErrorMessage is a struct for error message

type ErrorResponse

type ErrorResponse struct {
	URL     string
	Code    int
	Message []ErrorMessage `json:"message"`
}

ErrorResponse is a struct for error response

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

type FilterParams added in v1.3.0

type FilterParams struct {
	FilterParamsType FilterParamsType
	DateParam        *DateParam
	RecentParam      *RecentParam
}

FilterParams is struct for filter params

type FilterParamsType added in v1.3.0

type FilterParamsType uint

FilterParamsType is type of filter params

type FrequencyType added in v1.3.0

type FrequencyType uint

FrequencyType is type of frequency

type IDAndValue added in v1.0.1

type IDAndValue struct {
	ID    string
	Value string
}

IDAndValue represents ID and Value

type IncomeLevel

type IncomeLevel struct {
	ID       string
	Iso2Code string
	Value    string
}

IncomeLevel contains information for an incomelevel field

type IncomeLevelsService

type IncomeLevelsService service

IncomeLevelsService ...

func (*IncomeLevelsService) Get

func (il *IncomeLevelsService) Get(incomeLevelID string) (*PageSummary, *IncomeLevel, error)

Get returns a Response's Summary and an IncomeLevel

Example
client := wbdata.NewClient(nil)
summary, incomeLevel, _ := client.IncomeLevels.Get("hic")

fmt.Printf("Summary is: %#v\n", summary)
fmt.Printf("IncomeLevel is: %#v\n", incomeLevel)
Output:

Summary is: &wbdata.PageSummary{Page:1, Pages:1, PerPage:50, Total:1}
IncomeLevel is: &wbdata.IncomeLevel{ID:"HIC", Iso2Code:"XD", Value:"High income"}

func (*IncomeLevelsService) List

func (il *IncomeLevelsService) List(pages *PageParams) (*PageSummary, []*IncomeLevel, error)

List returns a Response's Summary and IncomeLevels

Example
client := wbdata.NewClient(nil)
summary, incomeLevels, _ := client.IncomeLevels.List(
	&wbdata.PageParams{
		Page:    1,
		PerPage: 10,
	},
)

summary.Pages = 1
summary.Total = 7

fmt.Printf("Summary is: %#v\n", summary)
fmt.Printf("IncomeLevels[0] is: %#v\n", incomeLevels[0])
Output:

Summary is: &wbdata.PageSummary{Page:1, Pages:1, PerPage:10, Total:7}
IncomeLevels[0] is: &wbdata.IncomeLevel{ID:"HIC", Iso2Code:"XD", Value:"High income"}

type Indicator

type Indicator struct {
	ID                 string
	Name               string
	Unit               string
	Source             *IDAndValue
	SourceNote         string
	SourceOrganization string
	Topics             []*IDAndValue
}

Indicator contains information for an indicator field

type IndicatorValue added in v1.1.0

type IndicatorValue struct {
	Indicator       IDAndValue `json:"indicator"`
	Country         IDAndValue `json:"country"`
	Countryiso3code string     `json:"countryiso3code"`
	Date            string     `json:"date"`
	Value           float64    `json:"value"`
	Unit            string     `json:"unit"`
	ObsStatus       string     `json:"obs_status"`
	Decimal         int32      `json:"decimal"`
}

IndicatorValue represents an indicator value

type IndicatorValueWithFootnote added in v1.3.0

type IndicatorValueWithFootnote struct {
	IndicatorValue
	Footnote string `json:"footnote"`
}

IndicatorValueWithFootnote represents an indicator value with footnote

type IndicatorValuesService added in v1.1.0

type IndicatorValuesService service

IndicatorValuesService ...

func (*IndicatorValuesService) List added in v1.2.0

func (i *IndicatorValuesService) List(
	indicatorID string,
	filterParams *FilterParams,
	pages *PageParams,
) (*PageSummaryWithSourceID, []*IndicatorValue, error)

List returns a Response's Summary and Indicator in all countries

Example
client := wbdata.NewClient(nil)
indicatorID := "NY.GDP.MKTP.CD"
summary, indicatorValues, _ := client.IndicatorValues.List(
	indicatorID,
	&wbdata.FilterParams{
		FilterParamsType: wbdata.FilterParamsDateRange,
		DateParam: &wbdata.DateParam{
			DateRange: &wbdata.DateRange{
				Start: "2018",
				End:   "2019",
			},
		},
	},
	&wbdata.PageParams{
		Page:    1,
		PerPage: 10,
	},
)

summary.Pages = 53
summary.Total = 528
summary.LastUpdated = "2020-12-16"

fmt.Printf("Summary is: %#v\n", summary)
fmt.Printf("IndicatorValues[0]: %#v\n", indicatorValues[0])
Output:

Summary is: &wbdata.PageSummaryWithSourceID{Page:1, Pages:53, PerPage:10, Total:528, SourceID:"2", LastUpdated:"2020-12-16"}
IndicatorValues[0]: &wbdata.IndicatorValue{Indicator:wbdata.IDAndValue{ID:"NY.GDP.MKTP.CD", Value:"GDP (current US$)"}, Country:wbdata.IDAndValue{ID:"1A", Value:"Arab World"}, Countryiso3code:"ARB", Date:"2019", Value:2.81741458466511e+12, Unit:"", ObsStatus:"", Decimal:0}
Example (Second)
client := wbdata.NewClient(nil)
indicatorID := "NY.GDP.MKTP.CD"
summary, indicatorValues, _ := client.IndicatorValues.List(
	indicatorID,
	&wbdata.FilterParams{
		FilterParamsType: wbdata.FilterParamsMRV,
		RecentParam: &wbdata.RecentParam{
			FrequencyType:    wbdata.FrequencyYearly,
			MostRecentValues: 1,
			IsNotEmpty:       false,
			IsGapFill:        false,
		},
	},
	&wbdata.PageParams{
		Page:    1,
		PerPage: 10,
	},
)

summary.Pages = 53
summary.Total = 528
summary.LastUpdated = "2020-12-16"

fmt.Printf("Summary is: %#v\n", summary)
fmt.Printf("IndicatorValues[0]: %#v\n", indicatorValues[0])
Output:

Summary is: &wbdata.PageSummaryWithSourceID{Page:1, Pages:53, PerPage:10, Total:528, SourceID:"2", LastUpdated:"2020-12-16"}
IndicatorValues[0]: &wbdata.IndicatorValue{Indicator:wbdata.IDAndValue{ID:"NY.GDP.MKTP.CD", Value:"GDP (current US$)"}, Country:wbdata.IDAndValue{ID:"1A", Value:"Arab World"}, Countryiso3code:"ARB", Date:"2019", Value:2.81741458466511e+12, Unit:"", ObsStatus:"", Decimal:0}

func (*IndicatorValuesService) ListByCountryIDs added in v1.1.0

func (i *IndicatorValuesService) ListByCountryIDs(
	countryIDs []string,
	indicatorID string,
	filterParams *FilterParams,
	pages *PageParams,
) (*PageSummaryWithSourceID, []*IndicatorValue, error)

ListByCountryIDs returns a Response's Summary and Indicator By country IDs

Example
client := wbdata.NewClient(nil)
countryIDs := []string{"JPN", "USA"}
indicatorID := "NY.GDP.MKTP.CD"
summary, indicatorValues, _ := client.IndicatorValues.ListByCountryIDs(
	countryIDs,
	indicatorID,
	&wbdata.FilterParams{
		FilterParamsType: wbdata.FilterParamsDateRange,
		DateParam: &wbdata.DateParam{
			DateRange: &wbdata.DateRange{
				Start: "2018",
				End:   "2019",
			},
		},
	},
	&wbdata.PageParams{
		Page:    1,
		PerPage: 10,
	},
)

summary.LastUpdated = "2020-12-16"

fmt.Printf("Summary is: %#v\n", summary)
fmt.Printf("IndicatorValues[0]: %#v\n", indicatorValues[0])
Output:

Summary is: &wbdata.PageSummaryWithSourceID{Page:1, Pages:1, PerPage:10, Total:4, SourceID:"2", LastUpdated:"2020-12-16"}
IndicatorValues[0]: &wbdata.IndicatorValue{Indicator:wbdata.IDAndValue{ID:"NY.GDP.MKTP.CD", Value:"GDP (current US$)"}, Country:wbdata.IDAndValue{ID:"JP", Value:"Japan"}, Countryiso3code:"JPN", Date:"2019", Value:5.08176954237977e+12, Unit:"", ObsStatus:"", Decimal:0}

func (*IndicatorValuesService) ListByCountryIDsAndSourceID added in v1.2.0

func (i *IndicatorValuesService) ListByCountryIDsAndSourceID(
	countryIDs []string,
	indicatorIDs []string,
	sourceID string,
	filterParams *FilterParams,
	pages *PageParams,
) (*PageSummaryWithLastUpdated, []*IndicatorValue, error)

ListByCountryIDsAndSourceID returns a Response's Summary and Indicator By country IDs and source ID

Example
client := wbdata.NewClient(nil)
countryIDs := []string{"JPN", "USA"}
indicatorIDs := []string{"NY.GDP.MKTP.CD", "SP.POP.TOTL"}
sourceID := "2"
summary, indicatorValues, _ := client.IndicatorValues.ListByCountryIDsAndSourceID(
	countryIDs,
	indicatorIDs,
	sourceID,
	&wbdata.FilterParams{
		FilterParamsType: wbdata.FilterParamsDateRange,
		DateParam: &wbdata.DateParam{
			DateRange: &wbdata.DateRange{
				Start: "2018",
				End:   "2019",
			},
		},
	},
	&wbdata.PageParams{
		Page:    1,
		PerPage: 10,
	},
)

summary.Pages = 106
summary.Total = 1056
summary.LastUpdated = "2020-12-16"

fmt.Printf("Summary is: %#v\n", summary)
fmt.Printf("IndicatorValues[0]: %#v\n", indicatorValues[0])
Output:

Summary is: &wbdata.PageSummaryWithLastUpdated{Page:1, Pages:106, PerPage:10, Total:1056, LastUpdated:"2020-12-16"}
IndicatorValues[0]: &wbdata.IndicatorValue{Indicator:wbdata.IDAndValue{ID:"NY.GDP.MKTP.CD", Value:"GDP (current US$)"}, Country:wbdata.IDAndValue{ID:"JP", Value:"Japan"}, Countryiso3code:"JPN", Date:"2019", Value:5.08176954237977e+12, Unit:"", ObsStatus:"", Decimal:0}

func (*IndicatorValuesService) ListByCountryIDsAndSourceIDWithFootnote added in v1.3.0

func (i *IndicatorValuesService) ListByCountryIDsAndSourceIDWithFootnote(
	countryIDs []string,
	indicatorIDs []string,
	sourceID string,
	filterParams *FilterParams,
	pages *PageParams,
) (*PageSummaryWithLastUpdated, []*IndicatorValueWithFootnote, error)

ListByCountryIDsAndSourceIDWithFootnote returns a Response's Summary and Indicator with footnote By country IDs and source ID

func (*IndicatorValuesService) ListByCountryIDsWithFootnote added in v1.3.0

func (i *IndicatorValuesService) ListByCountryIDsWithFootnote(
	countryIDs []string,
	indicatorID string,
	filterParams *FilterParams,
	pages *PageParams,
) (*PageSummaryWithSourceID, []*IndicatorValueWithFootnote, error)

ListByCountryIDsWithFootnote returns a Response's Summary and Indicator with footnote By country IDs

func (*IndicatorValuesService) ListBySourceID added in v1.2.0

func (i *IndicatorValuesService) ListBySourceID(
	indicatorIDs []string,
	sourceID string,
	filterParams *FilterParams,
	pages *PageParams,
) (*PageSummaryWithLastUpdated, []*IndicatorValue, error)

ListBySourceID returns a Response's Summary and Indicator in all countries By source ID

Example
client := wbdata.NewClient(nil)
indicatorIDs := []string{"NY.GDP.MKTP.CD", "SP.POP.TOTL"}
sourceID := "2"
summary, indicatorValues, _ := client.IndicatorValues.ListBySourceID(
	indicatorIDs,
	sourceID,
	&wbdata.FilterParams{
		FilterParamsType: wbdata.FilterParamsDateRange,
		DateParam: &wbdata.DateParam{
			DateRange: &wbdata.DateRange{
				Start: "2018",
				End:   "2019",
			},
		},
	},
	&wbdata.PageParams{
		Page:    1,
		PerPage: 10,
	},
)

summary.Pages = 106
summary.Total = 1056
summary.LastUpdated = "2020-12-16"

fmt.Printf("Summary is: %#v\n", summary)
fmt.Printf("IndicatorValues[0]: %#v\n", indicatorValues[0])
Output:

Summary is: &wbdata.PageSummaryWithLastUpdated{Page:1, Pages:106, PerPage:10, Total:1056, LastUpdated:"2020-12-16"}
IndicatorValues[0]: &wbdata.IndicatorValue{Indicator:wbdata.IDAndValue{ID:"NY.GDP.MKTP.CD", Value:"GDP (current US$)"}, Country:wbdata.IDAndValue{ID:"1A", Value:"Arab World"}, Countryiso3code:"ARB", Date:"2019", Value:2.81741458466511e+12, Unit:"", ObsStatus:"", Decimal:0}

func (*IndicatorValuesService) ListBySourceIDWithFootnote added in v1.3.0

func (i *IndicatorValuesService) ListBySourceIDWithFootnote(
	indicatorIDs []string,
	sourceID string,
	filterParams *FilterParams,
	pages *PageParams,
) (*PageSummaryWithLastUpdated, []*IndicatorValueWithFootnote, error)

ListBySourceIDWithFootnote returns a Response's Summary and Indicator with footnote in all countries By source ID

func (*IndicatorValuesService) ListWithFootnote added in v1.3.0

func (i *IndicatorValuesService) ListWithFootnote(
	indicatorID string,
	filterParams *FilterParams,
	pages *PageParams,
) (*PageSummaryWithSourceID, []*IndicatorValueWithFootnote, error)

ListWithFootnote returns a Response's Summary and Indicator with footnote in all countries

type IndicatorsService

type IndicatorsService service

IndicatorsService ...

func (*IndicatorsService) Get

func (i *IndicatorsService) Get(indicatorID string) (*PageSummary, *Indicator, error)

Get returns a Response's Summary and an Indicator

Example
client := wbdata.NewClient(nil)
summary, indicator, _ := client.Indicators.Get("1.0.hcount.1.90usd")

indicator.Source = nil
indicator.Topics = nil

fmt.Printf("Summary is: %#v\n", summary)
fmt.Printf("Indicator without Source and Topics is: %#v\n", indicator)
Output:

Summary is: &wbdata.PageSummary{Page:1, Pages:1, PerPage:50, Total:1}
Indicator without Source and Topics is: &wbdata.Indicator{ID:"1.0.HCount.1.90usd", Name:"Poverty Headcount ($1.90 a day)", Unit:"", Source:(*wbdata.IDAndValue)(nil), SourceNote:"The poverty headcount index measures the proportion of the population with daily per capita income (in 2011 PPP) below the poverty line.", SourceOrganization:"LAC Equity Lab tabulations of SEDLAC (CEDLAS and the World Bank).", Topics:[]*wbdata.IDAndValue(nil)}

func (*IndicatorsService) List

func (i *IndicatorsService) List(pages *PageParams) (*PageSummary, []*Indicator, error)

List returns a Response's Summary and Indicators

Example
client := wbdata.NewClient(nil)
summary, indicators, _ := client.Indicators.List(
	&wbdata.PageParams{
		Page:    1,
		PerPage: 10,
	},
)

summary.Pages = 1735
summary.Total = 17349
indicators[0].Source = nil
indicators[0].Topics = nil

fmt.Printf("Summary is: %#v\n", summary)
fmt.Printf("Indicators[0] without Source and Topics is: %#v\n", indicators[0])
Output:

Summary is: &wbdata.PageSummary{Page:1, Pages:1735, PerPage:10, Total:17349}
Indicators[0] without Source and Topics is: &wbdata.Indicator{ID:"1.0.HCount.1.90usd", Name:"Poverty Headcount ($1.90 a day)", Unit:"", Source:(*wbdata.IDAndValue)(nil), SourceNote:"The poverty headcount index measures the proportion of the population with daily per capita income (in 2011 PPP) below the poverty line.", SourceOrganization:"LAC Equity Lab tabulations of SEDLAC (CEDLAS and the World Bank).", Topics:[]*wbdata.IDAndValue(nil)}

func (*IndicatorsService) ListByTopicID added in v1.0.5

func (i *IndicatorsService) ListByTopicID(topicID string, pages *PageParams) (*PageSummary, []*Indicator, error)

ListByTopicID returns a Response's Summary and Indicators By topic id

Example
client := wbdata.NewClient(nil)
topicID := "1"
summary, indicators, _ := client.Indicators.ListByTopicID(
	topicID,
	&wbdata.PageParams{
		Page:    1,
		PerPage: 10,
	},
)

summary.Pages = 1735
summary.Total = 17349
topics := indicators[0].Topics
indicators[0].Source = nil
indicators[0].Topics = nil

fmt.Printf("Summary is: %#v\n", summary)
fmt.Printf("Indicators[0] without Source and Topics is: %#v\n", indicators[0])
fmt.Printf("Topics is: %+v\n", topics[0])
Output:

Summary is: &wbdata.PageSummary{Page:1, Pages:1735, PerPage:10, Total:17349}
Indicators[0] without Source and Topics is: &wbdata.Indicator{ID:"AG.AGR.TRAC.NO", Name:"Agricultural machinery, tractors", Unit:"", Source:(*wbdata.IDAndValue)(nil), SourceNote:"Agricultural machinery refers to the number of wheel and crawler tractors (excluding garden tractors) in use in agriculture at the end of the calendar year specified or during the first quarter of the following year.", SourceOrganization:"Food and Agriculture Organization, electronic files and web site.", Topics:[]*wbdata.IDAndValue(nil)}
Topics is: &{ID:1 Value:Agriculture & Rural Development  }

type Language added in v1.0.3

type Language struct {
	Code       string
	Name       string
	NativeForm string
}

Language contains information for an language field

type LanguagesService added in v1.0.3

type LanguagesService service

LanguagesService ...

func (*LanguagesService) Get added in v1.0.3

func (c *LanguagesService) Get(languageCode string) (*PageSummary, *Language, error)

Get returns summary and a language

Example
client := wbdata.NewClient(nil)
summary, language, _ := client.Languages.Get("ja")

fmt.Printf("Summary is: %#v\n", summary)
fmt.Printf("Language is: %#v\n", language)
Output:

Summary is: &wbdata.PageSummary{Page:1, Pages:1, PerPage:50, Total:1}
Language is: &wbdata.Language{Code:"ja", Name:"Japanese ", NativeForm:"日本語"}

func (*LanguagesService) List added in v1.0.3

func (c *LanguagesService) List(pages *PageParams) (*PageSummary, []*Language, error)

List returns summary and languages

Example
client := wbdata.NewClient(nil)
summary, languages, _ := client.Languages.List(
	&wbdata.PageParams{
		Page:    1,
		PerPage: 10,
	},
)

summary.Pages = 3
summary.Total = 23

fmt.Printf("Summary is: %#v\n", summary)
fmt.Printf("Languages[0] is: %#v\n", languages[0])
Output:

Summary is: &wbdata.PageSummary{Page:1, Pages:3, PerPage:10, Total:23}
Languages[0] is: &wbdata.Language{Code:"en", Name:"English", NativeForm:"English"}

type LendingType

type LendingType struct {
	ID       string
	Iso2Code string
	Value    string
}

LendingType contains information for a lending type field

type LendingTypesService

type LendingTypesService service

LendingTypesService ...

func (*LendingTypesService) Get

func (lt *LendingTypesService) Get(lendingTypeID string) (*PageSummary, *LendingType, error)

Get returns a Response's Summary and a LendingType

Example
client := wbdata.NewClient(nil)
summary, lendingType, _ := client.LendingTypes.Get("ibd")

fmt.Printf("Summary is: %#v\n", summary)
fmt.Printf("LendingType is: %#v\n", lendingType)
Output:

Summary is: &wbdata.PageSummary{Page:1, Pages:1, PerPage:50, Total:1}
LendingType is: &wbdata.LendingType{ID:"IBD", Iso2Code:"XF", Value:"IBRD"}

func (*LendingTypesService) List

func (lt *LendingTypesService) List(pages *PageParams) (*PageSummary, []*LendingType, error)

List returns a Response's Summary and LendingTypes

Example
client := wbdata.NewClient(nil)
summary, lendingTypes, _ := client.LendingTypes.List(
	&wbdata.PageParams{
		Page:    1,
		PerPage: 10,
	},
)

summary.Pages = 1
summary.Total = 4

fmt.Printf("Summary is: %#v\n", summary)
fmt.Printf("LendingTypes[0] is: %#v\n", lendingTypes[0])
Output:

Summary is: &wbdata.PageSummary{Page:1, Pages:1, PerPage:10, Total:4}
LendingTypes[0] is: &wbdata.LendingType{ID:"IBD", Iso2Code:"XF", Value:"IBRD"}

type ListCountryParams added in v1.0.5

type ListCountryParams struct {
	RegionID      string
	IncomeLevelID string
	LendingTypeID string
}

ListCountryParams contains parameters for List

type OutputFormat added in v1.0.4

type OutputFormat string

OutputFormat is output format

func (OutputFormat) String added in v1.0.4

func (o OutputFormat) String() string

type PageParams

type PageParams struct {
	Page    int
	PerPage int
}

PageParams is a struct for API's query params about pages

type PageSummary

type PageSummary struct {
	Page    intOrString `json:"page"`
	Pages   intOrString `json:"pages"`
	PerPage intOrString `json:"per_page"`
	Total   intOrString `json:"total"`
}

PageSummary is a struct for a Summary about pages

type PageSummaryWithLastUpdated added in v1.2.0

type PageSummaryWithLastUpdated struct {
	Page        intOrString `json:"page"`
	Pages       intOrString `json:"pages"`
	PerPage     intOrString `json:"per_page"`
	Total       intOrString `json:"total"`
	LastUpdated string      `json:"lastupdated"`
}

PageSummaryWithLastUpdated is a struct for a Summary about pages

type PageSummaryWithSourceID added in v1.2.0

type PageSummaryWithSourceID struct {
	Page        intOrString `json:"page"`
	Pages       intOrString `json:"pages"`
	PerPage     intOrString `json:"per_page"`
	Total       intOrString `json:"total"`
	SourceID    string      `json:"sourceid"`
	LastUpdated string      `json:"lastupdated"`
}

PageSummaryWithSourceID is a struct for a Summary about pages

type RecentParam added in v1.3.0

type RecentParam struct {
	FrequencyType    FrequencyType
	MostRecentValues uint
	IsNotEmpty       bool
	IsGapFill        bool
}

RecentParam is struct for recent params

type Region

type Region struct {
	ID       string
	Code     string
	Iso2Code string
	Name     string
}

Region is a struct for region

type RegionsService

type RegionsService service

RegionsService ...

func (*RegionsService) Get

func (r *RegionsService) Get(code string) (*PageSummary, *Region, error)

Get returns a Response's Summary and a Region

Example
client := wbdata.NewClient(nil)
summary, region, _ := client.Regions.Get("xzn")

fmt.Printf("Summary is: %#v\n", summary)
fmt.Printf("Region is: %#v\n", region)
Output:

Summary is: &wbdata.PageSummary{Page:1, Pages:1, PerPage:50, Total:1}
Region is: &wbdata.Region{ID:"", Code:"XZN", Iso2Code:"A5", Name:"Sub-Saharan Africa excluding South Africa and Nigeria"}

func (*RegionsService) List

func (r *RegionsService) List(pages *PageParams) (*PageSummary, []*Region, error)

List returns a Response's Summary and Regions

Example
client := wbdata.NewClient(nil)
summary, regions, _ := client.Regions.List(
	&wbdata.PageParams{
		Page:    1,
		PerPage: 10,
	},
)

summary.Pages = 5
summary.Total = 48

fmt.Printf("Summary is: %#v\n", summary)
fmt.Printf("Regions[0] is: %#v\n", regions[0])
Output:

Summary is: &wbdata.PageSummary{Page:1, Pages:5, PerPage:10, Total:48}
Regions[0] is: &wbdata.Region{ID:"", Code:"AFR", Iso2Code:"A9", Name:"Africa"}

type Source

type Source struct {
	ID                   string
	LastUpdated          string
	Name                 string
	Code                 string
	Description          string
	URL                  string
	DataAvailability     string
	MetadataAvailability string
	Concepts             string
}

Source contains information for a source field

type SourcesService

type SourcesService service

SourcesService ...

func (*SourcesService) Get

func (s *SourcesService) Get(sourceID string) (*PageSummary, *Source, error)

Get returns a Response's Summary and a Source

Example
client := wbdata.NewClient(nil)
summary, source, _ := client.Sources.Get("1")

fmt.Printf("Summary is: %#v\n", summary)
fmt.Printf("Source is: %#v\n", source)
Output:

Summary is: &wbdata.PageSummary{Page:1, Pages:1, PerPage:50, Total:1}
Source is: &wbdata.Source{ID:"1", LastUpdated:"2019-10-23", Name:"Doing Business", Code:"DBS", Description:"", URL:"", DataAvailability:"Y", MetadataAvailability:"Y", Concepts:"3"}

func (*SourcesService) List

func (s *SourcesService) List(pages *PageParams) (*PageSummary, []*Source, error)

List returns a Response's Summary and Sources

Example
client := wbdata.NewClient(nil)
summary, sources, _ := client.Sources.List(
	&wbdata.PageParams{
		Page:    1,
		PerPage: 10,
	},
)

summary.Pages = 6
summary.Total = 59

fmt.Printf("Summary is: %#v\n", summary)
fmt.Printf("Sources[0] is: %#v\n", sources[0])
Output:

Summary is: &wbdata.PageSummary{Page:1, Pages:6, PerPage:10, Total:59}
Sources[0] is: &wbdata.Source{ID:"1", LastUpdated:"2019-10-23", Name:"Doing Business", Code:"DBS", Description:"", URL:"", DataAvailability:"Y", MetadataAvailability:"Y", Concepts:"3"}

type Topic

type Topic struct {
	ID         string
	Value      string
	SourceNote string
}

Topic contains information for an topic field

type TopicsService

type TopicsService service

TopicsService ...

func (*TopicsService) Get

func (t *TopicsService) Get(topicID string) (*PageSummary, *Topic, error)

Get returns a Response's Summary and a Topic

Example
client := wbdata.NewClient(nil)
summary, topic, _ := client.Topics.Get("1")

fmt.Printf("Summary is: %#v\n", summary)
fmt.Printf("Topic is: %#v\n", topic)
Output:

Summary is: &wbdata.PageSummary{Page:1, Pages:1, PerPage:50, Total:1}
Topic is: &wbdata.Topic{ID:"1", Value:"Agriculture & Rural Development", SourceNote:"For the 70 percent of the world's poor who live in rural areas, agriculture is the main source of income and employment. But depletion and degradation of land and water pose serious challenges to producing enough food and other agricultural products to sustain livelihoods here and meet the needs of urban populations. Data presented here include measures of agricultural inputs, outputs, and productivity compiled by the UN's Food and Agriculture Organization."}

func (*TopicsService) List

func (t *TopicsService) List(pages *PageParams) (*PageSummary, []*Topic, error)

List returns a Response's Summary and Topics

Example
client := wbdata.NewClient(nil)
summary, topics, _ := client.Topics.List(
	&wbdata.PageParams{
		Page:    1,
		PerPage: 10,
	},
)

summary.Pages = 3
summary.Total = 21

fmt.Printf("Summary is: %#v\n", summary)
fmt.Printf("Topics[0] is: %#v\n", topics[0])
Output:

Summary is: &wbdata.PageSummary{Page:1, Pages:3, PerPage:10, Total:21}
Topics[0] is: &wbdata.Topic{ID:"1", Value:"Agriculture & Rural Development", SourceNote:"For the 70 percent of the world's poor who live in rural areas, agriculture is the main source of income and employment. But depletion and degradation of land and water pose serious challenges to producing enough food and other agricultural products to sustain livelihoods here and meet the needs of urban populations. Data presented here include measures of agricultural inputs, outputs, and productivity compiled by the UN's Food and Agriculture Organization."}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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