-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
baato "github.com/baato/baato-go-client/lib" | ||
"github.com/baato/baato-go-client/lib/directions" | ||
) | ||
|
||
func main() { | ||
|
||
// initialize Baato core module | ||
accessToken := "YOUR BAATO ACCESS TOKEN" // Get Baato token from environment | ||
baatoMap := baato.Baato(accessToken) | ||
|
||
// intialize directions request options | ||
directionsRequest := directions.DirectionsRequestOptions{ | ||
PointsArray: []string{"27.6733433,85.2763307", "27.67444444,85.28047222"}, | ||
Mode: "bike", | ||
} | ||
|
||
directions, _ := baatoMap.Directions.GetDirections(directionsRequest) | ||
|
||
fmt.Println(directions.Data) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package directions | ||
|
||
import ( | ||
"github.com/baato/baato-go-client/lib/commons" | ||
"github.com/google/go-querystring/query" | ||
) | ||
|
||
const ( | ||
apiLabel = "directions" | ||
) | ||
|
||
type Directions struct { | ||
commons *commons.Commons | ||
} | ||
|
||
type DirectionsRequestOptions struct { | ||
PointsArray []string `url:"pointsArray"` | ||
Mode string `url:"mode"` | ||
Alternatives bool `url:"alternatives"` | ||
Instructions bool `url:"instructions"` | ||
} | ||
|
||
type DirectionsResponse struct { | ||
Timestamp string | ||
Status int | ||
Message string | ||
*commons.DirectionsData | ||
} | ||
|
||
func NewDirections(commons *commons.Commons) *Directions { | ||
return &Directions{commons} | ||
} | ||
|
||
func (d *Directions) GetDirections(request DirectionsRequestOptions) (*DirectionsResponse, error) { | ||
|
||
values, error := query.Values(request) | ||
|
||
// deserialize points array into each points[] query param | ||
pointsArray := request.PointsArray | ||
for _, s := range pointsArray { | ||
values.Add("points[]", s) | ||
} | ||
|
||
if error != nil { | ||
return nil, error | ||
} | ||
|
||
resp := DirectionsResponse{} | ||
|
||
d.commons.BaatoAPIRequest(apiLabel, &values, &resp) | ||
|
||
return &resp, error | ||
} |