title: Kotlin API call using Retrofit
body: <p>I'm new to Kotlin, Android and OOP in general (Natural-ADABAS background, never did Java, C++, etc) so I'm pretty desperate.</p>
  
  <p>I have an API whose data looks like this, an array of book details:</p>
  
  <p><strong>API data sample</strong></p>
  
  <p><a href="https://i.stack.imgur.com/wIkLA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wIkLA.png" alt="enter image description here"></a></p>
  
  <p>I'm confused about data models. I know it's supposed to look like how the data in the API and return an array but how exactly do I code it in Kotlin? And then how do I parse it? I've read some tutorials but they all differ. Some use an object, and some use a class.</p>
  
  <p>I'm also probably breaking some standard by putting everything in the main activity but I haven't gotten to that part yet.</p>
  
  <pre><code>import android.support.v7.app.AppCompatActivity
  import android.os.Bundle
  import retrofit2.Call
  import retrofit2.Retrofit
  import retrofit2.converter.moshi.MoshiConverterFactory
  import retrofit2.http.GET
  import retrofit2.http.Query
  
  class MainActivity : AppCompatActivity()
  
   {
  
  private val api: RestAPI = RestAPI()
  
  override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      setContentView(R.layout.activity_main)
  
  
      val apiGetBooks = api.getBooksList("token123123123")
      val response = apiGetBooks.execute()
  
  
      if (response.isSuccessful) {
          val books = response.body()?.title
          println(books)
  
      } else {
          println("error on API") // What do I do?
      }
  
  }
  
  object  Model {
      val ResultArray : MutableList&lt;BookProperties&gt;? = null
  }
  
  data class BookProperties (val id: Int,val title: String, val coverURI: String, val pageURI: String, val pageCount: Int, val languageId: Int,val  description: String, val isFree: Boolean) {
  }
  
  private val buriApi: MainActivity.BooksAPI? = null
  
  class RestAPI {
      private val buriApi: BooksAPI
  
      init {
          val retrofit = Retrofit.Builder()
                  .baseUrl("https://api.someurl.com")
                  .addConverterFactory(MoshiConverterFactory.create())
                  .build()
  
          buriApi = retrofit.create(BooksAPI::class.java)
      }
  
      fun getBooksList(token: String): Call&lt;BookProperties&gt;{
          return buriApi.getBooks(token)
      }
  }
  
  fun getBooksList(token: String): Call&lt;MainActivity.BookProperties&gt; {
      return buriApi!!.getBooks(token)
  }
  
  interface  BooksAPI {
      @GET("/v1/books")
      fun getBooks (@Query("token")token: String) : Call&lt;BookProperties&gt;
  }
  }
  </code></pre>