-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample-charis-api-partners-facetofeet.html
219 lines (215 loc) · 6.98 KB
/
example-charis-api-partners-facetofeet.html
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<html>
<head>
<meta name=viewport content="width=device-width,user-scalable=no,minimal-ui">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script type="text/javascript" src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/core.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/md5.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/enc-base64.min.js"></script>
<style type="text/css">
.form-group .form-control+.form-control {
margin-top: 0.5em;
}
#response {
background-color: #f2f2f2;
padding: 20px 0;
}
.charis-sg-item {
position: relative;
background-color: #fff;
margin: 0 15px 25px 15px;
padding: 15px 15px 10px;
box-shadow: 4px 3px 5px 0 rgba(0, 0, 0, 0.1);
-webkit-box-shadow: 4px 3px 5px 0 rgba(0, 0, 0, 0.1);
}
.charis-sg-item a {
text-decoration: none;
}
.charis-sg-item-content {
position: relative;
padding-left: 103px;
min-height: 100px;
font-size: 14px;
}
.charis-sg-thumb {
position: absolute;
top: 0;
left: 0;
width: 95px;
height: 95px;
}
.charis-sg-thumb img {
width: 95px;
height: 95px;
}
.charis-sg-discount {
position: absolute;
top: 77px;
left: 0;
width: 95px;
height: 18px;
line-height: 18px;
padding: 0;
color: #fff;
text-align: center;
font-size: 12px;
font-weight: bold;
background-color: #000;
}
.charis-sg-meta-brand,
.charis-sg-meta-brand a {
color: #777;
font-size: 11px;
}
.charis-sg-meta-name,
.charis-sg-meta-name a {
color: #121314;
font-weight: bold;
overflow: hidden;
}
.charis-sg-price {
position: absolute;
bottom: 0;
}
.charis-sg-price-fixed {
color: #777;
text-decoration: line-through;
}
.charis-sg-price-sale {
color: #d0011b;
font-size: 18px;
font-weight: bold;
}
</style>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-12 col-md-6">
<h2>Parameters</h2>
<form id="frm">
<div class="form-group">
<label>Number of page</label>
<input type="text" name="page" class="form-control" value="1">
</div>
<div class="form-group">
<label>Number of results returned</label>
<input type="text" name="limit" class="form-control" value="5">
</div>
<div class="form-group">
<label>Language Code</label>
<input type="text" name="lang" class="form-control" value="en">
</div>
<div class="form-group">
<label>Category Code</label>
<input type="text" name="category" class="form-control" value="CAHJEGQMOS">
</div>
<div class="form-group">
<label>Seller uid</label>
<input type="text" name="seller_id" class="form-control" value="US57933191Ekdo9EkTx" placeholder="USXXX">
<input type="text" name="seller_id" class="form-control" value="" placeholder="USXXX">
</div>
<div class="form-group">
<label>Sale item url</label>
<input type="text" name="url" class="form-control" value="" placeholder="https://hicharis.net/charis/2Lq">
<input type="text" name="url" class="form-control" value="" placeholder="https://hicharis.net/charis/3ns">
</div>
<button type="submit" class="btn btn-primary">Search</button>
</form>
</div>
<div class="col-12 col-md-6">
<h2>Response</h2>
<div id="response"></div>
</div>
</div>
</div>
<script type="text/javascript">
var charis = {
api: {
ENDPOINT: 'https://api.hicharis.net',
basicToken: function () {
var client = {
id: '__CLIENT_ID__',
secret: '__CLIENT_SECRET__'
}
var ts = Date.now()
var secret = CryptoJS.MD5(client.secret + ts)
var token = CryptoJS.enc.Base64.stringify(
CryptoJS.enc.Utf8.parse([client.id, secret, ts].join(':'))
)
return token
}
},
tpl: {
salegoods: function (o) {
var url = o.url + '?utm_source=facetofeet&utm_medium=article&utm_campaign=partners'
return [
'<div class="charis-sg-item">',
'<div class="charis-sg-item-content">',
'<div class="charis-sg-thumb"><a href="', url, '"><img src="', o.thumb_img + '"></a></div>',
o.discount_rate > 0 ? '<div class="charis-sg-discount">' + o.discount_rate + '% OFF</div>' : '',
'<div class="charis-sg-meta">',
'<div class="charis-sg-meta-brand"><a href="', url, '">', o.meta.brand, '</a></div>',
'<div class="charis-sg-meta-name"><a href="', url, '">', o.meta.name, '</a></div>',
'</div>', // charis-sg-meta
'<div class="charis-sg-price">',
o.discount_rate > 0 ? '<div class="charis-sg-price-fixed">' + charis.currency.USD(o.fixed_price) + '</div>' : '',
'<div class="charis-sg-price-sale">' + charis.currency.USD(o.price) + '</div>',
'</div>', // charis-sg-price
'</div>', // charis-sg-item-content
'</div>' // charis-sg-item
].join('')
}
},
currency: {
USD: function (v) {
return '$ ' + Number(v).toFixed(2)
}
}
}
$(document.body).ready(function () {
var $frm = $('#frm')
$frm.submit(function () {
var page = $frm.find('input[name=page]').val()
var limit = $frm.find('input[name=limit]').val()
var lang = $frm.find('input[name=lang]').val()
var currency = 'USD'
var filter = {
category: $frm.find('input[name=category]').val(),
seller_id: [],
url: []
}
// set seller_id
$frm.find('input[name=seller_id]').each(function (idx, el) {
$(el).val() && filter.seller_id.push($(el).val())
})
$frm.find('input[name=url]').each(function (idx, el) {
$(el).val() && filter.url.push($(el).val())
})
$.ajax({
url: charis.api.ENDPOINT + '/v1/partners/facetofeet/salegoods?' + [
'page=' + page,
'limit=' + limit,
'lang=' + lang,
'currency=' + currency,
'filter=' + JSON.stringify(filter)
].join('&'),
headers: {
Authorization: ['Basic', charis.api.basicToken()].join(' ')
},
json: true,
success: function (res) {
var html = []
for (var i = 0, len = res.result.saleGoods.length; i < len; i++) {
html.push(charis.tpl.salegoods(res.result.saleGoods[i]))
}
$('#response').html(html.join(''))
}
})
return false
})
$frm.submit()
})
</script>
</body>
</html>