Skip to content

Commit

Permalink
Merge branch 'release/0.0.7' of github.com:Graqr/Threshr into release…
Browse files Browse the repository at this point in the history
…/0.0.7
  • Loading branch information
Jonathan-Zollinger committed Feb 20, 2024
2 parents 2009a41 + aa52d7f commit 861481b
Show file tree
Hide file tree
Showing 106 changed files with 804 additions and 297 deletions.
27 changes: 3 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ You'll need to add api `key` and `CHANNEL` values to environment variables `THRE
THRESHR_KEY=BatKey
THRESHR_CHANNEL=WEB
```

> :warning: Environment Variables on windows must be assigned as an environment variable, ie `$env:foo`.
<details><summary id="api-key">How to find a key for the redsky api</summary><ul>
In the network tab in your browser's dev tools, search for any endpoints from the `redsky.target.com` domain. Below I'm in firefox, from whose context menu I'm given the option to copy an api call's parameters.

![redsky_network-tab_firefox.gif](images%2Fredsky_network-tab_firefox.gif)
![redsky_network-tab_firefox.gif](media%2Fredsky_network-tab_firefox.gif)
</ul></details>

## Usage
Expand All @@ -59,42 +59,21 @@ Threshr doesn't support all redsky endpoints (not yet). There are three endpoint

```java
List<ProductSummary> fetchProductSummaries(TargetStore targetStore, Tcin tcin);

List<ProductSummary> fetchProductSummaries(TargetStore targetStore, String... tcin) throws ThreshrException;
```
```java
Product fetchProductDetails(TargetStore targetStore, String tcin);
```
```java
NearbyStores queryStoreLocations(Place place); // default values for limit and within

