Categorygithub.com/mca312/talon_go
2.2.2
Repository: https://github.com/mca312/talon_go.git
Documentation: pkg.go.dev

# README

Go API client for talon

The Talon.One API is used to manage applications and campaigns, as well as to integrate with your application. The operations in the Integration API section are used to integrate with our platform, while the other operations are used to manage applications and campaigns.

Where is the API?

The API is available at the same hostname as these docs. For example, if you are reading this page at https://mycompany.talon.one/docs/api/, the URL for the updateCustomerProfile operation is https://mycompany.talon.one/v1/customer_profiles/id

Overview

This API client was generated by the OpenAPI Generator project. By using the OpenAPI-spec from a remote server, you can easily generate an API client.

  • API version: 1.0.0
  • Package version: 2.2.0
  • Build package: org.openapitools.codegen.languages.GoClientExperimentalCodegen

Installation

Install the following dependencies:

go get github.com/stretchr/testify/assert
go get golang.org/x/oauth2
go get golang.org/x/net/context

Put the package under your project folder and add the following in import:

import sw "./talon"

Configuration of Server URL

Default configuration comes with Servers field that contains server objects as defined in the OpenAPI specification.

Select Server Configuration

For using other server than the one defined on index 0 set context value sw.ContextServerIndex of type int.

ctx := context.WithValue(context.Background(), sw.ContextServerIndex, 1)

Templated Server URL

Templated server URL is formatted using default variables from configuration or from context value sw.ContextServerVariables of type map[string]string.

ctx := context.WithValue(context.Background(), sw.ContextServerVariables, map[string]string{
	"basePath": "v2",
})

Note, enum values are always validated and all unused variables are silently ignored.

URLs Configuration per Operation

Each operation can use different server URL defined using OperationServers map in the Configuration. An operation is uniquely identifield by "{classname}Service.{nickname}" string. Similar rules for overriding default operation server index and variables applies by using sw.ContextOperationServerIndices and sw.ContextOperationServerVariables context maps.

ctx := context.WithValue(context.Background(), sw.ContextOperationServerIndices, map[string]int{
	"{classname}Service.{nickname}": 2,
})
ctx = context.WithValue(context.Background(), sw.ContextOperationServerVariables, map[string]map[string]string{
	"{classname}Service.{nickname}": {
		"port": "8443",
	},
})

Getting Started

Integration API

V2

package main

import (
	"context"
	"encoding/json"
	"fmt"

	talon "github.com/talon-one/talon_go"
)

func main() {
	configuration := talon.NewConfiguration()
	// Set API base path
	configuration.Servers = talon.ServerConfigurations{
		{
			// Notice that there is no trailing '/'
			URL:         "https://mycompany.talon.one",
			Description: "Talon.One's API base URL",
		},
	}
	// If you wish to inject a custom implementation of HTTPClient
	// configuration.HTTPClient = &customHTTPClient

	integrationClient := talon.NewAPIClient(configuration)

	// Create integration authentication context using api key
	integrationAuthContext := context.WithValue(context.Background(), talon.ContextAPIKeys, map[string]talon.APIKey{
		"Authorization": talon.APIKey{
			Prefix: "ApiKey-v1",
			Key:    "fd1fd219b1e953a6b2700e8034de5bfc877462ae106127311ddd710978654312",
		},
	})

	// Instantiating a NewCustomerSessionV2 struct
	customerSession := talon.NewCustomerSession{
		// You can use both struct literals
		ProfileId:   talon.PtrString("DEADBEEF"),
		CouponCodes: &[]string{"Cool-Stuff!"},
	}

	// Or alternatively, using the relevant setter in a later stage in the code
	newCustomerSession.SetCartItems([]talon.CartItem{
		talon.CartItem{
			Name:     "Pad Thai - Veggie",
			Sku:      "pad-332",
			Quantity: 1,
			Price:    5.5,
			Category: talon.PtrString("Noodles"),
		},
		talon.CartItem{
			Name:     "Chang",
			Sku:      "chang-br-42",
			Quantity: 1,
			Price:    2.3,
			Category: talon.PtrString("Beverages"),
		},
	})

	// Instantiating a new IntegrationRequest
	integrationRequest := talon.IntegrationRequest{
		CustomerSession: newCustomerSession,
	}

	// Optional list of requested information to be present on the response.
  // See docs/IntegrationRequest.md for full list of supported values
	// integrationRequest.SetResponseContent([]string{
	// 	"customerSession",
	// 	"customerProfile",
	// 	"loyalty",
	// })

	// Create/update a customer session using `UpdateCustomerSessionV2` function
	integrationState, _, err := integrationClient.IntegrationApi.
		UpdateCustomerSessionV2(integrationAuthContext, "deetdoot_2").
		Body(integrationRequest).
		Execute()

	if err != nil {
		fmt.Printf("ERROR while calling UpdateCustomerSessionV2: %s\n", err)
		return
	}
	fmt.Printf("%#v\n", integrationState)

	// Parsing the returned effects list, please consult https://developers.talon.one/Integration-API/handling-effects-v2 for the full list of effects and their corresponding properties
	for _, effect := range integrationState.GetEffects() {
		effectType := effect.GetEffectType()
		switch {
		case "setDiscount" == effectType:
			// Initiating right props instance according to the effect type
			effectProps := talon.SetDiscountEffectProps{}
			if err := decodeHelper(effect.GetProps(), &effectProps); err != nil {
				fmt.Printf("ERROR while decoding 'setDiscount' props: %s\n", err)
				continue
			}

			// Access the specific effect's properties
			fmt.Printf("Set a discount '%s' of %2.3f\n", effectProps.GetName(), effectProps.GetValue())
		case "acceptCoupon" == effectType:
			// Initiating right props instance according to the effect type
			effectProps := talon.AcceptCouponEffectProps{}
			if err := decodeHelper(effect.GetProps(), &effectProps); err != nil {
				fmt.Printf("ERROR while decoding props: %s\n", err)
				continue
			}

			// Work with AcceptCouponEffectProps' properties
			// ...
		default:
			fmt.Printf("Encounter unknown effect type: %s\n", effectType)
		}
	}
}

