Skip to content

Commit

Permalink
Merge pull request #111 from VishalMCF/Add-User-Agent-Header
Browse files Browse the repository at this point in the history
Add user agent header
  • Loading branch information
Cliftonz authored Dec 29, 2023
2 parents cf05809 + 933bc2b commit 5abd545
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,11 @@
<artifactId>okhttp</artifactId>
<version>4.10.0</version>
</dependency>
</dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.maven/maven-model -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>3.9.6</version>
</dependency>
</dependencies>
</project>
22 changes: 20 additions & 2 deletions src/main/java/co/novu/common/base/NovuConfig.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
package co.novu.common.base;

import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;

import java.io.FileReader;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class NovuConfig {

private String apiKey;
private String baseUrl = "https://api.novu.co/v1/";
private String sdkName;
private String sdkVersion;
public NovuConfig(String apiKey) {
this.apiKey = apiKey;
loadContextFromPom();
}

private String apiKey;
private String baseUrl = "https://api.novu.co/v1/";
private void loadContextFromPom(){
try {
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model = reader.read(new FileReader("pom.xml"));
this.sdkName = model.getArtifactId();
this.sdkVersion = model.getVersion();
} catch (Exception e) {
e.printStackTrace();
}
}
}
1 change: 1 addition & 0 deletions src/main/java/co/novu/common/rest/RestHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public Retrofit buildRetrofit() {
Request request = chain.request()
.newBuilder()
.addHeader("Authorization", "ApiKey " + novuConfig.getApiKey())
.addHeader("User-Agent", "novu/" + novuConfig.getSdkName() + "@" + novuConfig.getSdkVersion())
.build();
return chain.proceed(request);
}).addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BASIC));
Expand Down

0 comments on commit 5abd545

Please sign in to comment.