github.com/grokify/go-ringcentral-client@v0.3.31/engagedigital/v1/examples/simple_get/main.go (about) 1 package main 2 3 import ( 4 "context" 5 "fmt" 6 "log" 7 "strings" 8 9 "github.com/jessevdk/go-flags" 10 11 ex "github.com/grokify/go-ringcentral-client/engagedigital/v1/examples" 12 utils "github.com/grokify/go-ringcentral-client/engagedigital/v1/util" 13 ) 14 15 type options struct { 16 Site string `short:"s" long:"site" description:"A site" required:"true"` 17 Token string `short:"t" long:"token" description:"A token" required:"true"` 18 Object string `short:"o" long:"object" description:"An object" required:"true"` 19 Id string `short:"i" long:"id" description:"An object id" required:"false"` 20 } 21 22 func main() { 23 opts := options{} 24 _, err := flags.Parse(&opts) 25 if err != nil { 26 log.Fatal(err) 27 } 28 29 client := utils.NewApiClient(opts.Site, opts.Token) 30 31 opts.Id = strings.TrimSpace(opts.Id) 32 opts.Object = strings.ToLower(strings.TrimSpace(opts.Object)) 33 34 switch strings.ToLower(opts.Object) { 35 case "agentstatus": 36 if len(opts.Id) > 0 { 37 ex.HandleApiResponse(client.AgentStatusApi.GetAgentStatus(context.Background(), opts.Id)) 38 } else { 39 ex.HandleApiResponse(client.AgentStatusApi.GetAllAgentStatus(context.Background())) 40 } 41 case "attachment": 42 if len(opts.Id) > 0 { 43 ex.HandleApiResponse(client.AttachmentsApi.GetAttachment(context.Background(), opts.Id)) 44 } else { 45 ex.HandleApiResponse(client.AttachmentsApi.GetAllAttachments(context.Background(), nil)) 46 } 47 case "category": 48 if len(opts.Id) > 0 { 49 ex.HandleApiResponse(client.CategoriesApi.GetCategory(context.Background(), opts.Id)) 50 } else { 51 ex.HandleApiResponse(client.CategoriesApi.GetAllCategories(context.Background(), nil)) 52 } 53 case "channel": 54 if len(opts.Id) > 0 { 55 ex.HandleApiResponse(client.ChannelsApi.GetChannel(context.Background(), opts.Id)) 56 } else { 57 ex.HandleApiResponse(client.ChannelsApi.GetAllChannels(context.Background(), nil)) 58 } 59 case "community": 60 if len(opts.Id) > 0 { 61 ex.HandleApiResponse(client.CommunitiesApi.GetCommunity(context.Background(), opts.Id)) 62 } else { 63 ex.HandleApiResponse(client.CommunitiesApi.GetAllCommunities(context.Background(), nil)) 64 } 65 case "content": 66 if len(opts.Id) > 0 { 67 ex.HandleApiResponse(client.ContentsApi.GetContent(context.Background(), opts.Id)) 68 } else { 69 ex.HandleApiResponse(client.ContentsApi.GetAllContents(context.Background(), nil)) 70 } 71 case "customfields": 72 if len(opts.Id) > 0 { 73 ex.HandleApiResponse(client.CustomFieldsApi.GetCustomField(context.Background(), opts.Id)) 74 } else { 75 ex.HandleApiResponse(client.CustomFieldsApi.GetAllCustomFields(context.Background(), nil)) 76 } 77 case "event": 78 if len(opts.Id) > 0 { 79 ex.HandleApiResponse(client.EventsApi.GetEvent(context.Background(), opts.Id)) 80 } else { 81 ex.HandleApiResponse(client.EventsApi.GetAllEvents(context.Background(), nil)) 82 } 83 case "folder": 84 if len(opts.Id) > 0 { 85 ex.HandleApiResponse(client.FoldersApi.GetFolder(context.Background(), opts.Id)) 86 } else { 87 ex.HandleApiResponse(client.FoldersApi.GetAllFolders(context.Background(), nil)) 88 } 89 case "identity": 90 if len(opts.Id) > 0 { 91 ex.HandleApiResponse(client.IdentitiesApi.GetIdentity(context.Background(), opts.Id)) 92 } else { 93 ex.HandleApiResponse(client.IdentitiesApi.GetAllIdentities(context.Background(), nil)) 94 } 95 case "identitygroup": 96 if len(opts.Id) > 0 { 97 ex.HandleApiResponse(client.IdentityGroupsApi.GetIdentityGroup(context.Background(), opts.Id)) 98 } else { 99 ex.HandleApiResponse(client.IdentityGroupsApi.GetAllIdentityGroups(context.Background(), nil)) 100 } 101 case "intervention": 102 if len(opts.Id) > 0 { 103 ex.HandleApiResponse(client.InterventionsApi.GetIntervention(context.Background(), opts.Id)) 104 } else { 105 ex.HandleApiResponse(client.InterventionsApi.GetAllInterventions(context.Background(), nil)) 106 } 107 case "interventioncomment": 108 if len(opts.Id) > 0 { 109 ex.HandleApiResponse(client.InterventionCommentsApi.GetInterventionComment(context.Background(), opts.Id)) 110 } else { 111 ex.HandleApiResponse(client.InterventionCommentsApi.GetAllInterventionComments(context.Background(), nil)) 112 } 113 case "locale": 114 ex.HandleApiResponse(client.LocalesApi.GetAllLocales(context.Background())) 115 case "presencestatus": 116 if len(opts.Id) > 0 { 117 ex.HandleApiResponse(client.PresenceStatusApi.GetPresenceStatus(context.Background(), opts.Id)) 118 } else { 119 ex.HandleApiResponse(client.PresenceStatusApi.GetAllPresenceStatus(context.Background(), nil)) 120 } 121 case "replyassistantentry": 122 if len(opts.Id) > 0 { 123 ex.HandleApiResponse(client.ReplyAssistantEntriesApi.GetReplyAssistantEntry(context.Background(), opts.Id)) 124 } else { 125 ex.HandleApiResponse(client.ReplyAssistantEntriesApi.GetAllReplyAssistantEntries(context.Background(), nil)) 126 } 127 case "replyassistantgroup": 128 if len(opts.Id) > 0 { 129 ex.HandleApiResponse(client.ReplyAssistantGroupsApi.GetReplyAssistantGroup(context.Background(), opts.Id)) 130 } else { 131 ex.HandleApiResponse(client.ReplyAssistantGroupsApi.GetAllReplyAssistantGroups(context.Background(), nil)) 132 } 133 case "replyassistantversion": 134 if len(opts.Id) > 0 { 135 ex.HandleApiResponse(client.ReplyAssistantVersionsApi.GetReplyAssistantVersion(context.Background(), opts.Id)) 136 } else { 137 ex.HandleApiResponse(client.ReplyAssistantVersionsApi.GetAllReplyAssistantVersions(context.Background(), nil)) 138 } 139 case "role": 140 if len(opts.Id) > 0 { 141 ex.HandleApiResponse(client.RolesApi.GetRole(context.Background(), opts.Id)) 142 } else { 143 ex.HandleApiResponse(client.RolesApi.GetAllRoles(context.Background(), nil)) 144 } 145 case "settings": 146 ex.HandleApiResponse(client.SettingsApi.GetAllSettings(context.Background())) 147 case "source": 148 if len(opts.Id) > 0 { 149 ex.HandleApiResponse(client.SourcesApi.GetSource(context.Background(), opts.Id)) 150 } else { 151 ex.HandleApiResponse(client.SourcesApi.GetAllSources(context.Background(), nil)) 152 } 153 case "tag": 154 if len(opts.Id) > 0 { 155 ex.HandleApiResponse(client.TagsApi.GetTag(context.Background(), opts.Id)) 156 } else { 157 ex.HandleApiResponse(client.TagsApi.GetAllTags(context.Background(), nil)) 158 } 159 case "task": 160 if len(opts.Id) > 0 { 161 ex.HandleApiResponse(client.TasksApi.GetTask(context.Background(), opts.Id)) 162 } else { 163 ex.HandleApiResponse(client.TasksApi.GetAllTasks(context.Background(), nil)) 164 } 165 case "team": 166 if len(opts.Id) > 0 { 167 ex.HandleApiResponse(client.TeamsApi.GetTeam(context.Background(), opts.Id)) 168 } else { 169 ex.HandleApiResponse(client.TeamsApi.GetAllTeams(context.Background(), nil)) 170 } 171 case "thread": 172 if len(opts.Id) > 0 { 173 ex.HandleApiResponse(client.ThreadsApi.GetThread(context.Background(), opts.Id)) 174 } else { 175 ex.HandleApiResponse(client.ThreadsApi.GetAllThreads(context.Background(), nil)) 176 } 177 case "timesheet": 178 if len(opts.Id) > 0 { 179 ex.HandleApiResponse(client.TimeSheetsApi.GetTimeSheet(context.Background(), "me")) 180 } else { 181 ex.HandleApiResponse(client.TimeSheetsApi.GetAllTimeSheets(context.Background(), nil)) 182 } 183 case "user": 184 if len(opts.Id) > 0 { 185 ex.HandleApiResponse(client.UsersApi.GetUser(context.Background(), opts.Id)) 186 } else { 187 ex.HandleApiResponse(client.UsersApi.GetAllUsers(context.Background(), nil)) 188 } 189 /*case "usersourcespermissions": 190 info, resp, err := client.UsersApi.GetUser(context.Background(), "me") 191 if err != nil { 192 log.Fatal(err) 193 } else if resp.StatusCode != 200 { 194 log.Fatal(resp.StatusCode) 195 } 196 fmt.Println(info.Id) 197 ex.HandleApiResponse(client.UserSourcesPermissionsApi.GetUserSourcesPermission( 198 context.Background(), info.Id))*/ 199 case "webhook": 200 if len(opts.Id) > 0 { 201 ex.HandleApiResponse(client.WebhooksApi.GetWebhook(context.Background(), opts.Id, opts.Token)) 202 } else { 203 ex.HandleApiResponse(client.WebhooksApi.GetAllWebhooks(context.Background(), opts.Token, nil)) 204 } 205 default: 206 log.Fatal(fmt.Sprintf("E_ACTION_NOT_FOUND [%s]", opts.Object)) 207 } 208 209 fmt.Println("DONE") 210 }