Skip to content
This repository was archived by the owner on Apr 28, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions src/main/java/org/jinstagram/Instagram.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,25 +136,36 @@ protected OAuthRequest request(Verbs verb, String methodName, String rawMethodNa
// Add the AccessToken to the Request Url
if ((verb == Verbs.GET) || (verb == Verbs.DELETE)) {
if (accessToken == null) {
logger.debug(USING + OAuthConstants.CLIENT_ID + " : " + clientId);
logger.debug("{}{}:{}",USING, OAuthConstants.CLIENT_ID, clientId);
result.addQuerystringParameter(OAuthConstants.CLIENT_ID, clientId);
} else {
logger.debug(USING + OAuthConstants.ACCESS_TOKEN + " : " + accessToken.getToken());
logger.debug("{}{}:{}",USING,OAuthConstants.ACCESS_TOKEN, accessToken.getToken());
result.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getToken());
}
} else {
if (accessToken == null) {
logger.debug(USING + OAuthConstants.CLIENT_ID + " : " + clientId);
logger.debug("{}{}:{}", USING,OAuthConstants.CLIENT_ID, clientId);
result.addBodyParameter(OAuthConstants.CLIENT_ID, clientId);
} else {
logger.debug(USING + OAuthConstants.ACCESS_TOKEN + " : " + accessToken.getToken());
logger.debug("{}{}:{}", USING, OAuthConstants.ACCESS_TOKEN, accessToken.getToken());
result.addBodyParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getToken());
}
}

// check if we are enforcing a signed request and add the 'sig'
// parameter. Must use rawMethodName here (i.e. sign the non-URI-encoded version).
if (config.isEnforceSignedRequest()) {
return checkIfEnforcing(result, verb, rawMethodName);
}

/**
* Check if we are enforcing a signed request and add the 'sig'
* parameter. Must use rawMethodName here (i.e. sign the non-URI-encoded version).
* @param result
* @param verb
* @param rawMethodName
* @return
* @throws InstagramException
*/
private OAuthRequest checkIfEnforcing(OAuthRequest result, Verbs verb, String rawMethodName) throws InstagramException {
if (config.isEnforceSignedRequest()) {
boolean useQueryParam = (verb == Verbs.GET) || (verb == Verbs.DELETE);

Map<String,String> sigParams = useQueryParam ? result.getQueryStringParams() : result.getBodyParams();
Expand All @@ -168,8 +179,7 @@ protected OAuthRequest request(Verbs verb, String methodName, String rawMethodNa
result.addBodyParameter(QueryParam.SIGNATURE, sig);
}
}

return result;
return result;
}

@Deprecated
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/jinstagram/InstagramBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -996,8 +996,7 @@ else if (responseCode == 429) {
protected Response getApiResponse(Verbs verb, String methodName, String rawMethodName, Map<String, String> params) throws IOException {
Request request=request(verb, methodName, rawMethodName, params);
logger.debug("Sending request to Instagram...");
Response response=request.send();
return response;
return request.send();
}

protected Request request(Verbs verb, String methodName, String rawMethodName, Map<String, String> params) throws InstagramException {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jinstagram/http/APILimitUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private static int getIntegerValue(Map<String, String> header, String key) {
try {
value = Integer.valueOf(intValueStr);
} catch (NumberFormatException e) {
logger.error("Invalid Integer value for key: " + key + ", value :" + intValueStr);
logger.error("Invalid Integer value for key: {} , value : {}", key, intValueStr);
}
return value;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jinstagram/http/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ private void createConnection() throws IOException {
if (connection == null) {
System.setProperty("http.keepAlive", connectionKeepAlive ? "true" : "false");

URL url = new URL(effectiveUrl);
URL urlConnection = new URL(effectiveUrl);
connection = (HttpURLConnection) (proxy == null ?
url.openConnection() : url.openConnection(proxy));
urlConnection.openConnection() : urlConnection.openConnection(proxy));

connection.setConnectTimeout(connectTimeout);
connection.setReadTimeout(readTimeout);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jinstagram/http/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private Map<String, String> parseHeaders(HttpURLConnection conn) {
for (java.util.Map.Entry<String,List<String>> entry : conn.getHeaderFields().entrySet()) {
String key= entry.getKey();
List<String> valueList= entry.getValue();
if (key!=null && valueList!=null && valueList.size()>0) {
if (key!=null && valueList!=null && valueList.isEmpty()) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RobertLara "valueList.size()>0" seems to be the opposite of "valueList.isEmpty()".

Suggested change
if (key!=null && valueList!=null && valueList.isEmpty()) {
if (key!=null && valueList!=null && !valueList.isEmpty()) {

String value= valueList.get(0);
if (value!=null) {
headers.put(key, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.nio.charset.Charset;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.lang.NullPointerException;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
Expand Down