This repository was archived by the owner on May 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignals.java
More file actions
44 lines (37 loc) · 1.59 KB
/
Copy pathSignals.java
File metadata and controls
44 lines (37 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.fxdatapi;
import java.io.IOException;
import java.util.Optional;
import okhttp3.*;
import okhttp3.MediaType;
public class Signals {
private static final String BASE_URL = "https://fxdatapi.com/v1/signals";
private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
public static Optional<String> getAllSignals(String username) {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(BASE_URL + "?username=" + username)
.header("Accept", "application/json")
.header("Cookie", "user_type=member; username=" + username)
.build();
try (Response response = client.newCall(request).execute()) {
return Optional.ofNullable(response.body().string());
} catch (IOException e) {
e.printStackTrace();
return Optional.empty();
}
}
public static Optional<String> getSignalById(String username, String signalId) {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(BASE_URL + "/" + signalId + "?username=" + username)
.header("Accept", "application/json")
.header("Cookie", "user_type=member; username=" + username)
.build();
try (Response response = client.newCall(request).execute()) {
return Optional.ofNullable(response.body().string());
} catch (IOException e) {
e.printStackTrace();
return Optional.empty();
}
}
}