pixabay-lib

Simple Java library for Pixabay.com API

License

License

GroupId

GroupId

ru.blizzed
ArtifactId

ArtifactId

pixabay-lib
Last Version

Last Version

1.0.3
Release Date

Release Date

Type

Type

jar
Description

Description

pixabay-lib
Simple Java library for Pixabay.com API
Project URL

Project URL

https://github.com/BlizzedRu/Pixabay-Lib
Source Code Management

Source Code Management

https://github.com/BlizzedRu/Pixabay-Lib

Download pixabay-lib

How to add to project

<!-- https://jarcasting.com/artifacts/ru.blizzed/pixabay-lib/ -->
<dependency>
    <groupId>ru.blizzed</groupId>
    <artifactId>pixabay-lib</artifactId>
    <version>1.0.3</version>
</dependency>
// https://jarcasting.com/artifacts/ru.blizzed/pixabay-lib/
implementation 'ru.blizzed:pixabay-lib:1.0.3'
// https://jarcasting.com/artifacts/ru.blizzed/pixabay-lib/
implementation ("ru.blizzed:pixabay-lib:1.0.3")
'ru.blizzed:pixabay-lib:jar:1.0.3'
<dependency org="ru.blizzed" name="pixabay-lib" rev="1.0.3">
  <artifact name="pixabay-lib" type="jar" />
</dependency>
@Grapes(
@Grab(group='ru.blizzed', module='pixabay-lib', version='1.0.3')
)
libraryDependencies += "ru.blizzed" % "pixabay-lib" % "1.0.3"
[ru.blizzed/pixabay-lib "1.0.3"]

Dependencies

compile (3)

Group / Artifact Type Version
com.squareup.retrofit2 : retrofit jar 2.3.0
com.squareup.retrofit2 : converter-gson jar 2.3.0
com.squareup.retrofit2 : adapter-rxjava2 jar 2.4.0

Project Modules

There are no modules declared in this project.

Pixabay-Lib

Simple Java library for Pixabay API

Pixabay-Lib provides easy access to all available methods of Pixabay API. Can be useful for grabbing some pictures and videos from different categories.

  • Contains Java object wrappers for any API response
  • Supports RxJava Observable responses
  • Convenient request builders

Full list of methods and its params available in Pixabay API Documentation

Installing

Maven

In your pom.xml inside the <dependencies> tag

<dependencies>
    ...
    <dependency>
        <groupId>ru.blizzed</groupId>
        <artifactId>pixabay-lib</artifactId>
        <version>1.0.3</version>
    </dependency>
</dependencies>

Gradle

In your build.gradle file inside the dependencies section

  • Gradle 3.0 and above
dependencies {
   ...
   implementation 'ru.blizzed:pixabay-lib:1.0.3'
}
  • Below 3.0
dependencies {
    ...
    compile 'ru.blizzed:pixabay-lib:1.0.3'
}

Usage

Initialization

  • You don't care about language (EN is default)
Pixabay.initialize("your-api-key"));
  • You need a specific language from available lang list
Pixabay.initialize("your-api-key", LangParam.Lang.RU));

Russian language as example, you can choose any other

Building and executing requests

All methods of Pixabay API are available in Pixabay class after initialization. Use Pixabay.search() for usual case and Pixabay.rxSearch() if you prefer to deal with RxJava and its Observables.

You can pass any params to the call – just take a look at static class PixabayParams that contains completed instances of all parameters.

Imagine that you need to find some pics with animals

Pixabay.search().image(PixabayParams.CATEGORY.of(Category.ANIMALS))
        .execute()
        .getHits()
        .stream()
        .map(PixabayImage::getLargeImageURL)
        .forEach(System.out::println);

or the same but with a set of params (now you are looking for red pics with dog in cat. animals and horizontal orientation)

Pixabay.search().image(
             "dog",
             PixabayParams.CATEGORY.of(Category.ANIMALS),
             PixabayParams.COLORS.of(Color.RED),
             PixabayParams.ORIENTATION.of(Orientation.HORIZONTAL)
        )
        .execute()
        .getHits()
        .stream()
        .map(PixabayImage::getLargeImageURL)
        .forEach(System.out::println);

Callbacks

You can receive callbacks in two ways:

  • Catching exceptions
try {
    Pixabay.search().image().execute().getHits().forEach(System.out::println);
} catch (PixabayCallException | PixabayErrorException e) {
    // Handle error
} 
  • With listener
Pixabay.search().image().execute(new PixabayCaller.Listener<PixabayResult<PixabayImage>>() {
    @Override
    public void onComplete(PixabayResult<PixabayImage> result, PixabayCaller<PixabayResult<PixabayImage>> apiCaller) {
        // Handle result
    }

    @Override
    public void onError(PixabayError error, PixabayCaller<PixabayResult<PixabayImage>> apiCaller) {
        /* This method triggers you when API has been called but response contains an error */
        // Handle Api Error
    }

    @Override
    public void onFailure(PixabayCallException e, PixabayCaller<PixabayResult<PixabayImage>> apiCaller) {
        /* This method triggers you when call to API cannot be established. E.g. no internet connection */
        // Handle Failure
    }
});

Tip: you can override not all callback methods

  • Or by using RxJava Observables
Pixabay.rxSearch().image(PixabayParams.CATEGORY.of(Category.ANIMALS));

Requests cancelling

It goes without saying that you can also cancel request immediately if needs

caller.cancel();

License

Copyright (c) 2018 BlizzedRu (Ivan Vlasov)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Versions

Version
1.0.3
1.0.2
1.0.1
1.0.0