Skip to content

Commit

Permalink
Merge pull request #44 from pokepay/allow-accept-language-to-be-speci…
Browse files Browse the repository at this point in the history
…fied

accept-languageをプロパティファイルで指定できるようにする
  • Loading branch information
cxxxr authored May 22, 2024
2 parents a140643 + cf88b7c commit 691ddf4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions sample.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ API_BASE_URL = https://partnerapi-sandbox.pokepay.jp

PKCS12_FILE = certkey.p12
PKCS12_PASSWORD = changeit

ACCEPT-LANGUAGE = en

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", "en");
}
}
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 691ddf4

Please sign in to comment.