Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Singleton
- public class WalmartlabsParseService implements ParseService {
- private static final String API_KEY = "-----------------";
- private final RetrofitService mService;
- @Inject
- public WalmartlabsParseService(@NonNull WalmartlabsParseService.RetrofitService service) {
- mService = service;
- }
- @Override
- public Observable<List<Product>> searchProductsByCode(@NonNull String code) {
- return mService
- .getProducts(API_KEY, code)
- .filter(item -> item.items != null && !item.items.isEmpty())
- .flatMap(item -> Observable.from(item.items))
- .flatMap(childNode -> {
- Product product = new Product();
- product.source = ProductSource.WALMART.getDisplay();
- product.name = childNode.name;
- product.imageUrl = childNode.largeImage;
- product.upc = childNode.upc;
- product.model = childNode.brandName;
- return Observable.just(product);
- })
- .toSortedList();
- }
- public interface RetrofitService {
- @GET("items")
- Observable<Item> getProducts(@Query("apiKey") String apiKey, @Query("upc") String code);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement