Search in sources :

Example 1 with Blogger

use of com.google.api.services.blogger.Blogger in project data-transfer-project by google.

the class GoogleBloggerImporter method importItem.

@Override
public ImportResult importItem(UUID jobId, IdempotentImportExecutor idempotentExecutor, TokensAndUrlAuthData authData, SocialActivityContainerResource data) throws Exception {
    Blogger blogger = getOrCreateBloggerService(authData);
    BlogList blogList = blogger.blogs().listByUser("self").execute();
    // NB: we are just publishing everything to the first blog, which is a bit of a hack,
    // but there is no API to create a new blog.
    String blogId = blogList.getItems().get(0).getId();
    for (SocialActivityModel activity : data.getActivities()) {
        if (activity.getType() == SocialActivityType.NOTE || activity.getType() == SocialActivityType.POST) {
            try {
                insertActivity(idempotentExecutor, data.getActor(), activity, blogId, authData);
            } catch (IOException | RuntimeException e) {
                throw new IOException("Couldn't import: " + activity, e);
            }
        }
    }
    return new ImportResult(ResultType.OK);
}
Also used : Blogger(com.google.api.services.blogger.Blogger) ImportResult(org.datatransferproject.spi.transfer.provider.ImportResult) BlogList(com.google.api.services.blogger.model.BlogList) SocialActivityModel(org.datatransferproject.types.common.models.social.SocialActivityModel) IOException(java.io.IOException)

Aggregations

Blogger (com.google.api.services.blogger.Blogger)1 BlogList (com.google.api.services.blogger.model.BlogList)1 IOException (java.io.IOException)1 ImportResult (org.datatransferproject.spi.transfer.provider.ImportResult)1 SocialActivityModel (org.datatransferproject.types.common.models.social.SocialActivityModel)1