github.com/grokify/go-ringcentral-client@v0.3.31/engagedigital/v1/examples/attachment_create/main.go (about)

     1  package main
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"log"
     7  	"os"
     8  
     9  	"github.com/antihax/optional"
    10  	"github.com/jessevdk/go-flags"
    11  
    12  	engagedigital "github.com/grokify/go-ringcentral-client/engagedigital/v1/client"
    13  	utils "github.com/grokify/go-ringcentral-client/engagedigital/v1/util"
    14  	"github.com/grokify/mogo/fmt/fmtutil"
    15  )
    16  
    17  // curl -XPOST https://DOMAIN.api.engagement.dimelo.com/1.0/attachments -H 'Authorization: Bearer TOKEN' -F 'file=@ringcentral-engage-logo.svg'
    18  
    19  type options struct {
    20  	Site  string `short:"s" long:"site" description:"A site" required:"true"`
    21  	Token string `short:"t" long:"token" description:"A token" required:"true"`
    22  	File  string `short:"f" long:"file" description:"A file" required:"true"`
    23  }
    24  
    25  func main() {
    26  	opts := options{}
    27  	_, err := flags.Parse(&opts)
    28  	if err != nil {
    29  		log.Fatal(err)
    30  	}
    31  
    32  	client := utils.NewApiClient(opts.Site, opts.Token)
    33  
    34  	file, err := os.Open(opts.File)
    35  	if err != nil {
    36  		log.Fatal(err)
    37  	}
    38  
    39  	apiOpts := &engagedigital.CreateAttachmentOpts{
    40  		File: optional.NewInterface(file)}
    41  
    42  	info, resp, err := client.AttachmentsApi.CreateAttachment(context.Background(), apiOpts)
    43  
    44  	if err != nil {
    45  		log.Fatal(err)
    46  	} else if resp.StatusCode != 200 {
    47  		log.Fatal(resp.StatusCode)
    48  	}
    49  	fmtutil.PrintJSON(info)
    50  
    51  	fmt.Println("DONE")
    52  }