Skip to content

Commit 9d13127

Browse files
authored
Merge pull request #102 from Neur0toxine/favorite-products
favorite products methods
2 parents 39568f3 + e882563 commit 9d13127

File tree

9 files changed

+372
-28
lines changed

9 files changed

+372
-28
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
runs-on: ubuntu-latest
4141
strategy:
4242
matrix:
43-
go-version: ['1.19', '1.20', '1.21', '1.22', '1.23', 'stable']
43+
go-version: ['1.19', '1.20', '1.21', '1.22', '1.23', '1.24', '1.25', 'stable']
4444
include:
4545
- go-version: '1.23'
4646
coverage: 1
@@ -55,25 +55,27 @@ jobs:
5555
run: |
5656
go mod tidy
5757
cp .env.dist .env
58+
- name: Install gotestsum
59+
run: |
60+
if [[ "${{ matrix.go-version }}" < "1.24" && "${{ matrix.go-version }}" != "stable" ]]; then
61+
go install gotest.tools/gotestsum@v1.12.0
62+
else
63+
go install gotest.tools/gotestsum@latest
64+
fi
5865
- name: Tests
5966
env:
6067
COVERAGE: ${{ matrix.coverage }}
6168
if: env.COVERAGE != 1
6269
run: |
63-
go install gotest.tools/gotestsum@latest
6470
gotestsum --format testdox ./... -tags=testutils -v -cpu 2 -timeout 60s -race
6571
- name: Tests with coverage
6672
env:
6773
COVERAGE: ${{ matrix.coverage }}
6874
if: env.COVERAGE == 1
6975
run: |
70-
go install gotest.tools/gotestsum@latest
7176
gotestsum --format testdox ./... -tags=testutils -v -cpu 2 -timeout 60s -race -cover -coverprofile=coverage.txt -covermode=atomic "$d"
7277
- name: Coverage
7378
env:
7479
COVERAGE: ${{ matrix.coverage }}
7580
if: env.COVERAGE == 1
76-
run: |
77-
go install github.com/axw/gocov/gocov@latest
78-
gocov convert ./coverage.txt | gocov report
79-
bash <(curl -s https://codecov.io/bash)
81+
run: bash <(curl -s https://codecov.io/bash)

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ issues:
2323
- unused
2424
- errchkjson
2525
- varnamelen
26+
- dupl
2627
exclude-use-default: true
2728
exclude-case-sensitive: false
2829
max-issues-per-linter: 0

.tool-versions

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
go 1.23.12
2+
gotestsum 1.13.0
3+
golangci-lint 1.62.2

client.go

Lines changed: 159 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,7 +1959,7 @@ func (c *Client) CorporateCustomerEdit(customer CorporateCustomer, by string, si
19591959

19601960
// ClearCart clears the current customer's shopping cart
19611961
//
1962-
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-customer-interaction-site-cart-clear
1962+
// For more information see https://docs.retailcrm.ru/Developers/API/APIv5#post--api-v5-customer-interaction-site-cart-clear
19631963
//
19641964
// Example:
19651965
//
@@ -2021,7 +2021,7 @@ func (c *Client) ClearCart(site string, filter SiteFilter, req ClearCartRequest)
20212021

20222022
// SetCart creates or overwrites shopping cart data
20232023
//
2024-
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-customer-interaction-site-cart-set
2024+
// For more information see https://docs.retailcrm.ru/Developers/API/APIv5#post--api-v5-customer-interaction-site-cart-set
20252025
//
20262026
// Example:
20272027
//
@@ -2091,7 +2091,7 @@ func (c *Client) SetCart(site string, filter SiteFilter, req SetCartRequest) (
20912091

20922092
// GetCart returns the current customer's shopping cart
20932093
//
2094-
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#get--api-v5-customer-interaction-site-cart-customerId
2094+
// For more information see https://docs.retailcrm.ru/Developers/API/APIv5#get--api-v5-customer-interaction-site-cart-customerId
20952095
//
20962096
// Example:
20972097
//
@@ -2125,6 +2125,146 @@ func (c *Client) GetCart(site, customer string, filter GetCartFilter) (CartRespo
21252125
return resp, status, nil
21262126
}
21272127

2128+
// GetFavorites returns the current customer's list of favorite offers
2129+
//
2130+
// For more information see https://docs.retailcrm.ru/Developers/API/APIv5#get--api-v5-customer-interaction-site-favorites-customerId
2131+
//
2132+
// Example:
2133+
//
2134+
// var client = retailcrm.New("https://demo.url", "09jIJ")
2135+
//
2136+
// data, status, err := client.GetFavorites("site_id","customer_id",
2137+
// retailcrm.GetFavoritesFilter{ SiteBy: "code", By: "externalId"})
2138+
//
2139+
// if err != nil {
2140+
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
2141+
// log.Fatalf("http status: %d, %s", status, apiErr.String())
2142+
// }
2143+
//
2144+
// log.Fatalf("http status: %d, error: %s", status, err)
2145+
// }
2146+
func (c *Client) GetFavorites(site, customer string, filter FavoritesFilter) (FavoritesResponse, int, error) {
2147+
var resp FavoritesResponse
2148+
2149+
params, _ := query.Values(filter)
2150+
2151+
data, status, err := c.GetRequest(fmt.Sprintf("/customer-interaction/%s/favorites/%s?%s", site, customer, params.Encode()))
2152+
if err != nil {
2153+
return resp, status, err
2154+
}
2155+
2156+
err = json.Unmarshal(data, &resp)
2157+
if err != nil {
2158+
return resp, status, err
2159+
}
2160+
2161+
return resp, status, nil
2162+
}
2163+
2164+
// AddFavorite adds favorite products for customer
2165+
//
2166+
// For more information see https://docs.retailcrm.ru/Developers/API/APIv5#post--api-v5-customer-interaction-site-favorites-customerId-add
2167+
//
2168+
// Example:
2169+
//
2170+
// var client = retailcrm.New("https://demo.url", "09jIJ")
2171+
//
2172+
// data, status, err := client.AddFavorite("site_id", "customer_external_id", retailcrm.FavoritesFilter{SiteBy: "id", By: "externalId"},
2173+
// retailcrm.AddFavoriteRequest{
2174+
// ID: 1,
2175+
// ExternalID: "ext_id",
2176+
// XMLID: "xml_id",
2177+
// },
2178+
// )
2179+
//
2180+
// if err != nil {
2181+
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
2182+
// log.Fatalf("http status: %d, %s", status, apiErr.String())
2183+
// }
2184+
//
2185+
// log.Fatalf("http status: %d, error: %s", status, err)
2186+
// }
2187+
func (c *Client) AddFavorite(site, customer string, filter FavoritesFilter, req AddFavoriteRequest) (
2188+
SuccessfulResponse, int, error,
2189+
) {
2190+
var resp SuccessfulResponse
2191+
2192+
updateJSON, err := json.Marshal(&req)
2193+
if err != nil {
2194+
return SuccessfulResponse{}, 0, err
2195+
}
2196+
2197+
p := url.Values{
2198+
"favorite": {string(updateJSON)},
2199+
}
2200+
2201+
params, _ := query.Values(filter)
2202+
2203+
data, status, err := c.PostRequest(fmt.Sprintf("/customer-interaction/%s/favorites/%s/add?%s", site, customer, params.Encode()), p)
2204+
if err != nil {
2205+
return resp, status, err
2206+
}
2207+
2208+
err = json.Unmarshal(data, &resp)
2209+
if err != nil {
2210+
return resp, status, err
2211+
}
2212+
2213+
return resp, status, nil
2214+
}
2215+
2216+
// RemoveFavorite removes favorite products from customer
2217+
//
2218+
// For more information see https://docs.retailcrm.ru/Developers/API/APIv5#post--api-v5-customer-interaction-site-favorites-customerId-remove
2219+
//
2220+
// Example:
2221+
//
2222+
// var client = retailcrm.New("https://demo.url", "09jIJ")
2223+
//
2224+
// data, status, err := client.RemoveFavorite("site_id", "customer_external_id", retailcrm.FavoritesFilter{SiteBy: "id", By: "externalId"},
2225+
// retailcrm.AddFavoriteRequest{
2226+
// ID: 1,
2227+
// ExternalID: "ext_id",
2228+
// XMLID: "xml_id",
2229+
// },
2230+
// )
2231+
//
2232+
// if err != nil {
2233+
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
2234+
// log.Fatalf("http status: %d, %s", status, apiErr.String())
2235+
// }
2236+
//
2237+
// log.Fatalf("http status: %d, error: %s", status, err)
2238+
// }
2239+
func (c *Client) RemoveFavorite(site, customer string, filter FavoritesFilter, req AddFavoriteRequest) (
2240+
SuccessfulResponse, int, error,
2241+
) {
2242+
var resp SuccessfulResponse
2243+
2244+
updateJSON, err := json.Marshal(&req)
2245+
if err != nil {
2246+
return SuccessfulResponse{}, 0, err
2247+
}
2248+
2249+
p := url.Values{
2250+
"favorite": {string(updateJSON)},
2251+
}
2252+
2253+
params, _ := query.Values(filter)
2254+
2255+
data, status, err := c.PostRequest(fmt.Sprintf("/customer-interaction/%s/favorites/%s/remove?%s", site, customer, params.Encode()), p)
2256+
if err != nil {
2257+
return resp, status, err
2258+
}
2259+
2260+
err = json.Unmarshal(data, &resp)
2261+
if err != nil {
2262+
return resp, status, err
2263+
}
2264+
2265+
return resp, status, nil
2266+
}
2267+
21282268
// DeliveryTracking updates tracking data
21292269
//
21302270
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-delivery-generic-subcode-tracking
@@ -6277,7 +6417,7 @@ func (c *Client) AccountBonusOperations(id int, parameters AccountBonusOperation
62776417

62786418
// ProductsBatchEdit perform editing products batch
62796419
//
6280-
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-store-products-batch-edit
6420+
// For more information see https://docs.retailcrm.ru/Developers/API/APIv5#post--api-v5-store-products-batch-edit
62816421
//
62826422
// Example:
62836423
//
@@ -6333,7 +6473,7 @@ func (c *Client) ProductsBatchEdit(products []ProductEdit) (ProductsBatchEditRes
63336473

63346474
// ProductsBatchCreate perform adding products batch
63356475
//
6336-
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-store-products-batch-create
6476+
// For more information see https://docs.retailcrm.ru/Developers/API/APIv5#post--api-v5-store-products-batch-create
63376477
//
63386478
// Example:
63396479
//
@@ -6387,7 +6527,7 @@ func (c *Client) ProductsBatchCreate(products []ProductCreate) (ProductsBatchEdi
63876527

63886528
// LoyaltyAccountCreate аdd a client to the loyalty program
63896529
//
6390-
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-loyalty-account-create
6530+
// For more information see https://docs.retailcrm.ru/Developers/API/APIv5#post--api-v5-loyalty-account-create
63916531
//
63926532
// Example:
63936533
//
@@ -6441,7 +6581,7 @@ func (c *Client) LoyaltyAccountCreate(site string, loyaltyAccount SerializedCrea
64416581

64426582
// LoyaltyAccountEdit edit a client in the loyalty program
64436583
//
6444-
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-loyalty-account-id-edit
6584+
// For more information see https://docs.retailcrm.ru/Developers/API/APIv5#post--api-v5-loyalty-account-id-edit
64456585
//
64466586
// Example:
64476587
//
@@ -6491,7 +6631,7 @@ func (c *Client) LoyaltyAccountEdit(id int, loyaltyAccount SerializedEditLoyalty
64916631

64926632
// LoyaltyAccount return information about client in the loyalty program
64936633
//
6494-
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#get--api-v5-loyalty-account-id
6634+
// For more information see https://docs.retailcrm.ru/Developers/API/APIv5#get--api-v5-loyalty-account-id
64956635
//
64966636
// Example:
64976637
//
@@ -6530,7 +6670,7 @@ func (c *Client) LoyaltyAccount(id int) (LoyaltyAccountResponse, int, error) {
65306670

65316671
// LoyaltyAccountActivate activate participation in the loyalty program for client
65326672
//
6533-
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-loyalty-account-id-activate
6673+
// For more information see https://docs.retailcrm.ru/Developers/API/APIv5#post--api-v5-loyalty-account-id-activate
65346674
//
65356675
// Example:
65366676
//
@@ -6569,7 +6709,7 @@ func (c *Client) LoyaltyAccountActivate(id int) (LoyaltyAccountActivateResponse,
65696709

65706710
// LoyaltyBonusCredit accrue bonus participation in the program of loyalty
65716711
//
6572-
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-loyalty-account-id-bonus-credit
6712+
// For more information see https://docs.retailcrm.ru/Developers/API/APIv5#post--api-v5-loyalty-account-id-bonus-credit
65736713
//
65746714
// Example:
65756715
//
@@ -6615,7 +6755,7 @@ func (c *Client) LoyaltyBonusCredit(id int, req LoyaltyBonusCreditRequest) (Loya
66156755

66166756
// LoyaltyBonusStatusDetails get details on the bonus account
66176757
//
6618-
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#get--api-v5-loyalty-account-id-bonus-status-details
6758+
// For more information see https://docs.retailcrm.ru/Developers/API/APIv5#get--api-v5-loyalty-account-id-bonus-status-details
66196759
//
66206760
// Example:
66216761
//
@@ -6665,7 +6805,7 @@ func (c *Client) LoyaltyBonusStatusDetails(
66656805

66666806
// LoyaltyAccounts return list of participations in the loyalty program
66676807
//
6668-
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#get--api-v5-loyalty-accounts
6808+
// For more information see https://docs.retailcrm.ru/Developers/API/APIv5#get--api-v5-loyalty-accounts
66696809
//
66706810
// Example:
66716811
//
@@ -6719,7 +6859,7 @@ func (c *Client) LoyaltyAccounts(req LoyaltyAccountsRequest) (LoyaltyAccountsRes
67196859

67206860
// LoyaltyCalculate calculations of the maximum discount
67216861
//
6722-
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-loyalty-calculate
6862+
// For more information see https://docs.retailcrm.ru/Developers/API/APIv5#post--api-v5-loyalty-calculate
67236863
//
67246864
// Example:
67256865
//
@@ -6786,7 +6926,7 @@ func (c *Client) LoyaltyCalculate(req LoyaltyCalculateRequest) (LoyaltyCalculate
67866926

67876927
// GetLoyalties returns list of loyalty programs
67886928
//
6789-
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#get--api-v5-loyalty-loyalties
6929+
// For more information see https://docs.retailcrm.ru/Developers/API/APIv5#get--api-v5-loyalty-loyalties
67906930
//
67916931
// Example:
67926932
//
@@ -6838,7 +6978,7 @@ func (c *Client) GetLoyalties(req LoyaltiesRequest) (LoyaltiesResponse, int, err
68386978

68396979
// GetLoyaltyByID return program of loyalty by id
68406980
//
6841-
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#get--api-v5-loyalty-loyalties-id
6981+
// For more information see https://docs.retailcrm.ru/Developers/API/APIv5#get--api-v5-loyalty-loyalties-id
68426982
//
68436983
// Example:
68446984
//
@@ -6878,7 +7018,7 @@ func (c *Client) GetLoyaltyByID(id int) (LoyaltyResponse, int, error) {
68787018

68797019
// OrderIntegrationDeliveryCancel cancels of integration delivery
68807020
//
6881-
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-orders-externalId-delivery-cancel
7021+
// For more information see https://docs.retailcrm.ru/Developers/API/APIv5#post--api-v5-orders-externalId-delivery-cancel
68827022
//
68837023
// Example:
68847024
//
@@ -6922,7 +7062,7 @@ func (c *Client) OrderIntegrationDeliveryCancel(by string, force bool, id string
69227062

69237063
// CreateProductsGroup adds a product group
69247064
//
6925-
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-store-product-groups-create
7065+
// For more information see https://docs.retailcrm.ru/Developers/API/APIv5#post--api-v5-store-product-groups-create
69267066
//
69277067
// Example:
69287068
//
@@ -6975,7 +7115,7 @@ func (c *Client) CreateProductsGroup(group ProductGroup) (ActionProductsGroupRes
69757115

69767116
// EditProductsGroup edits a product group
69777117
//
6978-
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-store-product-groups-externalId-edit
7118+
// For more information see https://docs.retailcrm.ru/Developers/API/APIv5#post--api-v5-store-product-groups-externalId-edit
69797119
//
69807120
// Example:
69817121
//
@@ -7105,7 +7245,7 @@ func (c *Client) GetOrderPlate(by, orderID, site string, plateID int) (io.ReadCl
71057245

71067246
// NotificationsSend send a notification
71077247
//
7108-
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-notifications-send
7248+
// For more information see https://docs.retailcrm.ru/Developers/API/APIv5#post--api-v5-notifications-send
71097249
//
71107250
// Example:
71117251
//

0 commit comments

Comments
 (0)