// quick decoding of props-map into our library structures using JSON marshaling,
// or alternatively using a library like https://github.com/mitchellh/mapstructure
func decodeHelper(propsMap map[string]interface{}, v interface{}) error {
	propsJSON, err := json.Marshal(propsMap)
	if err != nil {
		return err
	}
	return json.Unmarshal(propsJSON, v)
}

V1

package main

import (
	"context"
	"fmt"

	talon "github.com/talon-one/talon_go"
)

func main() {
	configuration := talon.NewConfiguration()
	// Set API base path
	configuration.Servers = talon.ServerConfigurations{
		{
			// Notice that there is no trailing '/'
			URL:         "https://mycompany.talon.one",
			Description: "Talon.One's API base URL",
		},
	}
	// If you wish to inject a custom implementation of HTTPClient
	// configuration.HTTPClient = &customHTTPClient

	integrationClient := talon.NewAPIClient(configuration)

	// Create integration authentication context using api key
	integrationAuthContext := context.WithValue(context.Background(), talon.ContextAPIKeys, map[string]talon.APIKey{
		"Authorization": talon.APIKey{
			Prefix: "ApiKey-v1",
			Key:    "fd1fd219b1e953a6b2700e8034de5bfc877462ae106127311ddd710978654312",
		},
	})

	// Instantiating a NewCustomerSession struct
	customerSession := talon.NewCustomerSession{
		// You can use both struct literals
		ProfileId: talon.PtrString("DEADBEEF"),
		State:     talon.PtrString("open"),
	}

	// Or alternatively, using the relevant setter in a later stage in the code
	customerSession.SetTotal(42.0)

	// Create/update a customer session using `UpdateCustomerSession` function
	integrationState, response, err := integrationClient.IntegrationApi.
		UpdateCustomerSession(integrationAuthContext, "deetdoot").
		Body(customerSession).
		Execute()

	if err != nil {
		fmt.Printf("ERROR while calling UpdateCustomerSession: %s\n", err)
		return
	}

	fmt.Printf("%#v\n\n", integrationState.Session)
	fmt.Printf("%#v\n\n", response)
}

Management API

package main

import (
	"context"
	"fmt"

	talon "github.com/talon-one/talon_go"
)

