Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release/0.0.13 #142

Merged
merged 9 commits into from
Jun 19, 2024
70 changes: 25 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,72 +39,48 @@

## Summary

Threshr is a wrapper library for Target Corporation's redsky api. The redsky api has endpoints for querying product and store information. This includes fulfillment options, pricing, vendors, etc.
Threshr is a wrapper library for various grocery store api's. This includes querying specific store pricing and product data.

### Projects using threshr

Other projects using threshr include other graqr projects like the [threshr cli] and [harvester]

## Install

This project's artifacts are hosted on GitHub. Follow [these instructions] in order to include threshr in your maven or
gradle projects.
<ul>
<details><summary>My summary of GitHub's Instructions</summary>
<ol>
At the time of writing this, GitHub doesn't support using GitHub-hosted artifacts without first authenticating. You can do this in two steps:
<li>Generate a personal access token with <code>read:packages</code> <a href="https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token">privileges</a>. </li>
<li>Add <code><a href="settings.xml">settings.xml</a></code> to your <code>~/.m2/</code> directory (swapping Batman's name and password for your GitHub user and the token from step 1</li>
</ol>
</details>
</ul>
Threshr is available to jvm projects via [maven central].

<details><summary>Maven</summary>

#### Include as a Maven Dependency
```xml
<dependency>
<groupId>com.graqr</groupId>
<artifactId>threshr</artifactId>
<version>0.0.12</version>
<version>0.0.13</version>
</dependency>
```
#### Include as a Gradle dependency
```groovy
compile "com.graqr:threshr:0.0.12"
```

#### Environment Variables

You'll need to add api `key` and `CHANNEL` values to environment variables `THRESHR_KEY` and `THRESHR_CHANNEL`. I like using a `.env` file like the one below.
```properties
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.
</details>

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

## Usage
```groovy
implementation group: 'com.graqr', name: 'threshr', version: '0.0.13'
```
</details>

Threshr doesn't support all redsky endpoints (not yet). There are three endpoints currently supported:
<details><summary>Gradle Kotlin</summary>

```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);
```kotlin
implementation("com.graqr:threshr:0.0.13")
```
</details>

___
> [!NOTE]
> See the [testing README] for more information about all the needed environment variables, as well as tips and best practices.

### Want to get involved?

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!
See our [contributing] doc before taking a whack at any [open issues]. Also be sure to read the [testing README] for some tips and tricks. We'd love for you to work with us!

<!--top bar-->
[Bugs]:https://sonarcloud.io/api/project_badges/measure?project=Graqr_Threshr&metric=bugs
Expand Down Expand Up @@ -144,3 +120,7 @@ See our [contributing] doc before taking a whack at any [open issues]. Also be s

<!--All the other links-->
[these instructions]:https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry
[testing README]:src\test\groovy\com\graqr\threshr\README.md
[maven central]:https://central.sonatype.com/artifact/com.graqr/threshr/overview
[threshr cli]:https://github.com/Graqr/threshr-cli
[harvester]:https://github.com/Graqr/Harvester
12 changes: 9 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.graqr</groupId>
<artifactId>threshr</artifactId>
<version>0.0.12</version>
<version>0.0.13</version>
<packaging>${packaging}</packaging>

<parent>
<groupId>io.micronaut.platform</groupId>
<artifactId>micronaut-parent</artifactId>
<version>4.4.1</version>
<version>4.5.0</version>
</parent>

<properties>
<packaging>jar</packaging>
<jdk.version>17</jdk.version>
<release.version>17</release.version>
<micronaut.version>4.2.0</micronaut.version>
<micronaut.version>4.5.0</micronaut.version>
<owner>graqr</owner>
<sonar.organization>graqr</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
Expand Down Expand Up @@ -131,6 +131,12 @@
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>io.micronaut.maven</groupId>
<artifactId>micronaut-maven-plugin</artifactId>
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/com/graqr/threshr/Threshr.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,7 @@ public Store getStore(String storeId, String channel, Page page) throws ThreshrE
*/
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()));
throw new ThreshrException("response body is null or of an unexpected type.\n" + response);
}
return response.body();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ class ThreshrControllerSpec extends ThreshrSpec {
sql = Sql.newInstance(url)
}

// https://github.com/Graqr/Threshr/issues/67
void "null-bodied response from redsky is handled gracefully"() {
when: "querying a non-existent tcin"
threshrController.fetchProductSummaries(targetStore, "imAFakeTcin")

then: "Threshr exception thrown"
thrown(ThreshrException)
}

void "query pdp for #tcinArg tcin strings"() {
when:
if (count == 1){
Expand Down
Loading