-
Notifications
You must be signed in to change notification settings - Fork 2
Addressbook Service
Maciej Mionskowski edited this page Nov 1, 2016
·
4 revisions
Addressbook service let's you manage(add,delete,update) your contacts.
import (
"github.com/route4me/route4me-go-sdk"
"github.com/route4me/route4me-go-sdk/addressbook"
)
func main() {
client := route4me.NewClient("your-api-key")
service := &addressbook.Service{Client: client}
}
import (
"github.com/route4me/route4me-go-sdk"
"github.com/route4me/route4me-go-sdk/addressbook"
)
func main() {
client := route4me.NewClient("your-api-key")
service := &addressbook.Service{Client: client}
query := &addressbook.Query{
Limit: 10, //How many contacts to return
Offset: 0, //The offset (how many to skip) of contacts.
}
contacts, total, err := service.Get(query)
if err != nil {
//handle errors
return
}
//do something with contacts, it's []Contact
//total represents the total number of contacts in your addressbook
}
GET an address book location by containing specified text in any field.
import (
"github.com/route4me/route4me-go-sdk"
"github.com/route4me/route4me-go-sdk/addressbook"
)
func main() {
client := route4me.NewClient("your-api-key")
service := &addressbook.Service{Client: client}
query := &addressbook.Query{
Query: "technology",
Offset: 0,
Limit: 20,
}
locations, total, err := service.Get(query)
if err != nil {
//handle errors
return
}
// do something with locations
}
package test
import (
"github.com/route4me/route4me-go-sdk"
"github.com/route4me/route4me-go-sdk/addressbook"
)
func main() {
client := route4me.NewClient("your-api-key")
service := &addressbook.Service{Client: client}
query := &addressbook.Query{
Limit: 10, //How many contacts to return
Offset: 0, //The offset (how many to skip) of contacts.
Display: "routed", //include locations in routes
}
contacts, total, err := service.Get(query)
if err != nil {
//handle errors
return
}
//do something with contacts, it's []Contact
//total represents the total number of contacts in your addressbook
}
GET locations from an address book by a specified list of locations IDs.
import (
"github.com/route4me/route4me-go-sdk"
"github.com/route4me/route4me-go-sdk/addressbook"
)
func main() {
client := route4me.NewClient("your-api-key")
service := &addressbook.Service{Client: client}
query := &addressbook.Query{
AddressID: "4623361,6281217" //comma separated
}
locations, total, err := service.Get(query)
if err != nil {
//handle errors
return
}
// do something with locations
}
import (
"github.com/route4me/route4me-go-sdk"
"github.com/route4me/route4me-go-sdk/addressbook"
)
func main() {
client := route4me.NewClient("your-api-key")
service := &addressbook.Service{Client: client}
//To add a contact you will first need to create it's instance.
contact := &addressbook.Contact{
FirstName: "John",
Alias: "johny",
Address1: "Some address",
CachedLat: 38.024654,
CachedLng: -77.338814,
Email: "[email protected]",
PhoneNumber: "000-000-000",
StateID: "5",
CountryID: "3",
City: "City",
ZIP: "00-000",
}
newContact, err := service.Add(contact)
if err != nil {
//Handle errors
}
}
To remove a contact you will need it's ID.
import (
"github.com/route4me/route4me-go-sdk"
"github.com/route4me/route4me-go-sdk/addressbook"
)
func main() {
client := route4me.NewClient("your-api-key")
service := &addressbook.Service{Client: client}
removed, err := service.Delete([]string{"contact-id"})//It's likely your contact id is in uint64. You will need to convert it to string by calling strconv.FormatUint(contact-id, 10)
if err != nil {
//handle errors
return
}
}
To update a contact you will need it's ID or instance, you can get it by calling Get()
as stated above.
import (
"github.com/route4me/route4me-go-sdk"
"github.com/route4me/route4me-go-sdk/addressbook"
)
func main() {
client := route4me.NewClient("your-api-key")
service := &addressbook.Service{Client: client}
contact, err := service.Update(&contact)
if err != nil {
//handle errors
return
}
}
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