func main() {
	configuration := talon.NewConfiguration()
	// Set API base path
	configuration.Servers = talon.ServerConfigurations{
		{
			// Notice that there is no trailing '/'
			URL:         "https://mycompany.talon.one",
			Description: "Talon.One's API base URL",
		},
	}
	// If you wish to inject a custom implementation of HTTPClient
	// configuration.HTTPClient = &customHTTPClient

	managementClient := talon.NewAPIClient(configuration)

	session, _, err := managementClient.ManagementApi.
		CreateSession(context.Background()).
		Body(talon.LoginParams{
			Email:    "[email protected]",
			Password: "50meSecureVeryPa$$w0rd!",
		}).
		Execute()

	if err != nil {
		fmt.Printf("ERROR while creating a new session using CreateSession: %s\n", err)
		return
	}

	// Create integration authentication context using the logged-in session
	managerAuthContext := context.WithValue(context.Background(), talon.ContextAPIKeys, map[string]talon.APIKey{
		"Authorization": talon.APIKey{
			Prefix: "Bearer",
			Key:    session.GetToken(),
		},
	})

	// Calling `GetApplication` function with the desired id (7)
	application, response, err := managementClient.ManagementApi.
		GetApplication(managerAuthContext, 7).
		Execute()

	if err != nil {
		fmt.Printf("ERROR while calling GetApplication: %s\n", err)
		return
	}

	fmt.Printf("%#v\n\n", application)
	fmt.Printf("%#v\n\n", response)
}

Documentation for API Endpoints

All URIs are relative to http://localhost

