Skip to content

Commit

Permalink
no longer need to specify url when instantiating client (#5)
Browse files Browse the repository at this point in the history
* update RavenApiClient.java to use generated Environment

* update artifact version
  • Loading branch information
dsinghvi authored Nov 9, 2022
1 parent c41bc3c commit 522ddcc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ API documentation is available at <https://docs.ravenapp.dev/introduction>.
Add this dependency to your project's build file:

```groovy
implementation "dev.ravenapp:raven-java:0.0.24"
implementation "dev.ravenapp:raven-java:0.0.32"
```

### Maven users
Expand All @@ -25,14 +25,14 @@ Add this dependency to your project's POM:
<dependency>
<groupId>dev.ravenapp</groupId>
<artifactId>raven-java</artifactId>
<version>0.0.31</version>
<version>0.0.32</version>
</dependency>
```

## Usage

```java
RavenApiClient ravenApiClient = new RavenApiClient("api.ravenapp.dev", Authorization.of("AuthKey <auth>"));
RavenApiClient ravenApiClient = new RavenApiClient(Authorization.of("AuthKey <auth>"));
try {
var response = client.send(Send.Request.builder()
.appId("<app_id>")
Expand Down
3 changes: 1 addition & 2 deletions sample-app/src/main/java/sample/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public static void main(String[] args) {
String authKey = System.getenv("RAVEN_TOKEN");
Authorization auth = Authorization.of(authKey);

RavenApiClient ravenApiClient =
new RavenApiClient("api.ravenapp.dev", auth);
RavenApiClient ravenApiClient = new RavenApiClient(auth);

try {
Device device = ravenApiClient.device().add(Add.Request.builder()
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/com/raven/api/RavenApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.raven.api.client.event.exceptions.SendException;
import com.raven.api.client.event.types.SendEventResponse;
import com.raven.api.client.user.UserServiceClient;
import com.raven.api.core.Environment;
import java.lang.String;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
Expand All @@ -21,16 +22,14 @@ public final class RavenApiClient {

private final Supplier<UserServiceClient> userServiceClient;

public RavenApiClient(String url) {
this.userServiceClient = memoize(() -> new UserServiceClient(url));
this.eventServiceClient = memoize(() -> new EventServiceClient(url));
this.deviceServiceClient = memoize(() -> new DeviceServiceClient(url));
public RavenApiClient(Authorization auth) {
this(Environment.PROD, auth);
}

public RavenApiClient(String url, Authorization auth) {
this.userServiceClient = memoize(() -> new UserServiceClient(url, auth));
this.eventServiceClient = memoize(() -> new EventServiceClient(url, auth));
this.deviceServiceClient = memoize(() -> new DeviceServiceClient(url, auth));
public RavenApiClient(Environment environment, Authorization auth) {
this.userServiceClient = memoize(() -> new UserServiceClient(environment.getUrl(), auth));
this.eventServiceClient = memoize(() -> new EventServiceClient(environment.getUrl(), auth));
this.deviceServiceClient = memoize(() -> new DeviceServiceClient(environment.getUrl(), auth));
}

public final DeviceServiceClient device() {
Expand Down

0 comments on commit 522ddcc

Please sign in to comment.