Skip to content

Commit

Permalink
Fixed an error, upgraded to 1.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Idan Harel committed Jan 17, 2017
1 parent c969455 commit b566182
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 27 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This library is released on [maven central](http://central.maven.org/maven2/com/
### Gradle

```
compile group: 'com.viber', name: 'viber-bot', version: '1.0.6'
compile group: 'com.viber', name: 'viber-bot', version: '1.0.7'
```

### Maven
Expand All @@ -25,7 +25,7 @@ compile group: 'com.viber', name: 'viber-bot', version: '1.0.6'
<dependency>
<groupId>com.viber</groupId>
<artifactId>viber-bot</artifactId>
<version>1.0.6</version>
<version>1.0.7</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion nano-httpd-sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repositories {
}

dependencies {
compile group: 'com.viber', name: 'viber-bot', version: '1.0.6'
compile group: 'com.viber', name: 'viber-bot', version: '1.0.7'
compile group: 'org.nanohttpd', name: 'nanohttpd', version: '2.3.1'
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.21'
}
2 changes: 1 addition & 1 deletion spring-boot-sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repositories {
}

dependencies {
compile group: 'com.viber', name: 'viber-bot', version: '1.0.6'
compile group: 'com.viber', name: 'viber-bot', version: '1.0.7'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.4.2.RELEASE'
compile group: 'javax.inject', name: 'javax.inject', version: '1'
}
15 changes: 2 additions & 13 deletions src/main/java/com/viber/bot/api/ViberClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ViberClient {
static final String VIBER_AUTH_TOKEN_HEADER = "X-Viber-Auth-Token";
static final String USER_AGENT_HEADER_FIELD = "User-Agent";
static final String USER_AGENT_HEADER_VALUE = "ViberBot-Java/";
static final String VIBER_LIBRARY_VERSION = "1.0.7";

private static final String STATUS = "status";
private static final int MAX_GET_ONLINE_IDS = 100;
Expand All @@ -51,7 +52,7 @@ class ViberClient {
ViberClient(final @Nonnull String apiUrl, final @Nonnull String authToken) {
this.apiUrl = checkNotEmpty(apiUrl);
this.authToken = checkNotEmpty(authToken);
this.userAgent = String.format("%s%s", USER_AGENT_HEADER_VALUE, fetchUserAgentVersion());
this.userAgent = String.format("%s%s", USER_AGENT_HEADER_VALUE, VIBER_LIBRARY_VERSION);
}

ListenableFuture<ApiResponse> setWebhook(final @Nullable String url, final @Nonnull Collection<Event> events) {
Expand Down Expand Up @@ -84,18 +85,6 @@ ListenableFuture<ApiResponse> getOnlineStatus(final @Nonnull Collection<String>
}});
}

@VisibleForTesting
String fetchUserAgentVersion() {
Properties properties = new Properties();
try {
properties.load(getClass().getClassLoader().getResourceAsStream("./version.properties"));
return properties.getProperty("version");
} catch (Exception e) {
logger.error("Could not fetch user agent", e);
return "unknown";
}
}

@VisibleForTesting
Request createRequest(@Nonnull Endpoint endpoint, RequestBody body) {
return new Request.Builder()
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/viber/bot/message/MessageKeyboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
public class MessageKeyboard extends ForwardingMap<String, Object> {
private final Map<String, Object> map;

MessageKeyboard(final @Nullable Map<String, Object> delegate) {
public MessageKeyboard(final @Nullable Map<String, Object> delegate) {
this.map = Collections.unmodifiableMap(MoreObjects.firstNonNull(delegate, Collections.emptyMap()));
}

MessageKeyboard() {
public MessageKeyboard() {
this(null);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/viber/bot/message/TrackingData.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
public class TrackingData extends ForwardingMap<String, Object> {
private final Map<String, Object> map;

TrackingData(final @Nullable Map<String, Object> delegate) {
public TrackingData(final @Nullable Map<String, Object> delegate) {
this.map = Collections.unmodifiableMap(MoreObjects.firstNonNull(delegate, Collections.emptyMap()));
}

TrackingData() {
public TrackingData() {
this(null);
}

Expand Down
7 changes: 1 addition & 6 deletions src/test/java/com/viber/bot/api/ViberClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ public class ViberClientTest {
private static final ViberClient client = new ViberClient("http://url.com", "TOKEN");
private static final RequestBody EMPTY_REQUEST_BODY = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), "");

@Test
public void testFetchUserAgentSanity() {
assertThat(client.fetchUserAgentVersion()).isNotEmpty();
}

@Test
public void testCreateRequestAuthTokenExistsSanity() {
Request request = client.createRequest(ViberClient.Endpoint.SEND_MESSAGE, EMPTY_REQUEST_BODY);
Expand All @@ -29,6 +24,6 @@ public void testCreateRequestUserAgentExistsSanity() {
Request request = client.createRequest(ViberClient.Endpoint.SEND_MESSAGE, EMPTY_REQUEST_BODY);
assertThat(request.headers().get(ViberClient.USER_AGENT_HEADER_FIELD)).isNotEmpty();
assertThat(request.headers().get(ViberClient.USER_AGENT_HEADER_FIELD))
.isEqualTo(String.format("%s%s", ViberClient.USER_AGENT_HEADER_VALUE, client.fetchUserAgentVersion()));
.isEqualTo(String.format("%s%s", ViberClient.USER_AGENT_HEADER_VALUE, ViberClient.VIBER_LIBRARY_VERSION));
}
}

0 comments on commit b566182

Please sign in to comment.