ClassMethodHTTP requestDescription
IntegrationApiCreateCouponReservationPost /v1/coupon_reservations/{couponValue}Create a new coupon reservation
IntegrationApiCreateReferralPost /v1/referralsCreate a referral code for an advocate
IntegrationApiDeleteCouponReservationDelete /v1/coupon_reservations/{couponValue}Delete coupon reservations
IntegrationApiDeleteCustomerDataDelete /v1/customer_data/{integrationId}Delete the personal data of a customer.
IntegrationApiGetCustomerInventoryGet /v1/customer_profiles/{integrationId}/inventoryGet an inventory of all data associated with a specific customer profile.
IntegrationApiGetReservedCustomersGet /v1/coupon_reservations/customerprofiles/{couponValue}Get the users that have this coupon reserved
IntegrationApiTrackEventPost /v1/eventsTrack an Event
IntegrationApiUpdateCustomerProfilePut /v1/customer_profiles/{integrationId}Update a Customer Profile V1
IntegrationApiUpdateCustomerProfileAudiencesPost /v2/customer_audiencesUpdate a Customer Profile Audiences
IntegrationApiUpdateCustomerProfileV2Put /v2/customer_profiles/{integrationId}Update a Customer Profile
IntegrationApiUpdateCustomerProfilesV2Put /v2/customer_profilesUpdate multiple Customer Profiles
IntegrationApiUpdateCustomerSessionPut /v1/customer_sessions/{customerSessionId}Update a Customer Session V1
IntegrationApiUpdateCustomerSessionV2Put /v2/customer_sessions/{customerSessionId}Update a Customer Session
ManagementApiAddLoyaltyPointsPut /v1/loyalty_programs/{programID}/profile/{integrationID}/add_pointsAdd points in a certain loyalty program for the specified customer
ManagementApiCopyCampaignToApplicationsPost /v1/applications/{applicationId}/campaigns/{campaignId}/copyCopy the campaign into every specified application
ManagementApiCreateAdditionalCostPost /v1/additional_costsDefine a new additional cost
ManagementApiCreateAttributePost /v1/attributesDefine a new custom attribute
ManagementApiCreateCampaignPost /v1/applications/{applicationId}/campaignsCreate a Campaign
ManagementApiCreateCouponsPost /v1/applications/{applicationId}/campaigns/{campaignId}/couponsCreate Coupons
ManagementApiCreatePasswordRecoveryEmailPost /v1/password_recovery_emailsRequest a password reset
ManagementApiCreateRulesetPost /v1/applications/{applicationId}/campaigns/{campaignId}/rulesetsCreate a Ruleset
ManagementApiCreateSessionPost /v1/sessionsCreate a Session
ManagementApiDeleteCampaignDelete /v1/applications/{applicationId}/campaigns/{campaignId}Delete a Campaign
ManagementApiDeleteCouponDelete /v1/applications/{applicationId}/campaigns/{campaignId}/coupons/{couponId}Delete one Coupon
ManagementApiDeleteCouponsDelete /v1/applications/{applicationId}/campaigns/{campaignId}/couponsDelete Coupons
ManagementApiDeleteReferralDelete /v1/applications/{applicationId}/campaigns/{campaignId}/referrals/{referralId}Delete one Referral
ManagementApiDeleteRulesetDelete /v1/applications/{applicationId}/campaigns/{campaignId}/rulesets/{rulesetId}Delete a Ruleset
ManagementApiGetAccessLogsGet /v1/applications/{applicationId}/access_logsGet access logs for application (with total count)
ManagementApiGetAccessLogsWithoutTotalCountGet /v1/applications/{applicationId}/access_logs/no_totalGet access logs for application
ManagementApiGetAccountGet /v1/accounts/{accountId}Get Account Details
ManagementApiGetAccountAnalyticsGet /v1/accounts/{accountId}/analyticsGet Account Analytics
ManagementApiGetAdditionalCostGet /v1/additional_costs/{additionalCostId}Get an additional cost
ManagementApiGetAdditionalCostsGet /v1/additional_costsList additional costs
ManagementApiGetAllAccessLogsGet /v1/access_logsGet all access logs
ManagementApiGetAllRolesGet /v1/rolesGet all roles.
ManagementApiGetApplicationGet /v1/applications/{applicationId}Get Application
ManagementApiGetApplicationApiHealthGet /v1/applications/{applicationId}/health_reportGet report of health of application API
ManagementApiGetApplicationCustomerGet /v1/applications/{applicationId}/customers/{customerId}Get Application Customer
ManagementApiGetApplicationCustomersGet /v1/applications/{applicationId}/customersList Application Customers
ManagementApiGetApplicationCustomersByAttributesPost /v1/application_customer_searchGet a list of the customer profiles that match the given attributes (with total count)
ManagementApiGetApplicationEventTypesGet /v1/applications/{applicationId}/event_typesList Applications Event Types
ManagementApiGetApplicationEventsGet /v1/applications/{applicationId}/eventsList Applications Events (with total count)
ManagementApiGetApplicationEventsWithoutTotalCountGet /v1/applications/{applicationId}/events/no_totalList Applications Events
ManagementApiGetApplicationSessionGet /v1/applications/{applicationId}/sessions/{sessionId}Get Application Session
ManagementApiGetApplicationSessionsGet /v1/applications/{applicationId}/sessionsList Application Sessions
ManagementApiGetApplicationsGet /v1/applicationsList Applications
ManagementApiGetAttributeGet /v1/attributes/{attributeId}Get a custom attribute
ManagementApiGetAttributesGet /v1/attributesList custom attributes
ManagementApiGetCampaignGet /v1/applications/{applicationId}/campaigns/{campaignId}Get a Campaign
ManagementApiGetCampaignAnalyticsGet /v1/applications/{applicationId}/campaigns/{campaignId}/analyticsGet analytics of campaigns
ManagementApiGetCampaignByAttributesPost /v1/applications/{applicationId}/campaigns_searchGet a list of all campaigns that match the given attributes
ManagementApiGetCampaignsGet /v1/applications/{applicationId}/campaignsList your Campaigns
ManagementApiGetChangesGet /v1/changesGet audit log for an account
ManagementApiGetCouponsGet /v1/applications/{applicationId}/campaigns/{campaignId}/couponsList Coupons (with total count)
ManagementApiGetCouponsByAttributesPost /v1/applications/{applicationId}/campaigns/{campaignId}/coupons_searchGet a list of the coupons that match the given attributes
ManagementApiGetCouponsByAttributesApplicationWidePost /v1/applications/{applicationId}/coupons_searchGet a list of the coupons that match the given attributes in all active campaigns of an application (with total count)
ManagementApiGetCouponsWithoutTotalCountGet /v1/applications/{applicationId}/campaigns/{campaignId}/coupons/no_totalList Coupons
ManagementApiGetCustomerActivityReportGet /v1/applications/{applicationId}/customer_activity_reports/{customerId}Get Activity Report for Single Customer
ManagementApiGetCustomerActivityReportsGet /v1/applications/{applicationId}/customer_activity_reportsGet Activity Reports for Application Customers (with total count)
ManagementApiGetCustomerActivityReportsWithoutTotalCountGet /v1/applications/{applicationId}/customer_activity_reports/no_totalGet Activity Reports for Application Customers
ManagementApiGetCustomerAnalyticsGet /v1/applications/{applicationId}/customers/{customerId}/analyticsGet Analytics Report for a Customer
ManagementApiGetCustomerProfileGet /v1/customers/{customerId}Get Customer Profile
ManagementApiGetCustomerProfilesGet /v1/customers/no_totalList Customer Profiles
ManagementApiGetCustomersByAttributesPost /v1/customer_search/no_totalGet a list of the customer profiles that match the given attributes
ManagementApiGetEventTypesGet /v1/event_typesList Event Types
ManagementApiGetExportsGet /v1/exportsGet Exports
ManagementApiGetImportsGet /v1/importsGet Imports
ManagementApiGetLoyaltyPointsGet /v1/loyalty_programs/{programID}/profile/{integrationID}get the Loyalty Ledger for this integrationID
ManagementApiGetLoyaltyProgramGet /v1/loyalty_programs/{programID}Get a loyalty program
ManagementApiGetLoyaltyProgramsGet /v1/loyalty_programsList all loyalty Programs
ManagementApiGetLoyaltyStatisticsGet /v1/loyalty_programs/{programID}/statisticsGet loyalty program statistics by loyalty program ID
ManagementApiGetReferralsGet /v1/applications/{applicationId}/campaigns/{campaignId}/referralsList Referrals (with total count)
ManagementApiGetReferralsWithoutTotalCountGet /v1/applications/{applicationId}/campaigns/{campaignId}/referrals/no_totalList Referrals
ManagementApiGetRoleGet /v1/roles/{roleId}Get information for the specified role.
ManagementApiGetRulesetGet /v1/applications/{applicationId}/campaigns/{campaignId}/rulesets/{rulesetId}Get a Ruleset
ManagementApiGetRulesetsGet /v1/applications/{applicationId}/campaigns/{campaignId}/rulesetsList Campaign Rulesets
ManagementApiGetUserGet /v1/users/{userId}Get a single User
ManagementApiGetUsersGet /v1/usersList Users in your account
ManagementApiGetWebhookGet /v1/webhooks/{webhookId}Get Webhook
ManagementApiGetWebhookActivationLogsGet /v1/webhook_activation_logsList Webhook activation Log Entries
ManagementApiGetWebhookLogsGet /v1/webhook_logsList Webhook Log Entries
ManagementApiGetWebhooksGet /v1/webhooksList Webhooks
ManagementApiRemoveLoyaltyPointsPut /v1/loyalty_programs/{programID}/profile/{integrationID}/deduct_pointsDeduct points in a certain loyalty program for the specified customer
ManagementApiResetPasswordPost /v1/reset_passwordReset password
ManagementApiSearchCouponsAdvancedPost /v1/applications/{applicationId}/campaigns/{campaignId}/coupons_search_advancedGet a list of the coupons that match the given attributes (with total count)
ManagementApiSearchCouponsAdvancedApplicationWidePost /v1/applications/{applicationId}/coupons_search_advancedGet a list of the coupons that match the given attributes in all active campaigns of an application (with total count)
ManagementApiSearchCouponsAdvancedApplicationWideWithoutTotalCountPost /v1/applications/{applicationId}/coupons_search_advanced/no_totalGet a list of the coupons that match the given attributes in all active campaigns of an application
ManagementApiSearchCouponsAdvancedWithoutTotalCountPost /v1/applications/{applicationId}/campaigns/{campaignId}/coupons_search_advanced/no_totalGet a list of the coupons that match the given attributes
ManagementApiUpdateAdditionalCostPut /v1/additional_costs/{additionalCostId}Update an additional cost
ManagementApiUpdateAttributePut /v1/attributes/{attributeId}Update a custom attribute
ManagementApiUpdateCampaignPut /v1/applications/{applicationId}/campaigns/{campaignId}Update a Campaign
ManagementApiUpdateCouponPut /v1/applications/{applicationId}/campaigns/{campaignId}/coupons/{couponId}Update a Coupon
ManagementApiUpdateCouponBatchPut /v1/applications/{applicationId}/campaigns/{campaignId}/couponsUpdate a Batch of Coupons
ManagementApiUpdateRulesetPut /v1/applications/{applicationId}/campaigns/{campaignId}/rulesets/{rulesetId}Update a Ruleset

Documentation For Models

Documentation For Authorization

api_key_v1

  • Type: API key
  • API key parameter name: Authorization
  • Location: HTTP header

Note, each API key must be added to a map of map[string]APIKey where the key is: Authorization and passed in as the auth context for each request.

integration_auth

  • Type: API key
  • API key parameter name: Content-Signature
  • Location: HTTP header

Note, each API key must be added to a map of map[string]APIKey where the key is: Content-Signature and passed in as the auth context for each request.

manager_auth

  • Type: API key
  • API key parameter name: Authorization
  • Location: HTTP header

Note, each API key must be added to a map of map[string]APIKey where the key is: Authorization and passed in as the auth context for each request.

Documentation for Utility Methods

Due to the fact that model structure members are all pointers, this package contains a number of utility functions to easily obtain pointers to values of basic types. Each of these functions takes a value of the given basic type and returns a pointer to it:

  • PtrBool
  • PtrInt
  • PtrInt32
  • PtrInt64
  • PtrFloat
  • PtrFloat32
  • PtrFloat64
  • PtrString
  • PtrTime

Author

# Packages

No description provided by the author