Skip to content

Commit

Permalink
accept-languageをプロパティファイルで指定できるようにする
Browse files Browse the repository at this point in the history
  • Loading branch information
cxxxr committed May 22, 2024
1 parent b5f6e05 commit ed5de9a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/main/java/jp/pokepay/partnerapi/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Config {
public String baseUrl;
public String p12File;
public String p12Password;
public String acceptLanguage;

public Config(File file) throws ConfigFileNotFoundException, ProcessingError {
Properties properties = new Properties();
Expand All @@ -29,5 +30,6 @@ public Config(File file) throws ConfigFileNotFoundException, ProcessingError {
this.baseUrl = properties.getProperty("API_BASE_URL");
this.p12File = file.toPath().getParent().resolve(properties.getProperty("PKCS12_FILE")).toString();
this.p12Password = properties.getProperty("PKCS12_PASSWORD");
this.acceptLanguage = properties.getProperty("ACCEPT-LANGUAGE", "jp");
}
}
4 changes: 2 additions & 2 deletions src/main/java/jp/pokepay/partnerapi/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public Response get(String path, String body) throws ProcessingError, Connection
}
}

public Response post(String path, String body) throws ProcessingError, ConnectionError {
public Response post(String path, String body, String acceptLanguage) throws ProcessingError, ConnectionError {
URL url = ensureURL(path);
try {
HttpURLConnection conn = openConnection(url);
Expand All @@ -137,7 +137,7 @@ public Response post(String path, String body) throws ProcessingError, Connectio
conn.setRequestProperty("accept", "*/*");
if (body != null) {
conn.setDoOutput(true);
conn.setRequestProperty("Accept-Language", "jp");
conn.setRequestProperty("Accept-Language", acceptLanguage);
conn.setRequestProperty("Content-Type", "application/json; charset=utf-8");
conn.setRequestProperty("Content-Length", String.valueOf(body.length()));
OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/jp/pokepay/partnerapi/PartnerAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public String encodeRequest(Request request) throws ProcessingError {
}

public Response send(Request request) throws ProcessingError, ConnectionError, PartnerRequestError {
HttpClient.Response response = httpClient.post(request.path(), encodeRequest(request));
HttpClient.Response response = httpClient.post(request.path(), encodeRequest(request), config.acceptLanguage);
JsonResponse json = gson.fromJson(response.getBody(), JsonResponse.class);
if (json.responseData == null) {
ErrorResponse errorResponse = gson.fromJson(response.getBody(), ErrorResponse.class);
Expand Down

0 comments on commit ed5de9a

Please sign in to comment.