ServiceManager

ServiceManager

Class Initialize

การเริ่มต้นใช้งาน จะต้องประกาศ object ของคลาสตามตัวอย่าง

ServiceManager(val context: Context , private val apiInstance: ApiInterface)
NameDescriptionTypeVariable Type
contextcontext ของ Fragment หรือ Activity ที่จะใช้Contextval
apiInstanceapiInterface ที่ใช้เรียก Service เช่น RetrofitApiInterfaceprivate val

Method Overview

NameDescriptionReturn
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 ServiceSingle< 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 AuthenUnit

Method Details

fun callServiceGet() : Single<JsonObject>

การสร้าง Get Request และเรียก Web Service โดยสามารถระบุ Service Url ได้

Returns

TypeDescription
Single< JsonObject >Return Single เพื่อรอการ subscribe
fun callServicePostBody(postUrl: String = "", body: HashMap<String, Any> , authentication: String = ""): Single<JsonObject>

การสร้าง Post Request และเรียก Web Service และส่ง body ได้

Parameters

NameDescriptionTypeDefault
postUrlPost Url ที่ต่อ จาก path Base Url ที่ต้องการString“”
bodybody ที่ต้องการจะแนบไปกับการยิง Request เช่น paramsHashMap< String, Any >
authenticationauthen header ที่จะแนบไปกับ Request เช่น tokenString“”

Returns

TypeDescription
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

NameDescriptionTypeDefault
postUrlPost Url ที่ต่อ จาก path Base Url ที่ต้องการString“”
bodybody ที่ต้องการจะแนบไปกับการยิง Request เช่น paramsHashMap< String, Any >
headerheader ที่จะแนบไปกับ RequestHashMap< String,String >hashMapOf()

Returns

TypeDescription
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

NameDescriptionTypeDefault
postUrlPost Url ที่ต่อ จาก path Base Url ที่ต้องการString“”
bodybody ที่ต้องการจะแนบไปกับการยิง Request เช่น paramsHashMap< String, RequestBody >
authenticationauthen header ที่จะแนบไปกับ Request เช่น tokenString“”

Returns

TypeDescription
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

NameDescriptionTypeDefault
postUrlPost Url ที่ต่อ จาก path Base Url ที่ต้องการString“”
bodybody ที่ต้องการจะแนบไปกับการยิง Request เช่น paramsHashMap< String, RequestBody >
headerheader ที่จะแนบไปกับ RequestHashMap< String,String >hashMapOf()

Returns

TypeDescription
Single< JsonObject >Return Single เพื่อรอการ subscribe
fun callServicePost(postUrl: String = "", header: HashMap<String, String> = hashMapOf()): Single<JsonObject>

การสร้าง Post Request และเรียก Web Service

Parameters

NameDescriptionTypeDefault
postUrlPost Url ที่ต่อ จาก path Base Url ที่ต้องการString“”
headerheader ที่จะแนบไปกับ RequestHashMap< String,String >hashMapOf()

Returns

TypeDescription
Single< JsonObject >Return Single เพื่อรอการ subscribe
fun callServicePost(postUrl: String = "" , authentication: String = ""): Single<JsonObject>

การสร้าง Post Request และเรียก Web Service

Parameters

NameDescriptionTypeDefault
postUrlPost Url ที่ต่อ จาก path Base Url ที่ต้องการString“”
authenticationauthen header ที่จะแนบไปกับ Request เช่น tokenString“”

Returns

TypeDescription
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

NameDescriptionTypeDefault
postUrlPost Url ที่ต่อ จาก path Base Url ที่ต้องการString
fileข้อมูลไฟล์ที่ต้องการส่งไปยัง Web ServiceArray< MultipartBody.Part? >
headerheader ที่จะแนบไปกับ RequestHashMap< String,String >hashMapOf()

Returns

TypeDescription
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

NameDescriptionTypeDefault
postUrlPost Url ที่ต่อ จาก path Base Url ที่ต้องการString
fileข้อมูลไฟล์ที่ต้องการส่งไปยัง Web ServiceArray< MultipartBody.Part >
bodybody ที่จะแนบไปกับ RequestHashMap< String,RequestBody >
authenticationauthen header ที่จะแนบไปกับ RequestString“”

Returns

TypeDescription
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

NameDescriptionTypeDefault
postUrlPost Url ที่ต่อ จาก path Base Url ที่ต้องการString
fileข้อมูลไฟล์ที่ต้องการส่งไปยัง Web ServiceMultipartBody.Part
bodybody ที่จะแนบไปกับ RequestHashMap< String,RequestBody >
authenticationauthen header ที่จะแนบไปกับ RequestString“”

Returns

TypeDescription
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

NameDescriptionTypeDefault
postUrlPost Url ที่ต่อ จาก path Base Url ที่ต้องการString
fileข้อมูลไฟล์ที่ต้องการส่งไปยัง Web ServiceArray< MultipartBody.Part >
bodybody ที่จะแนบไปกับ RequestHashMap< String,RequestBody >
headerheader ที่จะแนบไปกับ RequestHashMap< String,String >hashMapOf()

Returns

TypeDescription
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

NameDescriptionTypeDefault
postUrlPost Url ที่ต่อ จาก path Base Url ที่ต้องการString
fileข้อมูลไฟล์ที่ต้องการส่งไปยัง Web ServiceMultipartBody.Part
bodybody ที่จะแนบไปกับ RequestHashMap< String,RequestBody >
headerheader ที่จะแนบไปกับ RequestHashMap< String,String >hashMapOf()

Returns

TypeDescription
Single< JsonObject >Return Single เพื่อรอการ subscribe
fun login(username: String, 
          password: String, 
          callback:(response: JsonObject? , error: Exception?) -> Unit)

การสร้าง Request และเรียก Web Service สำหรับการเข้าสู่ระบบ

Parameters

NameDescriptionTypeDefault
usernamePost Url ที่ต่อ จาก path Base Url ที่ต้องการString
passwordข้อมูลไฟล์ที่ต้องการส่งไปยัง Web ServiceString
callbackcallback ถ้า reponse ไม่เป็น null แสดงว่า login สำเร็จ แต่ถ้า error ไม่เป็น null แสดงว่า login ไม่สำเร็จUnit

Returns

TypeDescription
Single< JsonObject >Return Single เพื่อรอการ subscribe
fun login(callback:(response: JsonObject? , error: Exception?) -> Unit)

การสร้าง Request และเรียก Web Service สำหรับการขอ Token จาก App Authen

Parameters

NameDescriptionTypeDefault
callbackcallback ถ้า reponse ไม่เป็น null แสดงว่าขอ token ใหม่สำเร็จ แต่ถ้า error ไม่เป็น null แสดงว่าขอ token ใหม่ไม่สำเร็จUnit

Returns

TypeDescription
Single< JsonObject >Return Single เพื่อรอการ subscribe