Skip to content

Commit

Permalink
API-13976 customer-api: remove moved methods and methods not requirin…
Browse files Browse the repository at this point in the history
…g authentication (#174)
  • Loading branch information
wfabjanczuk authored Jan 17, 2025
1 parent 2c12ce3 commit c96f43c
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 313 deletions.
54 changes: 0 additions & 54 deletions customer/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,27 +352,6 @@ func (a *API) GetCustomer() (*Customer, error) {
return &resp, err
}

// ListLicenseProperties returns the properties of a given license.
func (a *API) ListLicenseProperties(namespace, name string) (Properties, error) {
var resp Properties
err := a.Call("list_license_properties", &listLicensePropertiesRequest{
Namespace: namespace,
Name: name,
}, &resp, &i.CallOptions{Method: http.MethodGet})
return resp, err
}

// ListGroupProperties returns the properties of a given group.
func (a *API) ListGroupProperties(groupID uint, namespace, name string) (Properties, error) {
var resp Properties
err := a.Call("list_group_properties", &listGroupPropertiesRequest{
ID: groupID,
Namespace: namespace,
Name: name,
}, &resp, &i.CallOptions{Method: http.MethodGet})
return resp, err
}

// AcceptGreeting marks an incoming greeting as seen.
func (a *API) AcceptGreeting(greetingID int, uniqueID string) error {
return a.Call("accept_greeting", &acceptGreetingRequest{
Expand All @@ -394,36 +373,3 @@ func (a *API) RequestEmailVerification(callbackURI string) error {
CallbackURI: callbackURI,
}, &emptyResponse{})
}

// GetDynamicConfiguration returns the dynamic configuration of a given group. It provides data to call Get Configuration and Get Localization.
func (a *API) GetDynamicConfiguration(groupID int, url, channelType string, isTest bool) (*DynamicConfiguration, error) {
var resp DynamicConfiguration
err := a.Call("get_dynamic_configuration", &getDynamicConfigurationRequest{
GroupID: groupID,
URL: url,
ChannelType: channelType,
Test: isTest,
}, &resp, &i.CallOptions{Method: http.MethodGet})
return &resp, err
}

// GetConfiguration returns the configuration of a given group in a given version.
func (a *API) GetConfiguration(groupID int, version string) (*Configuration, error) {
var resp Configuration
err := a.Call("get_configuration", &getConfigurationRequest{
GroupID: groupID,
Version: version,
}, &resp, &i.CallOptions{Method: http.MethodGet})
return &resp, err
}

// GetLocalization returns the localization of a given language and group in a given version.
func (a *API) GetLocalization(groupID int, language, version string) (map[string]string, error) {
var resp map[string]string
err := a.Call("get_localization", &getLocalizationRequest{
GroupID: groupID,
Language: language,
Version: version,
}, &resp, &i.CallOptions{Method: http.MethodGet})
return resp, err
}
210 changes: 1 addition & 209 deletions customer/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,81 +270,11 @@ var mockedResponses = map[string]string{
"image_height": 200,
"url": "https://livechatinc.com"
}`,
"mark_events_as_seen": `{}`,
"list_license_properties": `{
"0805e283233042b37f460ed8fbf22160": {
"string_property": "string value"
}
}`,
"list_group_properties": `{
"0805e283233042b37f460ed8fbf22160": {
"string_property": "string value"
}
}`,
"mark_events_as_seen": `{}`,
"get_customer": `{}`, //TODO - create some real structure here
"accept_greeting": `{}`,
"cancel_greeting": `{}`,
"request_email_verification": `{}`,
"get_dynamic_configuration": `{
"group_id": 0,
"client_limit_exceeded": false,
"domain_allowed": true,
"config_version": "84cc87cxza5ee24ed0f84fe3027fjf0c71",
"localization_version": "79cc87cea5ee24ed0f84fe3027fc0c74",
"language": "en"
}`,
"get_configuration": `{
"buttons": [
{
"id": "0466ba53cb",
"type": "image",
"online_value": "livechat.s3.amazonaws.com/default/buttons/button_online007.png",
"offline_value": "livechat.s3.amazonaws.com/default/buttons/button_offline007.png"
},
{
"id": "08ca886ba8",
"type": "image",
"online_value": "livechat.s3.amazonaws.com/default/buttons/button_online003.png",
"offline_value": "livechat.s3.amazonaws.com/default/buttons/button_offline003.png"
},
{
"id": "3344e63cad",
"type": "text",
"online_value": "Live chat now",
"offline_value": "Leave us a message"
}
],
"ticket_form": {
"id": "ticket_form_id",
"fields": [
{
"type": "name",
"id": "154417206262603539",
"label": "Your name",
"answer": "Thomas Anderson"
}
]
},
"prechat_form": {
"id": "prechat_form_id",
"fields": [
{
"type": "name",
"id": "154417206262603539",
"label": "Your name",
"answer": "Thomas Anderson"
}
]
},
"integrations": {},
"properties": {
"group": {},
"license": {}
}
}`,
"get_localization": `{
"Agents_currently_not_available": "Our agents are not available at the moment."
}`,
}

func createMockedResponder(t *testing.T, method string) roundTripFunc {
Expand Down Expand Up @@ -1289,50 +1219,6 @@ func TestGetCustomerShouldNotCrashOnErrorResponse(t *testing.T) {
verifyErrorResponse("GetCustomer", rErr, t)
}

func TestListLicensePropertiesShouldReturnDataReceivedFromCustomerAPI(t *testing.T) {
client := NewTestClient(createMockedResponder(t, "list_license_properties"))

api, err := customer.NewAPI(stubTokenGetter, client, "client_id")
if err != nil {
t.Error("API creation failed")
}

resp, rErr := api.ListLicenseProperties("", "")
if rErr != nil {
t.Errorf("ListLicenseProperties failed: %v", rErr)
}

if len(resp) != 1 {
t.Errorf("Invalid license properties: %v", resp)
}

if resp["0805e283233042b37f460ed8fbf22160"]["string_property"] != "string value" {
t.Errorf("Invalid license property 0805e283233042b37f460ed8fbf22160.string_property: %v", resp["0805e283233042b37f460ed8fbf22160"]["string_property"])
}
}

func TestListGroupPropertiesShouldReturnDataReceivedFromCustomerAPI(t *testing.T) {
client := NewTestClient(createMockedResponder(t, "list_group_properties"))

api, err := customer.NewAPI(stubTokenGetter, client, "client_id")
if err != nil {
t.Error("API creation failed")
}

resp, rErr := api.ListGroupProperties(0, "", "")
if rErr != nil {
t.Errorf("ListGroupProperties failed: %v", rErr)
}

if len(resp) != 1 {
t.Errorf("Invalid group properties: %v", resp)
}

if resp["0805e283233042b37f460ed8fbf22160"]["string_property"] != "string value" {
t.Errorf("Invalid group property 0805e283233042b37f460ed8fbf22160.string_property: %v", resp["0805e283233042b37f460ed8fbf22160"]["string_property"])
}
}

func TestAcceptGreetingShouldReturnDataReceivedFromCustomerAPI(t *testing.T) {
client := NewTestClient(createMockedResponder(t, "accept_greeting"))

Expand Down Expand Up @@ -1383,97 +1269,3 @@ func TestCancelGreetingShouldNotCrashOnErrorResponse(t *testing.T) {
rErr := api.CancelGreeting("foo")
verifyErrorResponse("CancelGreeting", rErr, t)
}

func TestGetDynamicConfigurationShouldReturnDataReceivedFromCustomerAPI(t *testing.T) {
client := NewTestClient(createMockedResponder(t, "get_dynamic_configuration"))

api, err := customer.NewAPI(stubTokenGetter, client, "client_id")
if err != nil {
t.Error("API creation failed")
}

resp, rErr := api.GetDynamicConfiguration(0, "foo", "bar", false)
if rErr != nil {
t.Errorf("GetDynamicConfiguration failed: %v", rErr)
}

if resp.ClientLimitExceeded {
t.Errorf("Invalid client_limit_exceeded: %v", resp.ClientLimitExceeded)
}

if resp.GroupID != 0 {
t.Errorf("Invalid group_id: %v", resp.GroupID)
}

if !resp.DomainAllowed {
t.Errorf("Invalid domain_allowed: %v", resp.DomainAllowed)
}

if resp.ConfigVersion != "84cc87cxza5ee24ed0f84fe3027fjf0c71" {
t.Errorf("Invalid config_version: %v", resp.ConfigVersion)
}

if resp.LocalizationVersion != "79cc87cea5ee24ed0f84fe3027fc0c74" {
t.Errorf("Invalid localization_version: %v", resp.LocalizationVersion)
}

if resp.Language != "en" {
t.Errorf("Invalid language: %v", resp.Language)
}
}

func TestGetConfigurationShouldReturnDataReceivedFromCustomerAPI(t *testing.T) {
client := NewTestClient(createMockedResponder(t, "get_configuration"))

api, err := customer.NewAPI(stubTokenGetter, client, "client_id")
if err != nil {
t.Error("API creation failed")
}

resp, rErr := api.GetConfiguration(0, "foo")
if rErr != nil {
t.Errorf("GetConfiguration failed: %v", rErr)
}

if len(resp.Buttons) != 3 {
t.Errorf("Invalid buttons: %v", resp.Buttons)
}

if len(resp.TicketForm.Fields) != 1 {
t.Errorf("Invalid ticket_form.fields: %v", resp.TicketForm.Fields)
}

if resp.TicketForm.ID != "ticket_form_id" {
t.Errorf("Invalid ticket_form.id: %v", resp.TicketForm.ID)
}

if len(resp.PrechatForm.Fields) != 1 {
t.Errorf("Invalid prechat_form.fields: %v", resp.PrechatForm.Fields)
}

if resp.PrechatForm.ID != "prechat_form_id" {
t.Errorf("Invalid prechat_form.id: %v", resp.PrechatForm.ID)
}
}

func TestGetLocalizationShouldReturnDataReceivedFromCustomerAPI(t *testing.T) {
client := NewTestClient(createMockedResponder(t, "get_localization"))

api, err := customer.NewAPI(stubTokenGetter, client, "client_id")
if err != nil {
t.Error("API creation failed")
}

resp, rErr := api.GetLocalization(0, "foo", "bar")
if rErr != nil {
t.Errorf("GetLocalization failed: %v", rErr)
}

if len(resp) != 1 {
t.Errorf("Invalid response size: %v", resp)
}

if resp["Agents_currently_not_available"] != "Our agents are not available at the moment." {
t.Errorf("Invalid response content: %v", resp)
}
}
29 changes: 0 additions & 29 deletions customer/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,6 @@ type markEventsAsSeenRequest struct {

type emptyResponse struct{}

type listLicensePropertiesRequest struct {
Namespace string `url:"namespace,omitempty"`
Name string `url:"name,omitempty"`
}

type listGroupPropertiesRequest struct {
ID uint `url:"id"`
Namespace string `url:"namespace,omitempty"`
Name string `url:"name,omitempty"`
}

type acceptGreetingRequest struct {
GreetingID int `json:"greeting_id"`
UniqueID string `json:"unique_id"`
Expand All @@ -198,21 +187,3 @@ type hashedPaginationResponse struct {
type requestEmailVerificationRequest struct {
CallbackURI string `json:"callback_uri"`
}

type getDynamicConfigurationRequest struct {
GroupID int `url:"group_id"`
URL string `url:"url"`
ChannelType string `url:"channel_type"`
Test bool `url:"test"`
}

type getConfigurationRequest struct {
GroupID int `url:"group_id"`
Version string `url:"version"`
}

type getLocalizationRequest struct {
GroupID int `url:"group_id"`
Language string `url:"language"`
Version string `url:"version"`
}
21 changes: 0 additions & 21 deletions customer/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,13 @@ type URLInfo struct {
ImageHeight int `json:"image_height"`
}

type DynamicConfiguration struct {
GroupID int `json:"group_id"`
ClientLimitExceeded bool `json:"client_limit_exceeded"`
DomainAllowed bool `json:"domain_allowed"`
ConfigVersion string `json:"config_version"`
LocalizationVersion string `json:"localization_version"`
Language string `json:"language"`
}

type ConfigButton struct {
ID string `json:"id"`
Type string `json:"type"`
OnlineValue string `json:"online_value"`
OfflineValue string `json:"offline_value"`
}

type Configuration struct {
Buttons []ConfigButton `json:"buttons"`
TicketForm *Form `json:"ticket_form,omitempty"`
PrechatForm *Form `json:"prechat_form,omitempty"`
AllowedDomains []string `json:"allowed_domains,omitempty"`
Integrations map[string]map[string]string `json:"integrations"`
Properties struct {
Group Properties `json:"group"`
License Properties `json:"license"`
} `json:"properties"`
}

// User represents base of both Customer and Agent
//
// To get specific user type's structure, call Agent() or Customer() (based on Type value).
Expand Down

0 comments on commit c96f43c

Please sign in to comment.