httpUser

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2017 License: BSD-3-Clause Imports: 7 Imported by: 1

Documentation

Overview

Package httpUser provides a Service that is a HTTP client to an external user service that can respond to HTTP requests defined here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthenticateRequest

type AuthenticateRequest struct {
	Password string `json:"password"`
}

AuthenticateRequest is a structure that is passed as JSON-encoded body to Authenticate HTTP request.

type AuthenticateResponse

type AuthenticateResponse struct {
	User *user.User `json:"user"`
}

AuthenticateResponse is expected structure of JSON-encoded response body for Authenticate HTTP request.

type ChangeEmailRequest

type ChangeEmailRequest struct {
	Token string `json:"token"`
}

ChangeEmailRequest is a structure that is passed as JSON-encoded body to ChangeEmail HTTP request.

type EmailChangeTokenResponse

type EmailChangeTokenResponse struct {
	Token string `json:"token"`
}

EmailChangeTokenResponse is expected structure of JSON-encoded response body for EmailChangeToken HTTP request.

type RegisterUserRequest

type RegisterUserRequest struct {
	Options                 *user.Options `json:"options"`
	Password                string        `json:"password"`
	EmailValidationDeadline time.Time     `json:"email-validation-deadline"`
}

RegisterUserRequest is a structure that is passed as JSON-encoded body to RegisterUser HTTP request.

type RegisterUserResponse

type RegisterUserResponse struct {
	User                 *user.User `json:"user"`
	EmailValidationToken string     `json:"email-validation-token"`
}

RegisterUserResponse is expected structure of JSON-encoded response body for RegisterUser HTTP request.

type RequestEmailChangeRequest

type RequestEmailChangeRequest struct {
	Email              string    `json:"email"`
	ValidationDeadline time.Time `json:"validation-deadline"`
}

RequestEmailChangeRequest is a structure that is passed as JSON-encoded body to RequestEmailChange HTTP request.

type RequestEmailChangeResponse

type RequestEmailChangeResponse struct {
	Token string `json:"token"`
}

RequestEmailChangeResponse is expected structure of JSON-encoded response body for RequestEmailChange HTTP request.

type RequestPasswordResetResponse

type RequestPasswordResetResponse struct {
	Token string `json:"token"`
}

RequestPasswordResetResponse is expected structure of JSON-encoded response body for RequestPasswordReset HTTP request.

type ResetPasswordRequest

type ResetPasswordRequest struct {
	Password string `json:"password"`
}

ResetPasswordRequest is a structure that is passed as JSON-encoded body to ResetPassword HTTP request.

type Service

type Service struct {
	Client *apiClient.Client
}

Service implements gopherpit.com/gopherpit/services/user.Service interface.

func NewService added in v0.3.1

func NewService(c *apiClient.Client) *Service

NewService creates a new Service and injects user.ErrorRegistry in the API Client.

func (Service) Authenticate

func (s Service) Authenticate(ref, password string) (u *user.User, err error)

Authenticate validates a password of an existing User by making a HTTP POST request to {Client.Endpoint}/users/{ref}/authenticate. Request body is a JSON-encoded AuthenticateRequest instance. Expected response body is a JSON-encoded instance of AuthenticateResponse.

func (Service) ChangeEmail

func (s Service) ChangeEmail(ref, token string) (u *user.User, err error)

ChangeEmail changes an email of an existing User only if provided token is valid by making a HTTP POST request to {Client.Endpoint}/users/{ref}/email-change. Request body is a JSON-encoded ChangeEmailRequest instance.

func (Service) CreateUser

func (s Service) CreateUser(o *user.Options) (u *user.User, err error)

CreateUser creates a new User instance by making a HTTP POST request to {Client.Endpoint}/users. Post body is a JSON-encoded user.Options instance.

func (Service) DeleteUser

func (s Service) DeleteUser(ref string) (u *user.User, err error)

DeleteUser deletes an existing User by making a HTTP DELETE request to {Client.Endpoint}/users/{ref}.

func (Service) EmailChangeToken

func (s Service) EmailChangeToken(ref, email string) (token string, err error)

EmailChangeToken retrieves a token to change an email, if it exists, by making a HTTP GET request to {Client.Endpoint}/users/{ref}/email-change/{email}.

