Migration guide

From October 2020, Ogury released a new API specially refactored to improve the onboarding experience. In this guide, you will learn how to switch from the old API to the new one.

Import the Ogury SDK

In order to import the last version of the new Ogury SDK, you must update the Ogury's dependency in the build.gradle of your application. Now, you have to request the 5.+ version instead of the 4.+.

dependencies {
    // ...
    implementation 'co.ogury:ogury-sdk:5.+'
    // ...
}

Initialize the Ogury SDK

The way to initialize the Ogury SDK is a bit different. Replace the old API by the new one:

Old API

Presage.getInstance().start("OGY-XXXXXXXXXXXX", context);

New API

OguryConfiguration.Builder oguryConfigurationBuilder = new OguryConfiguration.Builder(context, "OGY-XXXXXXXXXXXX");
Ogury.start(oguryConfigurationBuilder.build());

In the new API, the Ogury.start() must be called before you use the Ogury Choice Manager and the Thumbnail Ad (Native API)

If you use the Ogury Choice Manager, you no longer have to initialize the Ogury's SDK in the OguryConsentListener callbacks. It must be initialized before calling the ask and edit method:

Old API

public class MyActivity extends Activity {

    @Override protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        OguryChoiceManager.initialize(context, "OGY-XXXXXXXXXXXX", new OguryCmConfig());
        OguryChoiceManager.ask(this, oguryConsentListener);
    }
    
    private final OguryConsentListener oguryConsentListener = new OguryConsentListener() {
        @Override public void onComplete(OguryChoiceManager.Answer answer) {
            Presage.getInstance().start("OGY-XXXXXXXXXXXX", this);
            // ... and load Ogury ad formats
        }
        @Override public void onError(OguryError error) {
            Presage.getInstance().start("OGY-XXXXXXXXXXXX", this);
            // ... and load Ogury ad formats
        }
    };
}

New API

public class MyActivity extends Activity {

    @Override protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        OguryConfiguration.Builder oguryConfigurationBuilder = new OguryConfiguration.Builder(this, "OGY-XXXXXXXXXXXX");
        Ogury.start(oguryConfigurationBuilder.build());
        
        OguryChoiceManager.ask(this, oguryConsentListener);
    }
    
    private final OguryConsentListener oguryConsentListener = new OguryConsentListener() {
        @Override public void onComplete(OguryChoiceManager.Answer answer) {
            // ... start other SDK - including AdMob's SDK - and load ad formats
            
        }
        @Override public void onError(OguryError error) {
            // ... start other SDK - including AdMob's SDK - and load ad formats
        }
    };
    
}

Note the OguryChoiceManager.initialize() method is not required anymore. It is replaced by the Ogury.start().

If you are still using the deprecated API of the Ogury Choice Manager, note the API has changed a bit:

Deprecated API

ConsentListener consentListener = new ConsentListener() {
    @Override public void onComplete(ConsentManager.Answer answer) {
        // ...
    }
    @Override public void onError(ConsentException e) {
        // ...
    }
};
ConsentManager.ask(this, "OGY-XXXXXXXXXXXX" consentListener);

New API

OguryConsentListener oguryConsentListener = new OguryConsentListener() {
    @Override public void onComplete(OguryChoiceManager.Answer answer) {
        // ...
    }
    @Override public void onError(OguryError error) {
        // ...
    }
};
OguryChoiceManager.ask(this, oguryConsentListener);

Integrate Thumbnail Ad (native API)

The way Thumbnail ads (native API) is loaded and displayed has not really changed. Ogury has just refactored a little bit the API in order to have a more consistent and smother API. Let's take a look at the changes.

The constructor takes no longer take an Activity and an AdConfig object as parameters. Now, it takes aContext and an ad unit string.

The method used to register a listener on the lifecycle of the thumbnail ad is now setListener instead of setCallback and takes a OguryThumbnailAdListener object as parameters instead of a OguryThumbnailAdCallback.

the OguryThumbnailAdCallback object becomes OguryThumbnailAdListener and the methods to implement is now:

Methods

Definition

onAdLoaded

The SDK is ready to display the ad provided by the ad server.

onAdDisplayed

The ad has been displayed on the screen.

onAdClicked

The as has been clicked by the user.

onAdClosed

The ad has been closed by the user.

onAdError

The ad failed to load or display.

The onAdAvailable, onAdNotAvailable, onAdNotLoaded methods have been removed. The onAdNotAvailable, onAdNotLoaded callbacks are now replaced by the onAdError callback.

Now, the onAdError callback provides an OguryError object instead of an error code integer. The OguryError parameter contains the reason of the failure.

In practice

Old API

AdConfig config = new AdConfig("YOUR_OGURY_AD_UNIT_ID");
final OguryThumbnailAd thumbnail = new OguryThumbnailAd(activity, config);
thumbnail.setCallback(new OguryThumbnailAdCallback() {

    @Override public void onAdAvailable() {
        // ...
    }

    @Override public void onAdNotAvailable() {
        // ...
    }

    @Override public void onAdLoaded() {
        thumbnail.show(activity);
    }

    @Override public void onAdNotLoaded() {
        // ...
    }

    @Override public void onAdDisplayed() {
        // ...
    }

    @Override public void onAdClosed() {
        // ...
    }

    @Override public void onAdError(int errorCode) {
        Log.w("Ogury", "An error occured (code: " + errorCode + ")");
    }
});
thumbnail.load();

New API

final OguryThumbnailAd thumbnail = new OguryThumbnailAd(context, "YOUR_OGURY_AD_UNIT_ID");
thumbnail.setListener(new OguryThumbnailAdListener() {

    @Override public void onAdLoaded () {
        thumbnail.show(activity);
    }

    @Override public void onAdDisplayed () { 
        // ...
    }
    
    @Override public void onAdClicked () {
        // ... 
    }
    
    @Override public void onAdClosed () {
        // ... 
    }

    @Override public void onAdError (OguryError oguryError) {
        Log.w("Ogury", "An error occured (code: " + oguryError.getErrorCode()
            + " ; message: " + oguryError.getMessage() + ")");
    }
});
thumbnail.load();

Last updated