-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1f51c1
commit 4192a22
Showing
4 changed files
with
108 additions
and
4 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
src/main/java/com/gnip/core/endpoint/GnipStreamingEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.gnip.core.endpoint; | ||
|
||
import com.google.common.base.Joiner; | ||
import com.google.common.base.Preconditions; | ||
import com.google.common.collect.Maps; | ||
import com.twitter.hbc.core.HttpConstants; | ||
import com.twitter.hbc.core.endpoint.StreamingEndpoint; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentMap; | ||
|
||
public abstract class GnipStreamingEndpoint implements StreamingEndpoint { | ||
private static final String BASE_PATH = "/accounts/%s/publishers/%s/streams/%s/%s.json"; | ||
protected final String account; | ||
protected final String publisher; | ||
protected final String product; | ||
protected final String label; | ||
protected final ConcurrentMap<String, String> queryParameters = Maps.newConcurrentMap(); | ||
|
||
public GnipStreamingEndpoint(String account, String publisher, String product, String label) { | ||
this(account, publisher, product, label, 0); | ||
} | ||
|
||
public GnipStreamingEndpoint(String account, String publisher, String product, String label, int clientId) { | ||
this.account = Preconditions.checkNotNull(account); | ||
this.publisher = Preconditions.checkNotNull(publisher); | ||
this.product = Preconditions.checkNotNull(product); | ||
this.label = Preconditions.checkNotNull(label); | ||
|
||
if (clientId > 0) { | ||
addQueryParameter("client", String.valueOf(clientId)); | ||
} | ||
} | ||
|
||
@Override | ||
public String getURI() { | ||
String uri = String.format(BASE_PATH, account.trim(), publisher.trim(), product.trim(), label.trim()); | ||
|
||
if (queryParameters.isEmpty()) { | ||
return uri; | ||
} else { | ||
return uri + "?" + generateParamString(queryParameters); | ||
} | ||
} | ||
|
||
protected String generateParamString(Map<String, String> params) { | ||
return Joiner.on("&") | ||
.withKeyValueSeparator("=") | ||
.join(params); | ||
} | ||
|
||
@Override | ||
public String getHttpMethod() { | ||
return HttpConstants.HTTP_GET; | ||
} | ||
|
||
@Override | ||
public String getPostParamString() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getQueryParamString() { | ||
return generateParamString(queryParameters); | ||
} | ||
|
||
@Override | ||
public void addQueryParameter(String param, String value) { | ||
queryParameters.put(param, value); | ||
} | ||
|
||
@Override | ||
public void removeQueryParameter(String param) { | ||
queryParameters.remove(param); | ||
} | ||
|
||
// These don't do anything | ||
@Override | ||
public void setBackfillCount(int count) { } | ||
|
||
@Override | ||
public void setApiVersion(String apiVersion) { } | ||
|
||
@Override | ||
public void addPostParameter(String param, String value) { } | ||
|
||
@Override | ||
public void removePostParameter(String param) { } | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/gnip/core/endpoint/RealTimeGnipStreamingEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.gnip.core.endpoint; | ||
|
||
public class RealTimeGnipStreamingEndpoint extends GnipStreamingEndpoint { | ||
|
||
public RealTimeGnipStreamingEndpoint(String account, String publisher, String product, String label) { | ||
super(account, publisher, product, label); | ||
} | ||
|
||
public RealTimeGnipStreamingEndpoint(String account, String publisher, String product, String label, int clientId) { | ||
super(account, publisher, product, label, clientId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters