Last active
August 17, 2018 13:22
-
-
Save matheussales/c6b2f08fac2133aadc393f31d3ea0721 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.mmart.eadbox.model.api | |
import com.example.mmart.eadbox.model.Course | |
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory | |
import io.reactivex.Observable | |
import okhttp3.OkHttpClient | |
import okhttp3.logging.HttpLoggingInterceptor | |
import retrofit2.Retrofit | |
import retrofit2.converter.gson.GsonConverterFactory | |
class EadBoxApi { | |
private val eadBoxService : EadBoxService | |
init { | |
val logging = HttpLoggingInterceptor() | |
logging.level = HttpLoggingInterceptor.Level.BODY | |
val httpClient = OkHttpClient.Builder() | |
httpClient.addInterceptor(logging) | |
val retrofit = Retrofit.Builder() | |
.baseUrl("http://matheus-martins.eadbox.com/api/") | |
.addCallAdapterFactory(RxJava2CallAdapterFactory.create()) | |
.addConverterFactory(GsonConverterFactory.create()) | |
.client(httpClient.build()) | |
.build() | |
eadBoxService = retrofit.create<EadBoxService>(EadBoxService::class.java) | |
} | |
fun loadCourses(): Observable<Course>? { | |
return eadBoxService.listCourses() | |
.flatMap{ courses -> Observable.fromIterable(courses)} | |
.map { course -> Course(course.title, course.category, course.workload, course.logo, course.lectures) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment