liguetaxi

package module
v0.0.0-...-ed05083 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2019 License: MIT Imports: 8 Imported by: 0

README

liguetaxi

liguetaxi is a Go client library for acessing the Ligue Taxi API

Usage

import "bitbucket.org/mobilitee/liguetaxi"

Construct a new LigueTaxi client, then use the various services on the client to access different parts of the LigueTaxi API. For example:

host, _ := url.Parse("https://portal.taxidigital.net/suporte/php/API_TD/api/")

ligtaxi := liguetaxi.New(host, "token", nil)

// Read user info.
user, _ := ligtaxi.User.Read(context.Background(), "00115422321", "Jo�o da Silva")

The services of a client divide the API into logical chunks and correspond to the struct of the Ligue Taxi API documentation.

For more sample code snippets, head over to the _test.go files.

Authentication

The liguetaxi library handles the Authorization header with a custom Transport.

Creating and Updating Resources

Resources that can be created or updated in the Ligue Taxi API are exposed by the liguetaxi library through structs.

newUser := &liguetaxi.User{
        Name: "Jo�o da Silva",
        Email: "test@gmail.com",
        Phone: "11986548744",
        Password: "1234321",
        Classifier1: "Classifier Field",
}
ligtaxi.User.Create(context.Background(), newUser)

Tests

Running unit tests

You can run unit tests using the following command from the library's root directory:

$ go test -v -cover
Running integration tests

You can run integration tests from the testdirectory. See the integration tests README

Roadmap

This library is being initally developed for an internal application at Mobilitee, so API methods will likely be implemented in the order they are needed by the application.

Versioning

liguetax folows semver as closely as we can for tagging releases of the package. Because liguetaxi is a client library for the Ligue Taxi API, which itself can change behaviour, we've adopted the following policy:

  • Increment the major version with any incompatible change to the API functionality.
  • Increment the minor version with any backward-compatible changes to the API functionality.
  • Increment the patch version with any backwards-compatible bug fixes.
TODO
  • Implement the ride methods
  • Implement XML requests

Documentation

Index

Constants

View Source
const (
	// Request statuses.
	ReqStatusFail reqStatus = iota
	ReqStatusOK
)
View Source
const (
	Json = `json`
	Xml  = `xml`
)

Request return types.

View Source
const (
	UserStatusInactive userStatus = iota
	UserStatusActive
	UserStatusSynching
)

User statuses

Variables

View Source
var ResType contextKey

ResType is the context key to use with context's WithValue function to set the type of request's payload that will be received from the API.

Functions

This section is empty.

Types

type ApiError

type ApiError struct {
	// contains filtered or unexported fields
}

ApiError implements the error interface and returns infos from the request

func (*ApiError) Error

func (e *ApiError) Error() string

type Classifier

type Classifier struct {
	ID              string `json:"field_id,omitempty"`
	Field           string `json:"field,omitempty"`
	Value           string `json:"field_value"`
	AdditionalValue string `json:"field_additional_value,omitempty"`
}

Classifier is the classifier field infos.

type ClassifierOperationResponse

type ClassifierOperationResponse struct {
	OperationResponse

	Data string `json:"data"`
}

ClassifierOperationResponse is the response returned by the API for non-idempotent operations on user's classifier fields.

type ClassifierResponse

type ClassifierResponse struct {
	Status reqStatus

	Data []Classifier `json:"data"`
}

ClassifierResponse is the response returned by the API when reading the classifier field info.

type Client

type Client struct {

	// User is the service that handles http logic for requests
	// related to the user.
	User *UserService
	// contains filtered or unexported fields
}

Client encapsulates the requests to the Ligue Taxi endpoints.

func NewClient

func NewClient(host *url.URL, token string, client *http.Client) *Client

New returns a Client for requests Ligue Taxi API.

func (*Client) Request

func (c *Client) Request(ctx context.Context, method string, path endpoint, body, output interface{}) error

Request created an API request. A relative path can be providaded in which case it is resolved relative to the host of the Client.

type DataUser

