-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathendpoint.go
64 lines (53 loc) · 1.48 KB
/
endpoint.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
package bazaar
import (
"fmt"
)
// Create new endpoint
func NewEndpoint(route string) Endpoint {
e := Endpoint{}
e.setBaseUrl("https://pardakht.cafebazaar.ir")
e.setRoute(route)
e.Vars = map[string]string{}
return e
}
// Endpoint structure
type Endpoint struct {
BaseUrl string
Vars map[string]string
Route string
AcceessToken string
}
// Set endpoint's base url
func (e *Endpoint) setBaseUrl(url string) {
e.BaseUrl = url
}
// Define type of route
func (e *Endpoint) setRoute(route string) {
e.Route = route
}
// Define url option
func (e *Endpoint) setOption(key string, value string) {
e.Vars[key] = value
}
// Set access token
func (e *Endpoint) setAccessToken(accessToken string) {
e.AcceessToken = accessToken
}
// Generate final url
func (e *Endpoint) generate() string {
url := e.BaseUrl
switch e.Route {
case "auth":
url += "/auth/token/"
case "validatePurchase":
url += fmt.Sprintf("/api/validate/%s/inapp/%s/purchases/%s/", e.Vars["packageName"], e.Vars["productId"], e.Vars["purchaseToken"])
case "getSubscriptionStatus":
url += fmt.Sprintf("/api/applications/%s/subscriptions/%s/purchases/%s/", e.Vars["packageName"], e.Vars["subscriptionId"], e.Vars["purchaseToken"])
case "cancelSubscription":
url += fmt.Sprintf("/api/applications/%s/subscriptions/%s/purchases/%s/cancel/", e.Vars["packageName"], e.Vars["subscriptionId"], e.Vars["purchaseToken"])
}
if e.AcceessToken != "" {
url += "?access_token=" + e.AcceessToken
}
return url
}