transport

package
v0.0.0-...-6ca850d Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2020 License: MIT Imports: 5 Imported by: 0

README

transport

import "github.com/ronny/ptvapi/transport"

Overview

Package transport provides a custom transport that automatically calculates the request signature as required by the PTV Timetable API v3, and includes both the devid and signature query param in all requests to the API.

Example


	// Create a transport that will be wrapped by `SigningTransport`, here
	// we just create a default http transport from the
	// github.com/go-openapi/runtime/client package
	underlyingTransport := httptransport.New(
		apiclient.DefaultHost,
		apiclient.DefaultBasePath,
		apiclient.DefaultSchemes,
	)

	// Wrap the underlying transport and also supply devid and apikey that you
	// get from PTV
	transport := transport.NewSigningTransport(underlyingTransport,
		os.Getenv("DEVID"), os.Getenv("APIKEY"))

	// Create a new `client` (from github.com/ronny/ptvapi/client pkg) with the
	// custom transport
	client := apiclient.New(transport, strfmt.Default)

	// Use `client` as you would normally, without `devid` and `signature` params
	resp, err := client.Routes.RoutesOneOrMoreRoutes(&routes.RoutesOneOrMoreRoutesParams{
		Context: context.Background(),
	})

See examples/get-routes/ for a complete example of how to use this package.

Imported Packages

Index

Package files

doc.go signature.go transport.go

func Signature

func Signature(apiKey, requestURI string) (string, error)

type SigningTransport

type SigningTransport struct {
    Transport runtime.ClientTransport
    AuthInfo  runtime.ClientAuthInfoWriter
}

SigningTransport wraps another transport (Transport) to automatically add the devid and signature query params to every outgoing request as required by the PTV Timetable API v3.

The signature query param is calculated from the request URI and APIKey.

func NewSigningTransport
func NewSigningTransport(transport runtime.ClientTransport, devID string, apiKey string) *SigningTransport
func (*SigningTransport) Submit
func (t *SigningTransport) Submit(op *runtime.ClientOperation) (interface{}, error)

Generated by godoc2ghmd

Documentation

Overview

Package transport provides a custom transport that automatically calculates the request signature as required by the PTV Timetable API v3, and includes both the `devid` and `signature` query param in all requests to the API.

## Example

``` go

// Create a transport that will be wrapped by `SigningTransport`, here
// we just create a default http transport from the
// github.com/go-openapi/runtime/client package
underlyingTransport := httptransport.New(
	apiclient.DefaultHost,
	apiclient.DefaultBasePath,
	apiclient.DefaultSchemes,
)

// Wrap the underlying transport and also supply devid and apikey that you
// get from PTV
transport := transport.NewSigningTransport(underlyingTransport,
	os.Getenv("DEVID"), os.Getenv("APIKEY"))

// Create a new `client` (from github.com/ronny/ptvapi/client pkg) with the
// custom transport
client := apiclient.New(transport, strfmt.Default)

// Use `client` as you would normally, without `devid` and `signature` params
resp, err := client.Routes.RoutesOneOrMoreRoutes(&routes.RoutesOneOrMoreRoutesParams{
	Context: context.Background(),
})

```

See `examples/get-routes/` for a complete example of how to use this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Signature

func Signature(apiKey, requestURI string) (string, error)

Types

type SigningTransport

type SigningTransport struct {
	Transport runtime.ClientTransport
	AuthInfo  runtime.ClientAuthInfoWriter
}

SigningTransport wraps another transport (`Transport`) to automatically add the `devid` and `signature` query params to every outgoing request as required by the PTV Timetable API v3.

The `signature` query param is calculated from the request URI and `APIKey`.

func NewSigningTransport

func NewSigningTransport(transport runtime.ClientTransport, devID string, apiKey string) *SigningTransport

func (*SigningTransport) Submit

func (t *SigningTransport) Submit(op *runtime.ClientOperation) (interface{}, error)

Jump to

Keyboard shortcuts

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