go-opap

module
v0.0.0-...-dd46240 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2021 License: MIT

README

go-opap

GoDoc codecov goReportCard

go-opap is a Go client library for accessing the OPAP Web Services.

Install

$ go get -u github.com/chanioxaris/go-opap

Usage

Construct a new OPAP client. Optionally, you can provide a custom http client and/or a User-Agent.

package main

import (
	"net/http"
	"time"

	"github.com/chanioxaris/go-opap/opap"
)

func main() {
	c, err := opap.NewClient(
		opap.WithHTTPClient(&http.Client{Timeout: time.Second * 10}),	// Optional
		opap.WithUserAgent("custom-user-agent"), // Optional
	)
	if err != nil {
		// Handle error
	}
    
	// Use services to access the API
}

Then use the various services on the client to access different parts of the API.

Examples

Get the active draw of Kino
package main

import (
	"context"
	"net/http"
	"time"

	"github.com/chanioxaris/go-opap/opap"
)

func main() {
	c, err := opap.NewClient()
	if err != nil {
		// Handle error
	}

	data, err := c.Kino.Draws.GetActive(context.Background())
	if err != nil {
		// Handle error
	}

	// Use fetched data
}
Get statistics of Tzoker
package main

import (
	"context"

	"github.com/chanioxaris/go-opap/opap"
)

func main() {
	c, err := opap.NewClient()
	if err != nil {
		// Handle error
	}

	data, err := c.Tzoker.Games.GetStatistics(context.Background())
	if err != nil {
		// Handle error
	}

	// Use fetched data
}
Get the last and active draw of PropoGoal
package main

import (
	"context"

	"github.com/chanioxaris/go-opap/opap"
)

func main() {
	c, err := opap.NewClient()
	if err != nil {
		// Handle error
	}

	data, err := c.PropoGoal.Draws.GetLastAndActive(context.Background())
	if err != nil {
		// Handle error
	}

   // Use fetched data
}
Get program of Propo (Sunday)
package main

import (
	"context"

	"github.com/chanioxaris/go-opap/opap"
)

func main() {
	c, err := opap.NewClient()
	if err != nil {
		// Handle error
	}

	data, err := c.PropoSunday.Program.Get(context.Background(), 12345)
	if err != nil {
		// Handle error
	}

	// Use fetched data
}

Query parameters

Almost every API method accepts optional query parameters. For example:

Get lotto draws by ID, include 20 results per page and fetch the 4th page
package main

import (
	"context"

	"github.com/chanioxaris/go-opap/api/draws"
	"github.com/chanioxaris/go-opap/opap"
)

func main() {
	c, err := opap.NewClient()
	if err != nil {
		// Handle error
	}

	ctx := context.Background()

	data, err := c.Lotto.Draws.GetByIDRange(ctx, 12345, 54321, draws.WithLimit(20), draws.WithPage(4))
	if err != nil {
		// Handle error
	}

	// Use fetched data
}

License

go-opap is MIT licensed.

Directories

Path Synopsis
api
draws
Package draws provides a service to consume API resource draws.
Package draws provides a service to consume API resource draws.
draws/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
games
Package games provides a service to consume API resource games.
Package games provides a service to consume API resource games.
games/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
pos
Package pos provides a service to consume API resource pos.
Package pos provides a service to consume API resource pos.
pos/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
program
Package program provides a service to consume API resource program.
Package program provides a service to consume API resource program.
program/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
internal
baseclient
Package baseclient contains a base API client to perform http requests.
Package baseclient contains a base API client to perform http requests.
opaptest
Package opaptest contains utilities to help with http client request testing.
Package opaptest contains utilities to help with http client request testing.
types
Package types contains OPAP specific types for internal use only.
Package types contains OPAP specific types for internal use only.
Package opap contains the client to access OPAP Web Services API.
Package opap contains the client to access OPAP Web Services API.
Package types contains API response types.
Package types contains API response types.

Jump to

Keyboard shortcuts

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