-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrule.go
130 lines (115 loc) · 4 KB
/
rule.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
125
126
127
128
129
130
//********************************************************************************************************************//
//
// Copyright (C) 2018 - 2021 J&J Ideenschmiede GmbH <[email protected]>
//
// This file is part of gosw6.
// All code may be used. Feel free and maybe code something better.
//
// Author: Jonas Kwiedor (aka gowizzard)
//
//********************************************************************************************************************//
package gosw6
import (
"encoding/json"
"fmt"
"net/url"
"time"
)
// RulesReturn is to decode the json data
type RulesReturn struct {
Total int `json:"total"`
Data []struct {
Name string `json:"name"`
Description *string `json:"description"`
Priority int `json:"priority"`
ModuleTypes *struct {
Types []string `json:"types"`
} `json:"moduleTypes"`
ProductPrices interface{} `json:"productPrices"`
ShippingMethods interface{} `json:"shippingMethods"`
PaymentMethods interface{} `json:"paymentMethods"`
EventActions interface{} `json:"eventActions"`
Conditions interface{} `json:"conditions"`
Invalid bool `json:"invalid"`
ShippingMethodPrices interface{} `json:"shippingMethodPrices"`
PromotionDiscounts interface{} `json:"promotionDiscounts"`
PromotionSetGroups interface{} `json:"promotionSetGroups"`
ShippingMethodPriceCalculations interface{} `json:"shippingMethodPriceCalculations"`
PersonaPromotions interface{} `json:"personaPromotions"`
FlowSequences interface{} `json:"flowSequences"`
Tags interface{} `json:"tags"`
OrderPromotions interface{} `json:"orderPromotions"`
CartPromotions interface{} `json:"cartPromotions"`
UniqueIdentifier string `json:"_uniqueIdentifier"`
VersionId interface{} `json:"versionId"`
Translated []interface{} `json:"translated"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt interface{} `json:"updatedAt"`
Extensions struct {
ForeignKeys struct {
ApiAlias interface{} `json:"apiAlias"`
Extensions []interface{} `json:"extensions"`
} `json:"foreignKeys"`
} `json:"extensions"`
Id string `json:"id"`
CustomFields interface{} `json:"customFields"`
ApiAlias string `json:"apiAlias"`
} `json:"data"`
Aggregations []interface{} `json:"aggregations"`
Errors []struct {
Code string `json:"code"`
Status string `json:"status"`
Title string `json:"title"`
Detail string `json:"detail"`
Meta struct {
Trace []struct {
File string `json:"file"`
Line int `json:"line"`
Function string `json:"function"`
Class string `json:"class"`
Type string `json:"type"`
} `json:"trace"`
File string `json:"file"`
Line int `json:"line"`
} `json:"meta"`
} `json:"errors"`
}
// Rules are to get a list of all rules
func Rules(parameter map[string]string, r Request) (RulesReturn, error) {
// Set config for request
c := Config{
Path: "/api/rule",
Method: "GET",
Body: nil,
}
// Parse url & add attributes
parse, err := url.Parse(c.Path)
if err != nil {
return RulesReturn{}, err
}
newUrl, err := url.ParseQuery(parse.RawQuery)
if err != nil {
return RulesReturn{}, err
}
for index, value := range parameter {
newUrl.Add(index, value)
}
// Set new url
parse.RawQuery = newUrl.Encode()
c.Path = fmt.Sprintf("%s", parse)
// Send request
response, err := c.Send(r)
if err != nil {
return RulesReturn{}, err
}
// Close request
defer response.Body.Close()
// Decode data
var decode RulesReturn
err = json.NewDecoder(response.Body).Decode(&decode)
if err != nil {
return RulesReturn{}, err
}
// Return data
return decode, err
}