-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcatalogs.go
124 lines (103 loc) · 3.45 KB
/
catalogs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//********************************************************************************************************************//
//
// Copyright (C) 2018 - 2022 J&J Ideenschmiede GmbH <[email protected]>
//
// This file is part of goafterbuy.
// All code may be used. Feel free and maybe code something better.
//
// Author: Jonas Kwiedor (aka gowizzard)
//
//********************************************************************************************************************//
package goafterbuy
import (
"bytes"
"encoding/xml"
)
// CatalogsBody is to structure the xml data
type CatalogsBody struct {
Request CatalogsRequest `xml:"Request"`
}
type CatalogsRequest struct {
AfterbuyGlobal AfterbuyGlobal `xml:"AfterbuyGlobal"`
MaxCatalogs int `xml:"MaxCatalogs"`
DataFilter *CatalogsRequestDataFilter `xml:"DataFilter"`
}
type CatalogsRequestDataFilter struct {
Filter []CatalogsRequestFilter `xml:"Filter"`
}
type CatalogsRequestFilter struct {
FilterName string `xml:"FilterName"`
FilterValues CatalogsRequestFilterValues `xml:"FilterValues"`
}
type CatalogsRequestFilterValues struct {
ValueFrom int `xml:"ValueFrom,omitempty"`
ValueTo int `xml:"ValueTo,omitempty"`
FilterValue []string `xml:"FilterValue,omitempty"`
}
// CatalogsReturn is to decode the xml return data
type CatalogsReturn struct {
XmlName xml.Name `xml:"Afterbuy"`
CallStatus string `xml:"CallStatus"`
CallName string `xml:"CallName"`
VersionId int `xml:"VersionID"`
Result CatalogsReturnResult `xml:"Result"`
}
type CatalogsReturnResult struct {
XmlName xml.Name `xml:"Result"`
HasMoreCatalogs int `xml:"HasMoreCatalogs"`
Catalogs CatalogsReturnCatalogs `xml:"Catalogs"`
LastCatalogId int `xml:"LastCatalogID"`
}
type CatalogsReturnCatalogs struct {
XmlName xml.Name `xml:"Catalogs"`
Catalog []CatalogsReturnCatalog `xml:"Catalog"`
}
type CatalogsReturnCatalog struct {
XmlName xml.Name `xml:"Catalog"`
CatalogId int `xml:"CatalogID"`
Name string `xml:"Name"`
Description string `xml:"Description"`
ParentId int `xml:"ParentID"`
Level int `xml:"Level"`
Position int `xml:"Position"`
AdditionalText string `xml:"AdditionalText"`
Show int `xml:"Show"`
URL string `xml:"URL"`
Picture1 string `xml:"Picture1"`
Picture2 string `xml:"Picture2"`
TitlePicture string `xml:"TitlePicture"`
}
// Catalogs is to get all catalogs from ab interface
func Catalogs(body CatalogsBody) (CatalogsReturn, error) {
// Convert body
convert, err := xml.Marshal(body)
if err != nil {
return CatalogsReturn{}, err
}
// Set config for request
c := Config{
BaseUrl: "https://api.afterbuy.de/afterbuy/ABInterface.aspx",
Method: "GET",
Body: bytes.NewBuffer(convert),
Header: map[string]string{},
}
// Add header to config
header := make(map[string]string)
header["Content-Type"] = "application/xml"
c.Header = header
// Send new request
response, err := c.Send()
if err != nil {
return CatalogsReturn{}, err
}
// Close request body
defer response.Body.Close()
// Decode data
var decode CatalogsReturn
err = xml.NewDecoder(response.Body).Decode(&decode)
if err != nil {
return CatalogsReturn{}, err
}
// Return data
return decode, nil
}