All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.notronix.etsy.impl.method.GetListingMethod Maven / Gradle / Ivy

There is a newer version: 3.0.0014
Show newest version
package com.notronix.etsy.impl.method;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.notronix.etsy.api.model.ListingAssociations;
import com.notronix.etsy.impl.model.EtsyListing;

import java.util.List;

import static com.notronix.etsy.impl.method.MethodUtils.addIfProvided;
import static com.notronix.etsy.impl.method.MethodUtils.safeList;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.joining;

public class GetListingMethod extends AbstractEtsyMethod>
{
    private List listingIds;
    private ListingAssociations[] associations;

    @Override
    public String getURI() {
        String uri = "/listings/"
                + requireNonNull(listingIds).stream().map(Object::toString).distinct().collect(joining(","));
        uri = addIfProvided(uri, "includes", safeList(associations), ASSOCIATIONS_CONVERTER);

        return uri;
    }

    @Override
    public List getResponse(Gson gson, String jsonPayload) {
        EtsyResponse> response
                = gson.fromJson(jsonPayload, new TypeToken>>(){}.getType());

        return response.getResults();
    }

    public List getListingIds() {
        return listingIds;
    }

    public void setListingIds(List listingIds) {
        this.listingIds = listingIds;
    }

    public GetListingMethod withListingIds(List listingIds) {
        this.listingIds = listingIds;
        return this;
    }

    public ListingAssociations[] getAssociations() {
        return associations;
    }

    public void setAssociations(ListingAssociations[] associations) {
        this.associations = associations;
    }

    public GetListingMethod withAssociations(ListingAssociations[] associations) {
        this.associations = associations;
        return this;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy