tawasal

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2024 License: MIT Imports: 4 Imported by: 0

README


check our Documentation 👉 platform.tawasal.ae


Tawasal SDK for Go

The Tawasal SDK for Go provides a set of utilities to interact with the Tawasal platform. This SDK allows you to extract and decode user information from a cookie, generate authorization tokens, and extract device tokens.

Installation

To install the Tawasal SDK, use the following command:

go get github.com/TawasalPlatform/golang

Usage

Import the Package

In your Go code, import the Tawasal SDK package:

import "github.com/TawasalPlatform/golang"
Functions Provided by the SDK
GetUser

Extracts and decodes the user information from a provided cookie.

import (
	"github.com/TawasalPlatform/golang"
)

func main() {
	cookie := "your_encoded_cookie_here"
	user, err := tawasal.GetUser(cookie)
	if err != nil {
		log.Fatalf("Error getting user: %v", err)
	}
	fmt.Printf("User: %+v\n", user)
}
GetAuthorization

Generates an authorization token from the provided cookie.

import (
	"github.com/TawasalPlatform/golang"
)

func main() {
	cookie := "your_encoded_cookie_here"
	authToken, err := tawasal.GetAuthorization(cookie)
	if err != nil {
		log.Fatalf("Error getting authorization token: %v", err)
	}
	fmt.Printf("Authorization Token: %s\n", authToken)
}
GetDeviceToken

Extracts the device token from the provided cookie.

import (
	"github.com/TawasalPlatform/golang"
)

func main() {
	cookie := "your_encoded_cookie_here"
	deviceToken, err := tawasal.GetDeviceToken(cookie)
	if err != nil {
		log.Fatalf("Error getting device token: %v", err)
	}
	fmt.Printf("Device Token: %s\n", deviceToken)
}

Example

Here's a complete example demonstrating how to use the Tawasal SDK in a Go application:

package main

import (
	"fmt"
	"log"
	"github.com/TawasalPlatform/golang"
)

func main() {
	cookie := "your_encoded_cookie_here"

	// Get user information
	user, err := tawasal.GetUser(cookie)
	if err != nil {
		log.Fatalf("Error getting user: %v", err)
	}
	fmt.Printf("User: %+v\n", user)

	// Get authorization token
	authToken, err := tawasal.GetAuthorization(cookie)
	if err != nil {
		log.Fatalf("Error getting authorization token: %v", err)
	}
	fmt.Printf("Authorization Token: %s\n", authToken)

	// Get device token
	deviceToken, err := tawasal.GetDeviceToken(cookie)
	if err != nil {
		log.Fatalf("Error getting device token: %v", err)
	}
	fmt.Printf("Device Token: %s\n", deviceToken)
}

API Reference

GetUser

Extracts and decodes the user information from a provided cookie.

Parameters
  • cookie: A raw string representing the cookie from which user information is to be extracted.
Returns
  • An object containing the user information.
  • An error, if any.
GetAuthorization

Generates an authorization token from the provided cookie.

Parameters
  • cookie: A raw string representing the cookie from which the authorization token is to be extracted.
Returns
  • A base64 encoded string representing the authorization token, or an error if the token is not available.
GetDeviceToken

Extracts the device token from the provided cookie.

Parameters
  • cookie: A raw string representing the cookie from which the device token is to be extracted.
Returns
  • A string representing the device token, or an error if the token is not available.

License

This project is licensed under the MIT License.


This README provides an overview of how to use the Tawasal SDK in a Go application. Adjust the import paths and package names as necessary to match your project's structure.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeBase64

func DecodeBase64(encoded string) (string, error)

DecodeBase64 decodes a base64 encoded string similar to the JavaScript implementation.

func GetAuthorization

func GetAuthorization(cookie string) (string, error)

GetAuthorization generates an authorization token from the provided cookie. Parameters: - cookie: A raw string representing the cookie from which the authorization token is to be extracted. Returns: A base64 encoded string representing the authorization token, or an error if the token is not available.

func GetDeviceToken

func GetDeviceToken(cookie string) (string, error)

GetDeviceToken extracts the device token from the provided cookie. Parameters: - cookie: A raw string representing the cookie from which the device token is to be extracted. Returns: A string representing the device token, or an error if the token is not available.

Types

type Language

type Language string

Language type represents supported languages.

const (
	English    Language = "en"
	Arabic     Language = "ar"
	Spanish    Language = "es"
	Persian    Language = "fa"
	French     Language = "fr"
	Indonesian Language = "id"
	Russian    Language = "ru"
	Turkish    Language = "tr"
	Hindi      Language = "hi"
	Urdu       Language = "ur"
)

type Platform

type Platform string

Platform type represents supported platforms.

const (
	IOS     Platform = "ios"
	Android Platform = "android"
)

type User

type User struct {
	UserID       int      `json:"userId"`
	UserToken    string   `json:"userToken,omitempty"`
	FirstName    string   `json:"firstName,omitempty"`
	LastName     string   `json:"lastName,omitempty"`
	UserNickname string   `json:"userNickname,omitempty"`
	Language     Language `json:"language"`
	Platform     Platform `json:"platform"`
	Version      string   `json:"version"`
}

User struct represents the user information.

func GetUser

func GetUser(cookie string) (*User, error)

GetUser extracts and decodes the user information from a provided cookie. Parameters: - cookie: A raw string representing the cookie from which user information is to be extracted. Returns: An object containing the user information.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL