ServiceManager
Class Initialize
การเริ่มต้นใช้งาน จะต้องประกาศ object ของคลาสตามตัวอย่าง
ServiceManager(val context: Context , private val apiInstance: ApiInterface)
| Name | Description | Type | Variable Type |
|---|
| context | context ของ Fragment หรือ Activity ที่จะใช้ | Context | val |
| apiInstance | apiInterface ที่ใช้เรียก Service เช่น Retrofit | ApiInterface | private val |
Method Overview
| Name | Description | Return |
|---|
| callServiceGet() | การสร้าง Get Request และเรียก Web Service โดยสามารถระบุ Service Url ได้ | Single< JsonObject > |
| callServicePostBody() | การสร้าง Post Request และเรียก Web Service และส่ง body ได้ | Single< JsonObject > |
| callServicePostPartMap() | การสร้าง Post Request และเรียก Web Service และส่ง body ที่เป็น Hasmap ที่มี value เป็น RequestBody ได้ | Single< JsonObject > |
| callServicePost() | การสร้าง Post Request และเรียก Web Service | Single< JsonObject > |
| callServiceToUploadFile() | การสร้าง Request และเรียก Web Service สำหรับการ Upload File ใช้กับการ Sync ได้ | Single< JsonObject > |
| callServiceToUploadFileWithBody() | การสร้าง Request และเรียก Web Service สำหรับการ Upload File ใช้กับการ Sync ได้ และสามารถส่ง body ไปได้ | Single< JsonObject > |
| login() | การสร้าง Request และเรียก Web Service สำหรับการเข้าสู่ระบบ | Unit |
| getRefreshToken() | การสร้าง Request และเรียก Web Service สำหรับการขอ Token จาก App Authen | Unit |
Method Details
fun callServiceGet() : Single<JsonObject>
การสร้าง Get Request และเรียก Web Service โดยสามารถระบุ Service Url ได้
Returns
| Type | Description |
|---|
| Single< JsonObject > | Return Single เพื่อรอการ subscribe |
fun callServicePostBody(postUrl: String = "", body: HashMap<String, Any> , authentication: String = ""): Single<JsonObject>
การสร้าง Post Request และเรียก Web Service และส่ง body ได้
Parameters
| Name | Description | Type | Default |
|---|
| postUrl | Post Url ที่ต่อ จาก path Base Url ที่ต้องการ | String | “” |
| body | body ที่ต้องการจะแนบไปกับการยิง Request เช่น params | HashMap< String, Any > | |
| authentication | authen header ที่จะแนบไปกับ Request เช่น token | String | “” |
Returns
| Type | Description |
|---|
| Single< JsonObject > | Return Single เพื่อรอการ subscribe |
fun callServicePostBody(postUrl: String = "", body: HashMap<String, Any> , header: HashMap<String,String> = hashMapOf()): Single<JsonObject>
การสร้าง Post Request และเรียก Web Service และส่ง body ได้
Parameters
| Name | Description | Type | Default |
|---|
| postUrl | Post Url ที่ต่อ จาก path Base Url ที่ต้องการ | String | “” |
| body | body ที่ต้องการจะแนบไปกับการยิง Request เช่น params | HashMap< String, Any > | |
| header | header ที่จะแนบไปกับ Request | HashMap< String,String > | hashMapOf() |
Returns
| Type | Description |
|---|
| Single< JsonObject > | Return Single เพื่อรอการ subscribe |
fun callServicePostPartMap(postUrl: String = "", body: HashMap<String, RequestBody> , authentication: String = ""): Single<JsonObject>
การสร้าง Post Request และเรียก Web Service และส่ง body ที่เป็น Hasmap ที่มี value เป็น RequestBody ได้
Parameters
| Name | Description | Type | Default |
|---|
| postUrl | Post Url ที่ต่อ จาก path Base Url ที่ต้องการ | String | “” |
| body | body ที่ต้องการจะแนบไปกับการยิง Request เช่น params | HashMap< String, RequestBody > | |
| authentication | authen header ที่จะแนบไปกับ Request เช่น token | String | “” |
Returns
| Type | Description |
|---|
| Single< JsonObject > | Return Single เพื่อรอการ subscribe |
fun callServicePostPartMap(postUrl: String = "", body: HashMap<String, RequestBody> , header: HashMap<String,String> = hashMapOf()): Single<JsonObject>
การสร้าง Post Request และเรียก Web Service และส่ง body ที่เป็น Hasmap ที่มี value เป็น RequestBody ได้
Parameters
| Name | Description | Type | Default |
|---|
| postUrl | Post Url ที่ต่อ จาก path Base Url ที่ต้องการ | String | “” |
| body | body ที่ต้องการจะแนบไปกับการยิง Request เช่น params | HashMap< String, RequestBody > | |
| header | header ที่จะแนบไปกับ Request | HashMap< String,String > | hashMapOf() |
Returns
| Type | Description |
|---|
| Single< JsonObject > | Return Single เพื่อรอการ subscribe |
fun callServicePost(postUrl: String = "", header: HashMap<String, String> = hashMapOf()): Single<JsonObject>
การสร้าง Post Request และเรียก Web Service
Parameters
| Name | Description | Type | Default |
|---|
| postUrl | Post Url ที่ต่อ จาก path Base Url ที่ต้องการ | String | “” |
| header | header ที่จะแนบไปกับ Request | HashMap< String,String > | hashMapOf() |
Returns
| Type | Description |
|---|
| Single< JsonObject > | Return Single เพื่อรอการ subscribe |
fun callServicePost(postUrl: String = "" , authentication: String = ""): Single<JsonObject>
การสร้าง Post Request และเรียก Web Service
Parameters
| Name | Description | Type | Default |
|---|
| postUrl | Post Url ที่ต่อ จาก path Base Url ที่ต้องการ | String | “” |
| authentication | authen header ที่จะแนบไปกับ Request เช่น token | String | “” |
Returns
| Type | Description |
|---|
| Single< JsonObject > | Return Single เพื่อรอการ subscribe |
fun callServiceToUploadFile(postUrl: String,
file: Array<MultipartBody.Part?>,
header: HashMap<String,String> = hashMapOf()): Single<JsonObject>
การสร้าง Post Request และเรียก Web Service
Parameters
| Name | Description | Type | Default |
|---|
| postUrl | Post Url ที่ต่อ จาก path Base Url ที่ต้องการ | String | |
| file | ข้อมูลไฟล์ที่ต้องการส่งไปยัง Web Service | Array< MultipartBody.Part? > | |
| header | header ที่จะแนบไปกับ Request | HashMap< String,String > | hashMapOf() |
Returns
| Type | Description |
|---|
| Single< JsonObject > | Return Single เพื่อรอการ subscribe |
fun callServiceToUploadFileWithBody(postUrl: String ,
file: Array<MultipartBody.Part> ,
body: HashMap<String, RequestBody> ,
authentication: String = ""): Single<JsonObject>
การสร้าง Request และเรียก Web Service สำหรับการ Upload File ใช้กับการ Sync ได้ และสามารถส่ง body ไปได้
Parameters
| Name | Description | Type | Default |
|---|
| postUrl | Post Url ที่ต่อ จาก path Base Url ที่ต้องการ | String | |
| file | ข้อมูลไฟล์ที่ต้องการส่งไปยัง Web Service | Array< MultipartBody.Part > | |
| body | body ที่จะแนบไปกับ Request | HashMap< String,RequestBody > | |
| authentication | authen header ที่จะแนบไปกับ Request | String | “” |
Returns
| Type | Description |
|---|
| Single< JsonObject > | Return Single เพื่อรอการ subscribe |
fun callServiceToUploadFileWithBody(postUrl: String ,
file: MultipartBody.Part ,
body: HashMap<String, RequestBody> ,
authentication: String = ""): Single<JsonObject>
การสร้าง Request และเรียก Web Service สำหรับการ Upload File ใช้กับการ Sync ได้ และสามารถส่ง body ไปได้
Parameters
| Name | Description | Type | Default |
|---|
| postUrl | Post Url ที่ต่อ จาก path Base Url ที่ต้องการ | String | |
| file | ข้อมูลไฟล์ที่ต้องการส่งไปยัง Web Service | MultipartBody.Part | |
| body | body ที่จะแนบไปกับ Request | HashMap< String,RequestBody > | |
| authentication | authen header ที่จะแนบไปกับ Request | String | “” |
Returns
| Type | Description |
|---|
| Single< JsonObject > | Return Single เพื่อรอการ subscribe |
fun callServiceToUploadFileWithBody(postUrl: String ,
file: Array<MultipartBody.Part> ,
body: HashMap<String, RequestBody> ,
header: HashMap<String,String> = hashMapOf()): Single<JsonObject>
การสร้าง Request และเรียก Web Service สำหรับการ Upload File ใช้กับการ Sync ได้ และสามารถส่ง body ไปได้
Parameters
| Name | Description | Type | Default |
|---|
| postUrl | Post Url ที่ต่อ จาก path Base Url ที่ต้องการ | String | |
| file | ข้อมูลไฟล์ที่ต้องการส่งไปยัง Web Service | Array< MultipartBody.Part > | |
| body | body ที่จะแนบไปกับ Request | HashMap< String,RequestBody > | |
| header | header ที่จะแนบไปกับ Request | HashMap< String,String > | hashMapOf() |
Returns
| Type | Description |
|---|
| Single< JsonObject > | Return Single เพื่อรอการ subscribe |
fun callServiceToUploadFileWithBody(postUrl: String ,
file: MultipartBody.Part ,
body: HashMap<String, RequestBody> ,
header: HashMap<String,String> = hashMapOf()): Single<JsonObject>
การสร้าง Request และเรียก Web Service สำหรับการ Upload File ใช้กับการ Sync ได้ และสามารถส่ง body ไปได้
Parameters
| Name | Description | Type | Default |
|---|
| postUrl | Post Url ที่ต่อ จาก path Base Url ที่ต้องการ | String | |
| file | ข้อมูลไฟล์ที่ต้องการส่งไปยัง Web Service | MultipartBody.Part | |
| body | body ที่จะแนบไปกับ Request | HashMap< String,RequestBody > | |
| header | header ที่จะแนบไปกับ Request | HashMap< String,String > | hashMapOf() |
Returns
| Type | Description |
|---|
| Single< JsonObject > | Return Single เพื่อรอการ subscribe |
fun login(username: String,
password: String,
callback:(response: JsonObject? , error: Exception?) -> Unit)
การสร้าง Request และเรียก Web Service สำหรับการเข้าสู่ระบบ
Parameters
| Name | Description | Type | Default |
|---|
| username | Post Url ที่ต่อ จาก path Base Url ที่ต้องการ | String | |
| password | ข้อมูลไฟล์ที่ต้องการส่งไปยัง Web Service | String | |
| callback | callback ถ้า reponse ไม่เป็น null แสดงว่า login สำเร็จ แต่ถ้า error ไม่เป็น null แสดงว่า login ไม่สำเร็จ | Unit | |
Returns
| Type | Description |
|---|
| Single< JsonObject > | Return Single เพื่อรอการ subscribe |
fun login(callback:(response: JsonObject? , error: Exception?) -> Unit)
การสร้าง Request และเรียก Web Service สำหรับการขอ Token จาก App Authen
Parameters
| Name | Description | Type | Default |
|---|
| callback | callback ถ้า reponse ไม่เป็น null แสดงว่าขอ token ใหม่สำเร็จ แต่ถ้า error ไม่เป็น null แสดงว่าขอ token ใหม่ไม่สำเร็จ | Unit | |
Returns
| Type | Description |
|---|
| Single< JsonObject > | Return Single เพื่อรอการ subscribe |