/goma

Primary LanguageKotlinApache License 2.0Apache-2.0

Android Kotlin Goma http protocol client Library

License: Apache-2.0

Supported methods

GET, POST, PUT, DELETE

Download and Import

Android Studio/Gradle

  • Maven:
   <repositories>
   	<repository>
   	    <id>jitpack.io</id>
   	    <url>https://jitpack.io</url>
   	</repository>
   </repositories>
   
   
   

   <dependency>
       <groupId>com.github.jkanTech</groupId>
       <artifactId>goma</artifactId>
       <version>1.0.3</version>
   </dependency>

  • JitPack.io, add jitpack.io repositiory and dependency to your build.gradle:
   repositories {
       maven {
           url "https://jitpack.io"
       }
   }
   
   dependencies {
           implementation 'com.github.jkantech:goma:1.0.3'
   	}

Android Studio

   repositories {
       maven {
           url "https://jitpack.io"
       }
   }
   
   dependencies {
           implementation 'com.github.jkantech:goma:1.0.3'
   	}

Manifests

    <uses-permission android:name="android.permission.INTERNET"/>

<application

        android:usesCleartextTraffic="true"

Sample Kotlin Usage

GET Method

 private fun getUsers(){
 // initialize Goma Library
 Goma.init(this,"http://192.168.8.101/api/v1")
 
         
 //GET Method ,path
   Goma.get("users", object : OnResponseListener {
     
           override fun onSuccess(response: String?) {
             
                   users=users.deserializer(response)
 
                 Toast.makeText(requireContext(), response.toString(), Toast.LENGTH_SHORT).show()
             }
            override fun onError(error: String?) {
                 Toast.makeText(requireContext(), error.toString(), Toast.LENGTH_SHORT).show()
             }
 
         })
 
 
 }

POST Method

private fun addUser(){
// initialize Goma Library + baseURL
Goma.init(this)

val parameters:HashMap<String, String> = HashMap()
        parameters.put("appKey","12345#")
        parameters.put("name","Jonas")
        parameters.put("title","Inform")
        parameters.put("age","18")

//POST Method ,path
  Goma.post("http://192.168.8.101/api/v1/add",parameters, object : OnResponseListener {
    
          override fun onSuccess(response: String?) {

                Toast.makeText(requireContext(), "Successfully added", Toast.LENGTH_SHORT).show()
            }
           override fun onError(error: String?) {
                Toast.makeText(requireContext(), error.toString(), Toast.LENGTH_SHORT).show()
            }

        })


}
    

PUT Method

private fun add(){

// initialize Goma Library 
  Goma.init(this)

 val parameters: HashMap<String, String> = HashMap()
        parameters["Appkey"] = "12345"
        parameters["name"] = "Bob"
        parameters["title"] = "Infor"
        parameters["age"] = "30"


        Goma.put("http://192.168.8.101/api/v1/adduser", parameters,object :OnResponseListener {
            override fun onSuccess(response: String?) {
        Toast.makeText(this, response.toString(), Toast.LENGTH_SHORT).show()

            }

            override fun onError(error: String?) {

        Toast.makeText(this, response.toString(), Toast.LENGTH_SHORT).show()

            }


        })
}

DELETE Method

private fun delUser(){
// initialize Goma Library
Goma.init(this)

val parameters:HashMap<String, String> = HashMap()
        parameters.put("appKey","12345#")
        parameters.put("id","4")

        
//DELETE Method ,URL
  Goma.del("http://192.168.43.128/api/delUser",parameters, object : OnResponseListener {
    
          override fun onSuccess(response: String?) {

                Toast.makeText(requireContext(), "Successfully deleted", Toast.LENGTH_SHORT).show()
            }
           override fun onError(error: String?) {
                Toast.makeText(requireContext(), error.toString(), Toast.LENGTH_SHORT).show()
            }

        })


}

Examples 👀

Download the Goma Example App or look at the source code.


Authors

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.