type DataUser struct {
	ID                string         `json:"authorized_id"`
	Name              string         `json:"client_name"`
	Email             *emptyObjToStr `json:"client_email"`
	Phone             *emptyObjToStr `json:"client_phone"`
	Status            *userStatus    `json:"cod_status"`
	StatusDescription string         `json:"status_description"`
}

DataUser is the result from check user request.

type OperationResponse

type OperationResponse struct {
	Status reqStatus

	Message string `json:"message"`
}

OperationResponse is the response returned by the API for non-idempotent operations on user.

type Status

type Status struct {
	Status reqStatus `json:"status"`
}

status is the request status.

type Transport

type Transport struct {
	// Token is the string to be injected to the
	// outgoing request header
	Token string

	// Base is the base RoundTripper to make HTTP request.
	Base http.RoundTripper
}

Transport is the RountTripper for injecting the authorization header for every request to Ligue Taxi player.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip injects the Authorization Header with the Token

type User

type User struct {
	ID           string `json:"unique_field,omitempty"`
	Name         string `json:"user_name"`
	Email        string `json:"user_email"`
	Phone        string `json:"user_phone,omitempty"`
	Password     string `json:"user_password,omitempty"`
	Classifier1  string `json:"classificador1,omitempty"`
	Classifier2  string `json:"classificador2,omitempty"`
	Classifier3  string `json:"classificador3,omitempty"`
	Classifier4  string `json:"classificador4,omitempty"`
	Classifier5  string `json:"classificador5,omitempty"`
	Classifier6  string `json:"classificador6,omitempty"`
	Classifier7  string `json:"classificador7,omitempty"`
	Classifier8  string `json:"classificador8,omitempty"`
	Classifier9  string `json:"classificador9,omitempty"`
	Classifier10 string `json:"classificador10,omitempty"`
	Classifier11 string `json:"classificador11,omitempty"`
	Classifier12 string `json:"classificador12,omitempty"`
	Classifier13 string `json:"classificador13,omitempty"`
	Classifier14 string `json:"classificador14,omitempty"`
	Classifier15 string `json:"classificador15,omitempty"`
	Classifier16 string `json:"classificador16,omitempty"`
	Classifier17 string `json:"classificador17,omitempty"`
	Classifier18 string `json:"classificador18,omitempty"`
	Classifier19 string `json:"classificador19,omitempty"`
	Classifier20 string `json:"classificador20,omitempty"`
}

User is sent to server when creating or editing user.

type UserResponse

type UserResponse struct {
	Status reqStatus

	Data DataUser `json:"data"`
}

UserResponse is the response returned by the API when listing a user info.

type UserService

type UserService service

UserService handles the requests related to the user.

func (*UserService) Create

func (us *UserService) Create(ctx context.Context, u *User) (*OperationResponse, error)

Create returns the status operation for creating a user or an error.

func (*UserService) CreateClassifier

func (us *UserService) CreateClassifier(ctx context.Context, c *Classifier) (*ClassifierOperationResponse, error)

CreateClassifier returns the status operation for creating classifier field or an error.

func (*UserService) Read

func (us *UserService) Read(ctx context.Context, id, name string) (*UserResponse, error)

Read returns User infos or an error.

func (*UserService) ReadClassifier

func (us *UserService) ReadClassifier(ctx context.Context, field, value string) (*ClassifierResponse, error)

ReadClassifier returns the classifier field info.

func (*UserService) Update

func (us *UserService) Update(ctx context.Context, u *User) (*OperationResponse, error)

Update returns the status operation for updating user or an error.

func (*UserService) UpdateStatus

func (us *UserService) UpdateStatus(ctx context.Context, s *UserStatus) (*OperationResponse, error)

UpdateStatus returns the status operation for updating the user status or an error.

type UserStatus

type UserStatus struct {
	ID     string     `json:"authorized_id"`
	Name   string     `json:"user_name,omitempty"`
	Status userStatus `json:"status"`
	Reason string     `json:"reason,omitempty"`
}

UserStatus is the user status infos.

Jump to

Keyboard shortcuts

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