Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.
Jan Škrášek edited this page Oct 30, 2019 · 14 revisions

Sygic Travel SDK provides access to Sygic Travel API & data. The whole SDK is divided into separate modules. These modules are partially connected but you may choose to use only some of them. SDK provides the following modules:

  • Places module: provides an interface for searching places, fetching lists & details of places, fetching places' media & reviews;
  • Session module: allows managing a session for handling user data;
  • Trips module: provides interface for creating & managing user trips;
  • Favorites module: manages user's favorite places;
  • Synchronization module: allows server synchronization of user data;
  • Directions module: interface for fetching navigation data between places;
  • Events module: central place for SDK's internal events handling;
  • Tours module: provides an interface for searching tours, fetching lists of tours;

For further details see SDK Reference Documentation. You may also check the JSON API Documentation.

Installation

First, add an implementation dependency to your build.gradle file. Check the releases for the latest version.

dependencies {
	implementation 'com.sygic.travel:sdk:3.0.0'
}

SDK artifacts are available on jCenter, add jcenter() to your repositories.

Initialize an SDK instance in your dependency injection container or directly in your Application. You need to obtain an API key and a Client ID, contact us at https://travel.sygic.com/b2b/api-key. In case you want to use only Places module API key is sufficient. Most of the modules require also Client ID, see the specific modules.

val sdk = Sdk(
	applicationContext,
	object : SdkConfig() {
		override val apiKey
			get() = "your-api-key"
		override val clientId
			get() = "your-client-id"
	}
)

User Data

Some modules work with user-data. To correctly setup SDK to work with user data, you have to configure clientId and sign in/up your user through Session module to have a valid session. If you don't need user-data facing modules, you may let the clinetId be a null.

Usage

All SDK calls are synchronous and must be called from a background thread.

To ease the implementation, you may use any tool you like/already use in your application. The best approach is to use Kotlin language and coroutines; however, SDK can, of course, be used from Java as shown in the following examples with Rx Java. We provide two basic examples for the start, all of the other examples use only Kotlin.

Kotlin example:

suspend fun getPlaces(): List<Place> {
	async {
		val placesQuery = PlacesQuery()
		placesQuery.levels = listOf(Level.POI)
		placesQuery.categories = listOf(Category.SIGHTSEEING)
		placesQuery.parentIds = listof("city:1")
		placesQuery.limit = 10

		sdk.placesFacade.getPlaces(placeQuery)
	}.await()
}

Java & RxJava example:

Single.fromCallable(new Callable<List<Place>>() {
		@Override
		public List<PlaceInfo> call() throws Exception {
			PlacesQuery placeQuery = new PlacesQuery();
			placeQuery.setLevels(Collections.singletonList(Level.POI));
			placeQuery.setCategories(Collections.singletonList(Category.SIGHTSEEING));
			placeQuery.setParentIds(Collections.singletonList("city:1"));
			placeQuery.setLimit(10);

			return sdk.getPlacesFacade().getPlaces(placeQuery);
		}
	})
	.subscribeOn(Schedulers.io())
	.observeOn(AndroidSchedulers.mainThread())
	.subscribe(new Consumer<List<Place>>() {
		@Override
		public void accept(List<Place> places) throws Exception {
			// do something with fetched places
		}
	});

Error handling

Errors are propagated as exceptions, the best way is to try/catch for runtime exceptions. We recommend catching mainly java.lang.IOException for general networking issues and retrofit2.HttpException for specific HTTP error states.

Clone this wiki locally