NearbyStores queryStoreLocations(int limit, int within, Place place);
```

### Using threshr pojo's

```java
/**
* Queries the availability of products at a target store.
*
* @param store location to query
* @param tcin one or more target product item numbers as string values
*
* returns a set of boolean values reflecting a product's availability.
*/
public Set<boolean> isProductInStock(TargetStore store, String ... tcin) {
ProductSummary summary = threshr.fetchProductSummaries(store, tcin);
return summary().stream().map(it ->
it.fulfillment().soldOut())
.collect(Collectors.toSet());
}
```

___

### Want to get involved?

See our [contributing] doc before taking a whack at any [open issues]. We'd love for you to work with us!
See our [contributing] doc before taking a whack at any [open issues]. Also be sure to read the [Testing README](src/test/groovy/com/graqr/threshr/README.md) for some tips and tricks. We'd love for you to work with us!


[these instructions]:https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry
Expand Down
File renamed without changes
44 changes: 33 additions & 11 deletions src/main/java/com/graqr/threshr/Threshr.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,36 @@
import com.graqr.threshr.model.queryparam.TargetStore;
import com.graqr.threshr.model.queryparam.TargetStorePdpSearch;
import com.graqr.threshr.model.queryparam.Tcin;
import com.graqr.threshr.model.redsky.products.Product;
import com.graqr.threshr.model.redsky.products.ProductSummary;
import com.graqr.threshr.model.redsky.stores.NearbyStores;
import com.graqr.threshr.model.redsky.product.Product;
import com.graqr.threshr.model.redsky.product.ProductSummary;
import com.graqr.threshr.model.redsky.store.NearbyStore;
import io.micronaut.core.async.annotation.SingleResult;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import jakarta.inject.Inject;
import lombok.Getter;
import lombok.Setter;

import java.util.List;
import java.util.Objects;

@Controller()
public class Threshr {

@Setter
@Getter
private String channel = "WEB";

@Inject
ThreshrClient threshrClient;


@Get("/product/summary-with-fulfillment")
@SingleResult
public List<ProductSummary> fetchProductSummaries(TargetStore targetStore, Tcin tcin) {
return Objects.requireNonNull(threshrClient.productSummaryWithFulfillment(targetStore, tcin).body()).data().productSummary();
public List<ProductSummary> fetchProductSummaries(TargetStore targetStore, Tcin tcin) throws ThreshrException {
return checkForNull(threshrClient.getProductSummary(targetStore, tcin))
.data()
.productSummary();
}

@Get("/product/summary-with-fulfillment")
Expand All @@ -35,20 +44,33 @@ public List<ProductSummary> fetchProductSummaries(TargetStore targetStore, Strin

@Get("/product/details")
@SingleResult
public Product fetchProductDetails(TargetStore targetStore, String tcin) {
return Objects.requireNonNull(threshrClient.productDetails(new TargetStorePdpSearch(targetStore), tcin).body()).data().product();
public Product fetchProductDetails(TargetStore targetStore, String tcin) throws ThreshrException {
return checkForNull(threshrClient.getProductDetails(new TargetStorePdpSearch(targetStore), tcin))
.data()
.product();
}

@Get("/stores/locations-query")
@SingleResult
public NearbyStores queryStoreLocations(Place place) {
public NearbyStore queryStoreLocations(Place place) throws ThreshrException {
return queryStoreLocations(5, 100, place);
}

@Get("/stores/locations-query")
@SingleResult
public NearbyStores queryStoreLocations(int limit, int within, Place place) {
return Objects.requireNonNull(threshrClient.queryNearbyStores(limit, within, place.getPlace()).body()).data().nearbyStores();
public NearbyStore queryStoreLocations(int limit, int within, Place place) throws ThreshrException {
return checkForNull(threshrClient.getNearbyStores(limit, within, place.getPlace()))
.data()
.nearbyStores();
}

private <T> T checkForNull(HttpResponse<T> response) throws ThreshrException {
if (null == response.body()) {
throw new ThreshrException(String.format("response body of HttpResponse<%s> is null", response
.body()
.getClass()
.getName()));
}
return response.body();
}
}
26 changes: 18 additions & 8 deletions src/main/java/com/graqr/threshr/ThreshrClient.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.graqr.threshr;

import com.graqr.threshr.model.queryparam.Place;
import com.graqr.threshr.model.queryparam.TargetStore;
import com.graqr.threshr.model.queryparam.TargetStorePdpSearch;
import com.graqr.threshr.model.queryparam.Tcin;
import com.graqr.threshr.model.redsky.products.pdp.client.PdpClientRoot;
import com.graqr.threshr.model.redsky.products.summary.ProductSummaryRoot;
import com.graqr.threshr.model.redsky.stores.NearbyStoresRoot;
import com.graqr.threshr.model.redsky.product.pdp.client.PdpClientRoot;
import com.graqr.threshr.model.redsky.product.summary.ProductSummaryRoot;
import com.graqr.threshr.model.redsky.store.location.StoreLocationRoot;
import com.graqr.threshr.model.redsky.store.nearby.NearbyStoreRoot;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.annotation.Get;
import io.micronaut.http.annotation.Header;
Expand Down Expand Up @@ -39,7 +39,6 @@
@Header(name = ACCEPT, value = "application/vnd.github.v3+json, application/json")
interface ThreshrClient {


/**
* Queries target's product summaries from of the given tcins at a given target store.
* A product summary does not include pricing.
Expand All @@ -54,7 +53,7 @@ interface ThreshrClient {
"{&tcins*}" +
"{&targetStore*}" +
"&CHANNEL=${threshr.channel}")
HttpResponse<ProductSummaryRoot> productSummaryWithFulfillment(
HttpResponse<ProductSummaryRoot> getProductSummary(
TargetStore targetStore,
Tcin tcins);

Expand All @@ -67,7 +66,7 @@ HttpResponse<ProductSummaryRoot> productSummaryWithFulfillment(
"?key=${threshr.key}" +
"{&tcin}" +
"{&targetStorePdpSearch*}")
HttpResponse<PdpClientRoot> productDetails(
HttpResponse<PdpClientRoot> getProductDetails(
TargetStorePdpSearch targetStorePdpSearch,
@Pattern(regexp = "(\\d{8})|(\\d{9})")
String tcin);
Expand All @@ -88,5 +87,16 @@ HttpResponse<PdpClientRoot> productDetails(
"{&within}" +
"{&place}" +
"&CHANNEL=${threshr.channel}")
HttpResponse<NearbyStoresRoot> queryNearbyStores(int limit, int within, String place);
HttpResponse<NearbyStoreRoot> getNearbyStores(int limit, int within, String place);

/**
* Get Store Information (ie store hours) for a specific Target Store
* @return Store object, generally with more information about the store than other store endpoints.
*/
@Get("store_location_v1" +
"?key=${threshr.key}" +
"{&storeId}" +
"{&channel}")
HttpResponse<StoreLocationRoot> getStoreInformation(String storeId, String channel, String page);

}
40 changes: 40 additions & 0 deletions src/main/java/com/graqr/threshr/model/queryparam/Page.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.graqr.threshr.model.queryparam;

import com.graqr.threshr.ThreshrException;
import lombok.Getter;

/**
* Query parameter in redsky api. Specifies from where an api call is made in the browser.
*/
@Getter
public class Page {
private String page;

/**
* Sets string value as "/c/" + provided value.
*
* @param page Query parameter in redsky api to specify from where an api call is made in the browser
* @throws ThreshrException if string contains anything other than letters or is empty
*/
public Page(String page) throws ThreshrException {
setPage(page);
}

/**
* Sets string value as "/c/" + provided value.
*
* @param page Query parameter in redsky api to specify from where an api call is made in the browser
* @throws ThreshrException if string contains anything other than letters or is empty
*/
public void setPage(String page) throws ThreshrException {
String tempPage = page.trim().toLowerCase();
if (tempPage.startsWith("/c/")) {
tempPage = tempPage.substring(3);
}
if (tempPage.matches(".+([^(a-z|\\-)]).+") || tempPage.isEmpty()) {
throw new ThreshrException(String.format(
"Expected only letters for the page value, but received \"%s\".", tempPage));
}
this.page = "/c/" + tempPage;
}
}
2 changes: 0 additions & 2 deletions src/main/java/com/graqr/threshr/model/queryparam/Place.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
@Data
public class Place {
private final String place;

public Place(String zipcode) {
if (!String.valueOf(zipcode).matches("^\\d{5}(-|\\s*)?(\\d{4})?$")) {
throw new IllegalArgumentException("Invalid zipcode provided, \"" + zipcode + "\". Zipcode provided " +
"must match this regex: \"^\\d{5}(-|\\s*)?(\\d{4})?$\"");
}
place = zipcode;

}

public Place(String city, String state) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graqr.threshr.model.redsky.products;
package com.graqr.threshr.model.redsky.product;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.micronaut.serde.annotation.Serdeable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graqr.threshr.model.redsky.products;
package com.graqr.threshr.model.redsky.product;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.micronaut.serde.annotation.Serdeable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graqr.threshr.model.redsky.products;
package com.graqr.threshr.model.redsky.product;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.micronaut.serde.annotation.Serdeable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graqr.threshr.model.redsky.products;
package com.graqr.threshr.model.redsky.product;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.micronaut.serde.annotation.Serdeable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graqr.threshr.model.redsky.products;
package com.graqr.threshr.model.redsky.product;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.micronaut.serde.annotation.Serdeable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graqr.threshr.model.redsky.products;
package com.graqr.threshr.model.redsky.product;

import io.micronaut.serde.annotation.Serdeable;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graqr.threshr.model.redsky.products;
package com.graqr.threshr.model.redsky.product;

import io.micronaut.serde.annotation.Serdeable;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graqr.threshr.model.redsky.products;
package com.graqr.threshr.model.redsky.product;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.micronaut.serde.annotation.Serdeable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graqr.threshr.model.redsky.products;
package com.graqr.threshr.model.redsky.product;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.micronaut.serde.annotation.Serdeable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graqr.threshr.model.redsky.products;
package com.graqr.threshr.model.redsky.product;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.micronaut.serde.annotation.Serdeable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graqr.threshr.model.redsky.products;
package com.graqr.threshr.model.redsky.product;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.micronaut.serde.annotation.Serdeable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graqr.threshr.model.redsky.products;
package com.graqr.threshr.model.redsky.product;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.micronaut.serde.annotation.Serdeable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graqr.threshr.model.redsky.products;
package com.graqr.threshr.model.redsky.product;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.micronaut.serde.annotation.Serdeable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graqr.threshr.model.redsky.products;
package com.graqr.threshr.model.redsky.product;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.micronaut.core.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graqr.threshr.model.redsky.products;
package com.graqr.threshr.model.redsky.product;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.micronaut.serde.annotation.Serdeable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graqr.threshr.model.redsky.products;
package com.graqr.threshr.model.redsky.product;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.micronaut.serde.annotation.Serdeable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graqr.threshr.model.redsky.products;
package com.graqr.threshr.model.redsky.product;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.micronaut.serde.annotation.Serdeable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graqr.threshr.model.redsky.products;
package com.graqr.threshr.model.redsky.product;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.micronaut.serde.annotation.Serdeable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graqr.threshr.model.redsky.products;
package com.graqr.threshr.model.redsky.product;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.micronaut.core.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graqr.threshr.model.redsky.products;
package com.graqr.threshr.model.redsky.product;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.micronaut.serde.annotation.Serdeable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graqr.threshr.model.redsky.products;
package com.graqr.threshr.model.redsky.product;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.micronaut.serde.annotation.Serdeable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graqr.threshr.model.redsky.products;
package com.graqr.threshr.model.redsky.product;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.micronaut.core.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graqr.threshr.model.redsky.products;
package com.graqr.threshr.model.redsky.product;

import io.micronaut.serde.annotation.Serdeable;

Expand Down
Loading

0 comments on commit 861481b

Please sign in to comment.