-
Notifications
You must be signed in to change notification settings - Fork 2
Users Service
Maciej Mionskowski edited this page Mar 11, 2017
·
10 revisions
Users service let's you see all users on your 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}
}
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
}
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
}
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
}
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 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: "[email protected]",
Type: users.SubAccountDispatcher,
Password: "123",
HideRouteAddresses: true,
HideVisitedAddresses: true,
})
if err != nil {
//error making request
return
}
//do something with the 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: "[email protected]",
AcceptTOS: true,
Password: "111111",
Plan: "enterprise_plan",
})
if err != nil {
//error making request
return
}
if !success {
//error occured, while creating 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
}
}
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
}
}
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: "[email protected]",
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
}
}
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
}
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
}
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
}
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
}
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.
- Activity
- Addressbook
- Routing
- Single Driver Route 10 Stops
- Single Driver Round Trip
- Single Depot Multiple Driver No Time Windows
- Single Depot Multiple Driver Time Windows
- Multiple Depot Multiple Driver
- Multiple Depot Multiple Driver With Time Windows
- Multiple Depot Multiple Driver With Time Windows (24 Stops)
- Tracking
- Geocoding
- Users
- Territories
- Orders
- Vehicles
- Telematics