-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRetrofitService.kt
More file actions
51 lines (28 loc) · 1.08 KB
/
RetrofitService.kt
File metadata and controls
51 lines (28 loc) · 1.08 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
45
46
47
48
49
50
51
package com.example.myapplication
import com.example.myapplication.models.Model
import retrofit2.Call
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.GET
//Interface which will communicate with Retorfit instance
const val apikey = "95b6d8836ab74b2386fe24441682c94f"
interface RetrofitService {
@GET("v2/top-headlines?country=in&category=business&apiKey=$apikey")
suspend fun get() :Response<Model>
companion object {
//
var retrofitService: RetrofitService? = null
//this function will retrun the instance of Retrofit inferface
fun getInstance() : RetrofitService {
if (retrofitService == null) {
val retrofit = Retrofit.Builder()
.baseUrl("https://newsapi.org/")
.addConverterFactory(GsonConverterFactory.create())
.build()
retrofitService = retrofit.create(RetrofitService::class.java)
}
return retrofitService!!
}
}
}