-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproxies-example.js
More file actions
125 lines (105 loc) · 3.12 KB
/
Copy pathproxies-example.js
File metadata and controls
125 lines (105 loc) · 3.12 KB
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
/**
* Scrapeless Node SDK - Proxies Service Example (ES Module Version)
*
* This example demonstrates how to use the ProxiesService to generate and work
* with residential proxies.
*/
import { ScrapelessClient } from '@scrapeless-ai/sdk';
// Initialize the client
const client = new ScrapelessClient({
apiKey: process.env.SCRAPELESS_API_KEY || 'your_api_key_here'
});
/**
* Test creating a proxy with specific parameters
*/
async function testCreateProxy() {
try {
console.log('Testing proxy creation with specific parameters...');
const proxyUrl = client.proxies.proxy({
type: 'residential',
country: 'US',
state: 'KS',
city: 'gardner',
sessionDuration: 30,
sessionId: 'test-session-123',
gateway: 'gate.smartproxy.com:7000'
});
console.log('✅ Proxy URL generated successfully');
console.log('Proxy URL:', proxyUrl);
return proxyUrl;
} catch (error) {
console.error('❌ Proxy creation failed:', error.message);
throw error;
}
}
/**
* Test creating a proxy with the createProxy method
*/
async function testCreateProxyAlias() {
try {
console.log('Testing createProxy alias method...');
const proxyUrl = client.proxies.createProxy({
type: 'ipv6',
country: 'UK',
sessionDuration: 60,
sessionId: 'test-session-456',
gateway: 'gate.smartproxy.com:7000'
});
console.log('✅ Proxy URL generated successfully using createProxy');
console.log('Proxy URL:', proxyUrl);
return proxyUrl;
} catch (error) {
console.error('❌ createProxy method failed:', error.message);
throw error;
}
}
/**
* Test generating a session ID
*/
async function testGenerateSessionId() {
try {
console.log('Testing session ID generation...');
const sessionId = client.proxies.generateSessionId();
console.log('✅ Session ID generated successfully');
console.log('Session ID:', sessionId);
// Create a proxy with the generated session ID
const proxyUrl = client.proxies.proxy({
type: 'ipv6',
country: 'JP',
sessionDuration: 15,
sessionId: sessionId,
gateway: 'gate.smartproxy.com:7000'
});
console.log('Created proxy with generated session ID:', proxyUrl);
return { sessionId, proxyUrl };
} catch (error) {
console.error('❌ Session ID generation failed:', error.message);
throw error;
}
}
/**
* Run all tests
*/
async function runTests() {
console.log('=== Scrapeless Proxies Service Tests ===\n');
try {
// Test proxy creation
await testCreateProxy();
console.log('\n');
// Test createProxy alias
await testCreateProxyAlias();
console.log('\n');
// Test session ID generation
await testGenerateSessionId();
console.log('\n');
console.log('🎉 All tests completed successfully');
} catch (error) {
console.error('❌ Tests failed with error:', error);
}
}
// Run the tests
runTests().catch(console.error);
// To run individual tests, uncomment the desired test:
// testCreateProxy().catch(console.error);
// testCreateProxyAlias().catch(console.error);
// testGenerateSessionId().catch(console.error);