Skip to content

Instantly share code, notes, and snippets.

@diegolucasb
Last active August 6, 2018 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diegolucasb/72d7741514c1f99ef72a4c08a1cc4dd4 to your computer and use it in GitHub Desktop.
Save diegolucasb/72d7741514c1f99ef72a4c08a1cc4dd4 to your computer and use it in GitHub Desktop.

For SDK Builder on Kotlin, Swift and Web plataforms, how do we:

...Instanciate the SDK?

  • Kotlin
  val sdk = SlingSDK.Builder().build()
  
  //with parameters
  val sdk = SlingSDK.Builder()
          .setUrl("url.com/v0")
          .setHeaders(listOf())
          .setAffiliationCode(listOf())
          .setAuthentication(AuthenticationType.BEARER, "")
          .build()
  • Swift
  let sdk = SDKBuilder()
          .build()

  //with parameters
  
  • Web
import * as sdk from './src/index.js';
import { BEARER } from './src/constants/constants.js';

  //with parameters
  

...Authenticate user in the SDK?

  • Kotlin
  sdk.authentication.get(
                parameters = mapOf(
                        AuthenticationHandler.USERNAME_KEY to "",
                        AuthenticationHandler.PASSWORD_KEY to ""),
                success = {
                    Log.i("SDK", (it as? AuthResponse)?.data?.toString() ?: it?.toString())
                    callMethods()
                },
                error = { Log.e("SDK", it.toString()) }
  
  • Swift
  sdk.authenticate.post(email: "", password: "") { (result) in
              switch result {
              case .success(let response):
                  print(response.object.data)

                  self.sdk.setAffiliationCode(response.object.data.affiliationCodes)
                  self.sdk.setToken(response.object.data.token)

              case .failure(let error):
                  print(error)

              }
          }
        
  • Web
  It does not have authentication method

...Call get method from endpoint?

  • Kotlin
  //Address sample
  sdk.merchants.address.get(
    success = { Log.i("SDK-Address", it?.data?.forEach { it.toString() }.toString())},
    error = { Log.e("SDK-Address", it.toString()) }
  )  
  
  //if you want to call get address from other API Url, just fill URL parameter like this:
  sdk.merchants.partners.get(
    url = "https://portalapi.stone.com.br/",
    success = { Log.i("SDK-Information", it.toString())},
    error = { Log.e("SDK-Information", it.toString()) }
  )  
  
  //if you want to pass parameter to you endpoint, you have to call:
  sdk.payments.calendar.get(
    parameters = mapOf(
            "startDate" to "2018-06-01",
            "finalDate" to "2018-06-30",
            "crossBalance" to "true"
    ),
    success = { Log.i("SDK-Calendar", it?.data?.forEach{ it.toString() }.toString()) },
    error = { Log.e("SDK-Calendar", it.toString()) }
  )  
  • Swift
  sdk.merchant.address.get { (result) in
        switch result {
        case .success(let response):
            print(response.object.data)

        case .failure(let error):
            print(error)

        }
    }
  • Web
  sdk.merchants.addresses.get(params);

...Call get method from other endpoint different from gateway?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment