Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. @Singleton
  2. public class WalmartlabsParseService implements ParseService {
  3.  
  4. private static final String API_KEY = "-----------------";
  5.  
  6. private final RetrofitService mService;
  7.  
  8. @Inject
  9. public WalmartlabsParseService(@NonNull WalmartlabsParseService.RetrofitService service) {
  10. mService = service;
  11. }
  12.  
  13. @Override
  14. public Observable<List<Product>> searchProductsByCode(@NonNull String code) {
  15. return mService
  16. .getProducts(API_KEY, code)
  17. .filter(item -> item.items != null && !item.items.isEmpty())
  18. .flatMap(item -> Observable.from(item.items))
  19. .flatMap(childNode -> {
  20. Product product = new Product();
  21.  
  22. product.source = ProductSource.WALMART.getDisplay();
  23. product.name = childNode.name;
  24. product.imageUrl = childNode.largeImage;
  25. product.upc = childNode.upc;
  26. product.model = childNode.brandName;
  27.  
  28. return Observable.just(product);
  29. })
  30. .toSortedList();
  31. }
  32.  
  33. public interface RetrofitService {
  34.  
  35. @GET("items")
  36. Observable<Item> getProducts(@Query("apiKey") String apiKey, @Query("upc") String code);
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement