Coder Social home page Coder Social logo

go-zoho's Introduction

go-zoho

go-zoho is a Golang library for dealing with ZOHO CRM. Please see ZOHO API Docs for details on API credentials.

Installation

go get github.com/pushm0v/go-zoho

Basic usage

You can use custom http.Client & cache if you want to implement Redis or similar cache, by default it will use LocalCache.

import "github.com/pushm0v/go-zoho"

var params = zoho.ZohoParams{
    GrantToken:    "1000.xxxx.yyyy",
    ClientID:      "1000.abcdef",
    ClientSecret:  "client-secret",
    IamURL:        "https://accounts.zoho.com",
    CrmURL:        "https://zohoapis.com/crm",
    FileUploadURL: "https://content.zohoapis.com/crm",
    ZGID:          "12345677",
    Version:       crm.VersionV2,
}

var httpClient = http2.NewHttpClient(new(http.Client))
var localCache = cache.NewCache(cache.WithLocalCache())
var zohoClient = zoho.NewZoho(params, httpClient, cache)

Auth Worker with Redis cache

Auth Worker can retrieve and refresh Access Token automatically and be used later by zohoClient.

params := zoho2.ZohoParams{
    GrantToken:    "1000.xxxx.yyyy",
    ClientID:      "1000.abcdef",
    ClientSecret:  "client-secret",
    IamURL:        "https://accounts.zoho.com",
    CrmURL:        "https://zohoapis.com/crm",
    FileUploadURL: "https://content.zohoapis.com/crm",
    ZGID:          "12345677",
    Version:       crm.VersionV2,
}

var ctx = context.Background()
rdb := redis.NewClient(&redis.Options{
    Addr:     "localhost:6379",
    Password: "", // no password set
    DB:       0,  // use default DB
})

var onSetFunc = func(key string, value interface{}, expire int) error {
    return rdb.Set(ctx, key, value, time.Duration(expire)*time.Second).Err()
}

var onGetFunc = func(key string) (value interface{}, err error) {
    val, err := rdb.Get(ctx, key).Result()
    if err != nil {
        return nil, err
    }

    return val, nil
}

cache := cache2.NewCache(cache2.WithExternalCache(cache2.Option{
    SetFunc: onSetFunc,
    GetFunc: onGetFunc,
}))
storage := storage2.NewStorage(cache)
authParams := oauth.ZohoAuthParams{
    ClientID:     params.ClientID,
    ClientSecret: params.ClientSecret,
    GrantToken:   params.GrantToken,
    IamURL:       params.IamURL,
}
authClient := oauth.NewZohoAuthClient(authParams, http2.NewHttpClient(new(http.Client)), storage)
wParams := worker.AuthWorkerParams{
    SecondsBeforeRefreshToken: 30,
}
w := worker.NewAuthWorker(authClient, wParams)

w.OnError(func(err error) {
    fmt.Println(err)
    w.Stop()
})
w.Start()

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

go-zoho's People

Contributors

pushm0v avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.