func (Service) RegisterUser

func (s Service) RegisterUser(o *user.Options, password string, emailValidationDeadline time.Time) (u *user.User, emailValidationToken string, err error)

RegisterUser combines CreateUser SetPassword and RequestEmailChange into a single transaction to provide more convenient method for adding new users by making a HTTP POST request to {Client.Endpoint}/register. Request body is a JSON-encoded RegisterUserRequest instance. Expected response body is a JSON-encoded instance of RegisterUserResponse.

func (Service) RequestEmailChange

func (s Service) RequestEmailChange(ref, email string, validationDeadline time.Time) (token string, err error)

RequestEmailChange starts a process of changing an email by returning a token that must be used in ChangeEmail to authorize email change by making a HTTP POST request to {Client.Endpoint}/users/{ref}/email-change-request. Request body is a JSON-encoded RequestEmailChangeRequest instance. Expected response body is a JSON-encoded instance of RequestEmailChangeResponse.

func (Service) RequestPasswordReset

func (s Service) RequestPasswordReset(ref string) (token string, err error)

RequestPasswordReset starts a process of reseting a password by providing a token that must be used in ResetPassword to authorize password reset by making a HTTP POST request to {Client.Endpoint}/users/{ref}/password-reset-request. Expected response body is a JSON-encoded instance of RequestPasswordResetResponse.

func (Service) ResetPassword

func (s Service) ResetPassword(token, password string) (err error)

ResetPassword changes a password of an existing User by making a HTTP POST request to {Client.Endpoint}/users/{ref}/password-reset. Request body is a JSON-encoded ResetPasswordRequest instance.

func (Service) SetPassword

func (s Service) SetPassword(ref string, password string) (err error)

SetPassword changes a password of an existing User by making a HTTP POST request to {Client.Endpoint}/users/{ref}/password. Request body is a JSON-encoded SetPasswordRequest instance.

func (Service) UpdateUser

func (s Service) UpdateUser(ref string, o *user.Options) (u *user.User, err error)

UpdateUser changes the data of an existing User by making a HTTP POST request to {Client.Endpoint}/users/{ref}. Post body is a JSON-encoded user.Options instance.

func (Service) User

func (s Service) User(ref string) (u *user.User, err error)

User retrieves an existing User instance by making a HTTP GET request to {Client.Endpoint}/users/{ref}.

func (Service) UserByEmail

func (s Service) UserByEmail(email string) (u *user.User, err error)

UserByEmail retrieves an existing User instance by making a HTTP GET request to {Client.Endpoint}/users-by-email/{email}.

func (Service) UserByID

func (s Service) UserByID(id string) (u *user.User, err error)

UserByID retrieves an existing User instance by making a HTTP GET request to {Client.Endpoint}/users-by-id/{id}.

func (Service) UserByUsername

func (s Service) UserByUsername(username string) (u *user.User, err error)

UserByUsername retrieves an existing User instance by making a HTTP GET request to {Client.Endpoint}/users-by-username/{username}.

func (Service) UsersByEmail

func (s Service) UsersByEmail(startEmail string, limit int) (page *user.UsersPage, err error)

UsersByEmail retrieves a paginated list of User instances ordered by Email values by making a HTTP GET request to {Client.Endpoint}/users-by-email?start={stardEmail}&limit={limit}.

func (Service) UsersByID

func (s Service) UsersByID(startID string, limit int) (page *user.UsersPage, err error)

UsersByID retrieves a paginated list of User instances ordered by ID values by making a HTTP GET request to {Client.Endpoint}/users-by-id?start={stardID}&limit={limit}.

func (Service) UsersByUsername

func (s Service) UsersByUsername(startUsername string, limit int) (page *user.UsersPage, err error)

UsersByUsername retrieves a paginated list of User instances ordered by Username values by making a HTTP GET request to {Client.Endpoint}/users-by-username?start={stardUsername}&limit={limit}.

type SetPasswordRequest

type SetPasswordRequest struct {
	Password string `json:"password"`
}

SetPasswordRequest is a structure that is passed as JSON-encoded body to SetPassword HTTP request.

Jump to

Keyboard shortcuts

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