Skip to content
Maciej Mionskowski edited this page Jun 2, 2017 · 6 revisions

Activity service let's you fetch events associated routes.

Creating Service

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

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

Endpoints

Getting activities

In order to fetch activities of a specific route you need to know it's route-id.

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{RouteID:"route-id"})
	if err != nil {
		t.Error(err)
	}
	//do something with activities, it's []Activity
}

Getting last activities

In order to fetch activities of a specific route you need to know it's route-id. To fetch activities that happened after specific timestamp Start parameter has to be applied to activity.Query

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(
		&activity.Query{
			RouteID:"route-id",
			Start: 1495238400, //Start is a timestamp
		}
	}
	if err != nil {
		t.Error(err)
	}
	//do something with activities, it's []Activity
}

Logging a specific message

This example demonstrates how to permanently store a specific message directly to the activity feed. For example, this can be used for one or two-way chat.

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	err := service.Log("Message", "ROUTE_ID")
	if err != nil {
		// handle error
	}
	// success!
}

Area Added

GET area added activities.

Area refers to a geographic territory, which can be added as a territory or as an avoidance zone for route planning

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{Type: service.AreaAdded})
	if err != nil {
		// handle error
	}
	// do something with activities, it's []Activity
}

Area Removed

GET area removed activities.

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{Type: service.AreaRemoved})
	if err != nil {
		// handle error
	}
	// do something with activities, it's []Activity
}

Area Updated

GET area updated activities.

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{Type: service.AreaUpdated})
	if err != nil {
		// handle error
	}
	// do something with activities, it's []Activity
}

Destination Deleted

GET destination deleted activities.

Destination refers to a point on a route or address, it is where the driver should drive the vehicle. It has sequence numbers within the route

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{Type: service.DeleteDestination})
	if err != nil {
		// handle error
	}
	// do something with activities, it's []Activity
}

Destination Out of Sequence

GET destination out of sequence activities (events).

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{Type: service.DestinationOutSequence})
	if err != nil {
		// handle error
	}
	// do something with activities, it's []Activity
}

Driver arrived early

GET driver arrived early activities (events).

Driver refers to a person who is assigned to a vehicle by the user to drive that vehicle on routes defined by that user

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{Type: service.DriverArrivedEarly})
	if err != nil {
		// handle error
	}
	// do something with activities, it's []Activity
}

Driver arrived late

GET driver arrived late activities (events).

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{Type: service.DriverArrivedLate})
	if err != nil {
		// handle error
	}
	// do something with activities, it's []Activity
}

Driver arrived on-time

GET driver arrived on time activities (events).

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{Type: service.DriverArrivedOnTime})
	if err != nil {
		// handle error
	}
	// do something with activities, it's []Activity
}

Geofence entered

GET geofence entered activities (events).

A geo-fence is a virtual perimeter for a real-world geographic area. A geo-fence could be a radius around a store or point location, or a geo-fence can be a predefined set of boundaries, like school attendance zones or neighborhood boundaries. Geo-fencing allows a user to set up triggers so when a device enters (or exits) the boundaries defined by that user, a text message or email alert is sent.

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{Type: service.GeofenceEntered})
	if err != nil {
		// handle error
	}
	// do something with activities, it's []Activity
}

Geofence left

GET geofence left activities (events).

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{Type: service.GeofenceLeft})
	if err != nil {
		// handle error
	}
	// do something with activities, it's []Activity
}

Destination inserted to a certain route

GET destination inserted activities (events) from a certain route.

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{Type: service.InsertDestination, RouteID: "5C15E83A4BE005BCD1537955D28D51D7"})
	if err != nil {
		// handle error
	}
	// do something with activities, it's []Activity
}

Destination inserted all routes

GET destination inserted activities (events) from all routes.

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{Type: service.InsertDestination})
	if err != nil {
		// handle error
	}
	// do something with activities, it's []Activity
}

Destination marked as departed from a certain route

GET destination marked as departed activities (events) from a certain route.

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{Type: service.MarkDestinationDeparted, RouteID: "5C15E83A4BE005BCD1537955D28D51D7"})
	if err != nil {
		// handle error
	}
}

Destination marked as departed all routes

GET destination marked as departed activities (events) from all routes.

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{Type: service.MarkDestinationDeparted})
	if err != nil {
		// handle error
	}
	// do something with activities, it's []Activity
}

Destination marked as visited

GET destination marked as visited activities (events) from all routes.

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{Type: service.MarkDestinationVisited})
	if err != nil {
		// handle error
	}
	// do something with activities, it's []Activity
}

Member created

GET member created activities (events).

Member refers to a registered user of Route4Me's API who has their own programming environment in our system (access to API endpoints, routes, address books, etc.)

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{Type: service.MemberCreated})
	if err != nil {
		// handle error
	}
	// do something with activities, it's []Activity
}

Member deleted

GET member deleted activities (events).

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{Type: service.MemberDeleted})
	if err != nil {
		// handle error
	}
	// do something with activities, it's []Activity
}

Member modified

GET member modified activities (events).

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{Type: service.MemberModified})
	if err != nil {
		// handle error
	}
	// do something with activities, it's []Activity
}

Destination moved (all)

GET destination moved to other route activities (events) from all routes.

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{Type: service.MoveDestination})
	if err != nil {
		// handle error
	}
	// do something with activities, it's []Activity
}

Note inserted from a certain route

GET note inserted activities (events) from a certain route.

Note refers to a text attached to a certain route or address

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{Type: service.NoteInsert, RouteID: "5C15E83A4BE005BCD1537955D28D51D7"})
	if err != nil {
		// handle error
	}
	// do something with activities, it's []Activity
}

Note inserted from all routes

GET note inserted activities (events) from all routes

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{Type: service.NoteInsert})
	if err != nil {
		// handle error
	}
	// do something with activities, it's []Activity
}

Route deleted

GET route deleted activities (events) from all routes.

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{Type: service.RouteDelete})
	if err != nil {
		// handle error
	}
	// do something with activities, it's []Activity
}

Route optimized

GET route optimized activities (events) from all routes.

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{Type: service.RouteOptimized})
	if err != nil {
		// handle error
	}
	// do something with activities, it's []Activity
}

Route owner changed

GET route owner changed activities (events) from a certain route

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{Type: service.RouteOptimized, RouteID: "5C15E83A4BE005BCD1537955D28D51D7"})
	if err != nil {
		// handle error
	}
	// do something with activities, it's []Activity
}

Destination updated (all)

GET destination updated activities (events) from all routes.

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{Type: service.UpdateDestinations})
	if err != nil {
		// handle error
	}
	// do something with activities, it's []Activity
}

Send user message

GET all messages send activities

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{Type: service.UserMessage})
	if err != nil {
		// handle error
	}
	// do something with activities, it's []Activity
}

Get Team Activities on a Route

The example refers to the process of getting all recorded activities associated not only with a specific Route4Me account, but also with other users of a member’s team.

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

func main() {
	client := route4me.NewClient("your-api-key")
	service := &activity.Service{Client: client}
	activities, err := service.Get(&activity.Query{
		Team:    true,
		RouteID: "06B655F27E0D6A74BD37F6F9758E4D2E",
	})
	if err != nil {
		// handle error
	}
	// do something with activities, it's []Activity
}

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

Clone this wiki locally