Skip to content

Commit 851fa4b

Browse files
Merge pull request #86 from tolu-paystack/feat/add-pagination
add code snippets for pagination
2 parents 5b7ff22 + 7759feb commit 851fa4b

File tree

16 files changed

+297
-0
lines changed

16 files changed

+297
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const json = `{
2+
"meta": {
3+
"next": "dW5kZWZpbmVkOjQwOTczNTgxNTg=",
4+
"previous": "null",
5+
"perPage": 49
6+
}
7+
}
8+
`
9+
10+
export {json}

dist/api/pagination/cursor-request.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const js = `const https = require('https')
2+
3+
const options = {
4+
hostname: 'api.paystack.co',
5+
port: 443,
6+
path: '/transaction?use_cursor=true&perPage=50',
7+
method: 'GET',
8+
headers: {
9+
Authorization: 'Bearer YOUR_SECRET_KEY'
10+
}
11+
}
12+
13+
https.request(options, res => {
14+
let data = ''
15+
16+
res.on('data', (chunk) => {
17+
data += chunk
18+
});
19+
20+
res.on('end', () => {
21+
console.log(JSON.parse(data))
22+
})
23+
}).on('error', error => {
24+
console.error(error)
25+
})`
26+
27+
const php = `<?php
28+
$curl = curl_init();
29+
30+
curl_setopt_array($curl, array(
31+
CURLOPT_URL => "https://api.paystack.co/transaction?use_cursor=true&perPage=50",
32+
CURLOPT_RETURNTRANSFER => true,
33+
CURLOPT_ENCODING => "",
34+
CURLOPT_MAXREDIRS => 10,
35+
CURLOPT_TIMEOUT => 30,
36+
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
37+
CURLOPT_CUSTOMREQUEST => "GET",
38+
CURLOPT_HTTPHEADER => array(
39+
"Authorization: Bearer YOUR_SECRET_KEY",
40+
"Cache-Control: no-cache",
41+
),
42+
));
43+
44+
$response = curl_exec($curl);
45+
$err = curl_error($curl);
46+
47+
curl_close($curl);
48+
49+
if ($err) {
50+
echo "cURL Error #:" . $err;
51+
} else {
52+
echo $response;
53+
}
54+
?>`
55+
56+
const sh = `#!/bin/sh
57+
url="https://api.paystack.co/transaction?use_cursor=true&perPage=50"
58+
authorization="Authorization: Bearer YOUR_SECRET_KEY"
59+
60+
curl "$url" -H "$authorization" -X GET`
61+
62+
export {js, php, sh}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const json = `{
2+
"meta": {
3+
"total": 7316,
4+
"total_volume": 397800,
5+
"skipped": 0,
6+
"perPage": 50,
7+
"page": 1,
8+
"pageCount": 147
9+
}
10+
}
11+
`
12+
13+
export {json}

