Android sdk for pelias
Java

README.md

Pelias Android SDK

Android SDK for Pelias

Circle CI

Usage

Pelias Android SDK is a client-side Java wrapper for Pelias plus Android specific integrations.

Initialization

Pelias provides a simple singleton which can be statically included in your application.

import static com.mapzen.android.Pelias.getPelias;

getPelias().<method> ...

Suggest

import static com.mapzen.android.Pelias.getPelias;

getPelias().suggest("term to search", Callback<Result>);

Search

import static com.mapzen.android.Pelias.getPelias;

getPelias().search("term to search", "<viewbox>", Callback<Result>);

Custom Endpoint

If you have deployed your own instance of pelias described here you can set it on the class before initializing

getPeliasWithEndpoint("http://your-pelias-domain.com").search("term to search", "<viewbox>", Callback<Result>);

Testing

The current stratedgy for testing involves mocking the service instance which is an retrofit interface which describes the paths to the API.

You can extend Pelias where you can inject you mock object ... we use Mockito which is awesome.

package com.mapzen.android;

import org.mockito.Mockito;

public final class TestPelias extends Pelias {
    protected TestPelias(PeliasService service) {
        super(service);
    }

    public static PeliasService getPeliasMock() {
        PeliasService service = Mockito.mock(PeliasService.class);
        instance = new TestPelias(service);
        return service;
    }
}

Then when you want to interact with Pelias in stests you can just feed it a mock.

@Captor
@SuppressWarnings("unused")
ArgumentCaptor<Callback<Result>> peliasCallback;


MockitoAnnotations.initMocks(this);
PeliasService peliasServiceMock = TestPelias.getPeliasMock();

Mockito.verify(peliasServiceMock)
  .getSearch(Mockito.eq("Empire State Building"), Mockito.anyString(), peliasCallback.capture());

With this you can verify which arguments got sent to the service ... and then to test success or failure path you can can capture the callback and retrive the value and call respective callbacks with your own object mocks you want to have returned in your test.

success

peliasCallback.getValue().success(results, response);

failure

peliasCallback.getValue().failure(RetrofitError.unexpectedError("", null));

Install

Download Jar

Download the latest AAR.

Maven

Include dependency using Maven.

<dependency>
  <groupId>com.mapzen.android</groupId>
  <artifactId>pelias-android-sdk</artifactId>
  <version>1.0.0</version>
</dependency>

Gradle

Include dependency using Gradle.

compile 'com.mapzen.android:pelias-android-sdk:1.0.0'