Skip to content

Users Service

Maciej Mionskowski edited this page Mar 11, 2017 · 10 revisions

Users service let's you see all users on your account.

Creating Service

import (
	"github.com/route4me/route4me-go-sdk"
	"github.com/route4me/route4me-go-sdk/users"
)

func main() {
	client := route4me.NewClient("your-api-key")
	service := &users.Service{Client: client}
}

Endpoints

Getting users

import (
	"github.com/route4me/route4me-go-sdk"
	"github.com/route4me/route4me-go-sdk/users"
)

func main() {
	client := route4me.NewClient("your-api-key")
	service := &users.Service{Client: client}
	users, err := service.GetSubusers()
	if err != nil {
		// could not fetch users
		return
	}
	//do something with users, it's []*Member
}

Get User by ID

import (
	"github.com/route4me/route4me-go-sdk"
	"github.com/route4me/route4me-go-sdk/users"
)

func main() {
	client := route4me.NewClient("your-api-key")
	service := &users.Service{Client: client}
	users, err := service.GetUserByID(id)
	if err != nil {
		// could not fetch a user
		return
	}
	//do something with the user, it's *Member
}

Validating Session

Check if session is valid.

import (
	"github.com/route4me/route4me-go-sdk"
	"github.com/route4me/route4me-go-sdk/users"
)

func main() {
	client := route4me.NewClient("your-api-key")
	service := &users.Service{Client: client}
	success, err := service.ValidateSession("GUID",memberID)
	if err != nil {
		// session invalid, error making request
		return
	}
	if !success {
		// session invalid
		return
	}
	// session valid
}

Authenticating

Authentication of a user with an email and password.

import (
	"github.com/route4me/route4me-go-sdk"
	"github.com/route4me/route4me-go-sdk/users"
)

func main() {
	client := route4me.NewClient("your-api-key")
	service := &users.Service{Client: client}
	session, err := service.Authenticate("email","password")
	if err != nil {
		// auth unsuccessful
		return
	}
	if !session.Status {
		// session invalid
		return
	}
	//session valid
}

Register an account

Register a new account.

import (
	"github.com/route4me/route4me-go-sdk"
	"github.com/route4me/route4me-go-sdk/users"
)

func main() {
	client := route4me.NewClient("your-api-key")
	service := &users.Service{Client: client}
	account, err := service.Register(&users.MemberBase{
		FirstName:            "John",
		LastName:             "Example",
		Email:                "newdispatcher+something@gmail.com",
		Type:                 users.SubAccountDispatcher,
		Password:             "123",
		HideRouteAddresses:   true,
		HideVisitedAddresses: true,
	})
	if err != nil {
		//error making request
		return
	}
	//do something with the account
}

Create an account

Create a route4me account.

import (
	"github.com/route4me/route4me-go-sdk"
	"github.com/route4me/route4me-go-sdk/users"
)

func main() {
	client := route4me.NewClient("your-api-key")
	service := &users.Service{Client: client}
	success, err := service.Create(&Account{
		Industry:  "Gifting",
		FirstName: "Olman",
		LastName:  "Oland",
		Email:     "ololol@outlook.com",
		AcceptTOS: true,
		Password:  "111111",
		Plan:      "enterprise_plan",
	})
	if err != nil {
		//error making request
		return
	}
	if !success {
		//error occured, while creating an account
	}
}

Edit an account

import (
	"github.com/route4me/route4me-go-sdk"
	"github.com/route4me/route4me-go-sdk/users"
)

func main() {
	client := route4me.NewClient("your-api-key")
	service := &users.Service{Client: client}
	//fetch users to edit later
	users, err := service.GetSubusers()
	if err != nil {
		//could not get users
	}
	//get the last one
	user := users[len(users)-1]
	//change the phone number
	user.Phone = "123452"
	//call "edit"
	member, err := service.Edit(user)
	if err != nil {
		//editing failed
	}
}

Deleting an account

Remove an existing user from a member's account.

package test

import (
	"github.com/route4me/route4me-go-sdk"
	"github.com/route4me/route4me-go-sdk/users"
)

func main() {
	client := route4me.NewClient("your-api-key")
	service := &users.Service{Client: client}

	users, err := service.GetSubusers()
	if err != nil {
		//could not get users
	}
	//get the last one
	user := users[len(users)-1]

	resp, err := service.Delete(user.ID)
	if err != nil {
		//handle error
	}
	if !resp.Status {
		//something undefined went wrong
	}
}

Register to webinar

import (
	"github.com/route4me/route4me-go-sdk"
	"github.com/route4me/route4me-go-sdk/users"
)

func main() {
	client := route4me.NewClient("your-api-key")
	service := &users.Service{Client: client}
	success, err := service.RegisterToWebinar(&WebinarRegistration{
		EmailAddress: "oooooo@yahoo.com",
		FirstName:    "First Name",
		LastName:     "Last Name",
		PhoneNumber:  "454-454544",
		CompanyName:  "Company",
		MemberID:     "123456",
		WebiinarDate: "2016-06-05 10:00:00",
	})
	if err != nil {
		//handle error
		return
	}
	if success != nil {
		//unknown error
	}
}

Get config values

import (
	"github.com/route4me/route4me-go-sdk"
	"github.com/route4me/route4me-go-sdk/users"
)

func main() {
	client := route4me.NewClient("your-api-key")
	service := &users.Service{Client: client}
	values, err := service.GetConfigValues()
	if err != nil {
		//handle error
		return
	}
	//process values
}

Add config entry

import (
	"github.com/route4me/route4me-go-sdk"
	"github.com/route4me/route4me-go-sdk/users"
)

func main() {
	client := route4me.NewClient("your-api-key")
	service := &users.Service{Client: client}
	success, err := service.AddConfigEntry("config-test-key-go", "config-test-value-go")
	if err != nil {
		// request unsuccessful
		return
	}
	if !success {
		// couldn't add entry
		return
	}
	// everything went as expected
}

Get config entry

import (
	"github.com/route4me/route4me-go-sdk"
	"github.com/route4me/route4me-go-sdk/users"
)

func main() {
	client := route4me.NewClient("your-api-key")
	service := &users.Service{Client: client}
	value, err := service.GetConfigEntry("config-test-key-go")
	if err != nil {
		// request unsuccessful
		return
	}
	// value fetched
}

Update config entry

import (
	"github.com/route4me/route4me-go-sdk"
	"github.com/route4me/route4me-go-sdk/users"
)

func main() {
	client := route4me.NewClient("your-api-key")
	service := &users.Service{Client: client}
	success, err := service.UpdateConfigEntry("config-test-key-go", "config-test-value-go")
	if err != nil {
		// request unsuccessful
		return
	}
	if !success {
		// couldn't edit entry
		return
	}
	// everything went as expected
}

Delete config entry

import (
	"github.com/route4me/route4me-go-sdk"
	"github.com/route4me/route4me-go-sdk/users"
)

func main() {
	client := route4me.NewClient("your-api-key")
	service := &users.Service{Client: client}
	success, err := service.DeleteConfigEntry("config-test-key-go")
	if err != nil {
		// request unsuccessful
		return
	}
	if !success {
		// couldn't delete entry
		return
	}
	// key deleted
}

You can look at service's test file for more implementation details.

You can’t perform that action at this time.