dist/api/pagination/offset-request.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const js = `const https = require('https')
2+
3+
const options = {
4+
hostname: 'api.paystack.co',
5+
port: 443,
6+
path: '/transaction?page=1&perPage=50',
7+
method: 'GET',
8+
headers: {
9+
Authorization: 'Bearer SECRET_KEY'
10+
}
11+
}
12+
13+
https.request(options, res => {
14+
let data = ''
15+
16+
res.on('data', (chunk) => {
17+
data += chunk
18+
});
19+
20+
res.on('end', () => {
21+
console.log(JSON.parse(data))
22+
})
23+
}).on('error', error => {
24+
console.error(error)
25+
})`
26+
27+
const php = `<?php
28+
$curl = curl_init();
29+
30+
curl_setopt_array($curl, array(
31+
CURLOPT_URL => "https://api.paystack.co/transaction?page=1&perPage=50",
32+
CURLOPT_RETURNTRANSFER => true,
33+
CURLOPT_ENCODING => "",
34+
CURLOPT_MAXREDIRS => 10,
35+
CURLOPT_TIMEOUT => 30,
36+
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
37+
CURLOPT_CUSTOMREQUEST => "GET",
38+
CURLOPT_HTTPHEADER => array(
39+
"Authorization: Bearer SECRET_KEY",
40+
"Cache-Control: no-cache",
41+
),
42+
));
43+
44+
$response = curl_exec($curl);
45+
$err = curl_error($curl);
46+
47+
curl_close($curl);
48+
49+
if ($err) {
50+
echo "cURL Error #:" . $err;
51+
} else {
52+
echo $response;
53+
}
54+
?>`
55+
56+
const sh = `#!/bin/sh
57+
url="https://api.paystack.co/transaction?page=1&perPage=50"
58+
authorization="Authorization: Bearer YOUR_SECRET_KEY"
59+
60+
curl "$url" -H "$authorization" -X GET`
61+
62+
export {js, php, sh}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type: standalone
2+
languages:
3+
- json
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"meta": {
3+
"next": "dW5kZWZpbmVkOjQwOTczNTgxNTg=",
4+
"previous": "null",
5+
"perPage": 49
6+
}
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type: standalone
2+
languages:
3+
- js
4+
- php
5+
- sh
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const https = require('https')
2+
3+
const options = {
4+
hostname: 'api.paystack.co',
5+
port: 443,
6+
path: '/transaction?use_cursor=true&perPage=50',
7+
method: 'GET',
8+
headers: {
9+
Authorization: 'Bearer YOUR_SECRET_KEY'
10+
}
11+
}
12+
13+
https.request(options, res => {
14+
let data = ''
15+
16+
res.on('data', (chunk) => {
17+
data += chunk
18+
});
19+
20+
res.on('end', () => {
21+
console.log(JSON.parse(data))
22+
})
23+
}).on('error', error => {
24+
console.error(error)
25+
})
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
$curl = curl_init();
3+
4+
curl_setopt_array($curl, array(
5+
CURLOPT_URL => "https://api.paystack.co/transaction?use_cursor=true&perPage=50",
6+
CURLOPT_RETURNTRANSFER => true,
7+
CURLOPT_ENCODING => "",
8+
CURLOPT_MAXREDIRS => 10,
9+
CURLOPT_TIMEOUT => 30,
10+
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
11+
CURLOPT_CUSTOMREQUEST => "GET",
12+
CURLOPT_HTTPHEADER => array(
13+
"Authorization: Bearer YOUR_SECRET_KEY",
14+
"Cache-Control: no-cache",
15+
),
16+
));
17+
18+
$response = curl_exec($curl);
19+
$err = curl_error($curl);
20+
21+
curl_close($curl);
22+
23+
if ($err) {
24+
echo "cURL Error #:" . $err;
25+
} else {
26+
echo $response;
27+
}
28+
?>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
url="https://api.paystack.co/transaction?use_cursor=true&perPage=50"
3+
authorization="Authorization: Bearer YOUR_SECRET_KEY"
4+
5+
curl "$url" -H "$authorization" -X GET
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# TODO: Work on handling multiple non-response JSON
2+
type: standalone
3+
languages:
4+
- json
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"meta": {
3+
"total": 7316,
4+
"total_volume": 397800,
5+
"skipped": 0,
6+
"perPage": 50,
7+
"page": 1,
8+
"pageCount": 147
9+
}
10+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type: standalone
2+
languages:
3+
- js
4+
- php
5+
- sh
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const https = require('https')
2+
3+
const options = {
4+
hostname: 'api.paystack.co',
5+
port: 443,
6+
path: '/transaction?page=1&perPage=50',
7+
method: 'GET',
8+
headers: {
9+
Authorization: 'Bearer SECRET_KEY'
10+
}
11+
}
12+
13+
https.request(options, res => {
14+
let data = ''
15+
16+
res.on('data', (chunk) => {
17+
data += chunk
18+
});
19+
20+
res.on('end', () => {
21+
console.log(JSON.parse(data))
22+
})
23+
}).on('error', error => {
24+
console.error(error)
25+
})
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
$curl = curl_init();
3+
4+
curl_setopt_array($curl, array(
5+
CURLOPT_URL => "https://api.paystack.co/transaction?page=1&perPage=50",
6+
CURLOPT_RETURNTRANSFER => true,
7+
CURLOPT_ENCODING => "",
8+
CURLOPT_MAXREDIRS => 10,
9+
CURLOPT_TIMEOUT => 30,
10+
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
11+
CURLOPT_CUSTOMREQUEST => "GET",
12+
CURLOPT_HTTPHEADER => array(
13+
"Authorization: Bearer SECRET_KEY",
14+
"Cache-Control: no-cache",
15+
),
16+
));
17+
18+
$response = curl_exec($curl);
19+
$err = curl_error($curl);
20+
21+
curl_close($curl);
22+
23+
if ($err) {
24+
echo "cURL Error #:" . $err;
25+
} else {
26+
echo $response;
27+
}
28+
?>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
url="https://api.paystack.co/transaction?page=1&perPage=50"
3+
authorization="Authorization: Bearer YOUR_SECRET_KEY"
4+
5+
curl "$url" -H "$authorization" -X GET

0 commit comments

Comments
 (0)