Skip to content

Commit fc8dddc

Browse files
committed
ApiUtils.kt: Add reporting functions to ApiUtils
1 parent f743504 commit fc8dddc

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

app/src/main/java/com/addev/listaspam/util/ApiUtils.kt

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,53 @@ object ApiUtils {
6868
}
6969
}
7070

71+
/**
72+
* Sends a POST report to the UnknownPhone API for a given phone number, marking it with a comment and metadata.
73+
*
74+
* This method constructs and sends a form-encoded POST request that includes the phone number, a comment,
75+
* call type, language, and optional metadata. It's used to report marketing or spam calls to the platform.
76+
*
77+
* @param phone The phone number being reported.
78+
* @param comment The user comment about the phone number.
79+
* @param lang The language code (e.g., "ES" for Spanish).
80+
* @param username Optional: The username of the person submitting the report.
81+
* @param phoneOwner Optional: A string indicating ownership or recipient identity.
82+
* @return `true` if the report was submitted successfully; `false` otherwise.
83+
*/
84+
fun reportToUnknownPhone(
85+
phone: String,
86+
comment: String,
87+
isSpam: Boolean,
88+
lang: String,
89+
): Boolean {
90+
val optRating = if (isSpam) "1" else "5"
91+
92+
val formBuilder = FormBody.Builder()
93+
.add("api_key", "d58d5bdaba8a80b2311957e9e4af885c")
94+
.add("phone", phone)
95+
.add("_action", "_submit_comment")
96+
.add("comment", comment)
97+
.add("lang", lang)
98+
.add("_opt_rating", optRating)
99+
100+
val request = Request.Builder()
101+
.url(UNKNOWN_PHONE_API_URL)
102+
.post(formBuilder.build())
103+
.header("Connection", "Keep-Alive")
104+
.header("Content-Type", "application/x-www-form-urlencoded")
105+
.header("Host", "secure.unknownphone.com")
106+
.header("User-Agent", "okhttp/3.14.9")
107+
.build()
108+
109+
return try {
110+
val response = client.newCall(request).execute()
111+
Log.d("com.addev.listaspam", response.toString())
112+
response.isSuccessful
113+
} catch (e: Exception) {
114+
false
115+
}
116+
}
117+
71118
fun checkTellowsSpamApi(number: String, country: String): Boolean {
72119
val url = HttpUrl.Builder()
73120
.scheme("https")
@@ -111,4 +158,60 @@ object ApiUtils {
111158
}
112159
}
113160

161+
/**
162+
* Sends a report to Tellows about a phone number, submitting a comment and associated metadata.
163+
*
164+
* This method builds a POST request to the Tellows API with form data including the phone number,
165+
* comment, complaint type, user type, and score.
166+
*
167+
* @param phone The phone number to report (without country code prefix, if already localized).
168+
* @param comment A description of the issue or behavior associated with the number.
169+
* @param complainTypeId Type of complaint, e.g. 5 = "estafa" (scam).
170+
* @param userScore The danger score (1 = safe, 9 = dangerous).
171+
* @param lang Language and country code, e.g. "es".
172+
* @return `true` if the report was accepted; `false` otherwise.
173+
*/
174+
fun reportToTellows(
175+
phone: String,
176+
comment: String,
177+
isSpam: Boolean,
178+
lang: String = "es",
179+
complainTypeId: Int = 5
180+
): Boolean {
181+
val userScore = if (isSpam) 9 else 1
182+
183+
val url = "https://www.tellows.de/basic/num/$phone" +
184+
"?xml=1&partner=androidapp&apikey=koE5hjkOwbHnmcADqZuqqq2" +
185+
"&createcomment=1&country=$lang&lang=$lang&user_auth=&user_email="
186+
187+
val formBody = FormBody.Builder()
188+
.add("caller", phone)
189+
.add("comment", comment)
190+
.add("complain_type_id", complainTypeId.toString())
191+
.add("user", "Android")
192+
.add("userscore", userScore.toString())
193+
.build()
194+
195+
val request = Request.Builder()
196+
.url(url)
197+
.post(formBody)
198+
.header("Accept-Encoding", "gzip")
199+
.header("Connection", "Keep-Alive")
200+
.header("Content-Type", "application/x-www-form-urlencoded")
201+
.header("Host", "www.tellows.de")
202+
.header("User-Agent", "Dalvik/2.1.0 (Linux; U; Android 6.0; I14 Pro Max Build/MRA58K)")
203+
.build()
204+
205+
return try {
206+
val response = client.newCall(request).execute()
207+
val responseBody = response.body?.string() ?: return false
208+
209+
// Check for success in JSON response
210+
val json = JSONObject(responseBody)
211+
json.optBoolean("success", false)
212+
} catch (e: Exception) {
213+
false
214+
}
215+
}
216+
114217
}

0 commit comments

Comments
 (0)