Skip to content

Commit

Permalink
feat: ringcentral: examples/get_url init
Browse files Browse the repository at this point in the history
  • Loading branch information
grokify committed Jul 30, 2021
1 parent 813fe7e commit c1357da
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions ringcentral/examples/get_url/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"fmt"
"io/ioutil"

"github.com/grokify/oauth2more/credentials"
"github.com/grokify/simplego/fmt/fmtutil"
"github.com/jessevdk/go-flags"
"github.com/rs/zerolog/log"
)

type Options struct {
CredsPath string `short:"c" long:"credspath" description:"Environment File Path" required:"true"`
Account string `short:"a" long:"account" description:"Environment Variable Name" required:"true"`
URL string `short:"u" long:"url" description:"URL"`
}

func main() {
opts := Options{}
_, err := flags.Parse(&opts)
if err != nil {
log.Fatal().Err(err).Msg("required properties not present")
}
fmtutil.PrintJSON(opts)

cset, err := credentials.ReadFileCredentialsSet(opts.CredsPath)
if err != nil {
log.Fatal().Err(err).
Str("credentials_filepath", opts.CredsPath).
Msg("cannot read credentials file")
}
sclient, err := cset.NewSimpleClient(opts.Account)
if err != nil {
fmt.Println(string(err.Error()))
log.Fatal().Err(err).
Msg("cannot create simpleclient")
}

resp, err := sclient.Get(opts.URL)
if err != nil {
log.Fatal().Err(err).Msg("get URL error")
}
fmt.Printf("STATUS [%d]", resp.StatusCode)
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal().Err(err).Msg("parse body error")
}
fmt.Println(string(body))

fmt.Println("DONE")
}

0 comments on commit c1357da

Please sign in to comment.