Skip to content

Commit

Permalink
Changed a lot...
Browse files Browse the repository at this point in the history
πŸ“ **Changelog: Version X.X.X**

πŸ”ƒ **Enhancements:**
- ✨ Upgraded to the latest approach for handling post requests, which now support both JSON and x-www-form-urlencoded formats.
- βž• Implemented extensive error handling capabilities to improve overall stability.
- πŸ“š Updated JSDocs for all methods, enhancing code documentation and clarity.
- ⚑️ Automatically converts sessionId to session, ensuring smooth updates without major disruptions.
- βž• Added new parameters to enhance functionality and customization options.
- βž• Introduced three new methods: `validCookies()`, `isJSON()`, and `isFormData()`, providing additional utility.
- ⏰ Extended timeout duration to allow sufficient waiting time for response handling.

πŸ”€ **Other Changes:**
- πŸ“ˆ Various performance optimizations and bug fixes to improve overall reliability.
- πŸ”„ Minor code refactoring and improvements for better maintainability.

🌟 **And more exciting updates!**
  • Loading branch information
DemonMartin committed Jun 22, 2023
1 parent 78aba2e commit 816ed4b
Show file tree
Hide file tree
Showing 5 changed files with 795 additions and 131 deletions.
131 changes: 131 additions & 0 deletions countries.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
[
"UnitedStates",
"Canada",
"Afghanistan",
"Albania",
"Algeria",
"Argentina",
"Armenia",
"Aruba",
"Australia",
"Austria",
"Azerbaijan",
"Bahamas",
"Bahrain",
"Bangladesh",
"Belarus",
"Belgium",
"BosniaandHerzegovina",
"Brazil",
"BritishVirginIslands",
"Brunei",
"Bulgaria",
"Cambodia",
"Cameroon",
"Canada",
"Chile",
"China",
"Colombia",
"CostaRica",
"Croatia",
"Cuba",
"Cyprus",
"Czechia",
"Denmark",
"DominicanRepublic",
"Ecuador",
"Egypt",
"ElSalvador",
"Estonia",
"Ethiopia",
"Finland",
"France",
"Georgia",
"Germany",
"Ghana",
"Greece",
"Guatemala",
"Guyana",
"HashemiteKingdomofJordan",
"HongKong",
"Hungary",
"India",
"Indonesia",
"Iran",
"Iraq",
"Ireland",
"Israel",
"Italy",
"Jamaica",
"Japan",
"Kazakhstan",
"Kenya",
"Kosovo",
"Kuwait",
"Latvia",
"Liechtenstein",
"Luxembourg",
"Macedonia",
"Madagascar",
"Malaysia",
"Mauritius",
"Mexico",
"Mongolia",
"Montenegro",
"Morocco",
"Mozambique",
"Myanmar",
"Nepal",
"Netherlands",
"NewZealand",
"Nigeria",
"Norway",
"Oman",
"Pakistan",
"Palestine",
"Panama",
"PapuaNewGuinea",
"Paraguay",
"Peru",
"Philippines",
"Poland",
"Portugal",
"PuertoRico",
"Qatar",
"RepublicofLithuania",
"RepublicofMoldova",
"Romania",
"Russia",
"SaudiArabia",
"Senegal",
"Serbia",
"Seychelles",
"Singapore",
"Slovakia",
"Slovenia",
"Somalia",
"SouthAfrica",
"SouthKorea",
"Spain",
"SriLanka",
"Sudan",
"Suriname",
"Sweden",
"Switzerland",
"Syria",
"Taiwan",
"Tajikistan",
"Thailand",
"TrinidadandTobago",
"Tunisia",
"Turkey",
"Uganda",
"Ukraine",
"UnitedArabEmirates",
"UnitedKingdom",
"UnitedStates",
"Uzbekistan",
"Venezuela",
"Vietnam",
"Zambia"
]
65 changes: 65 additions & 0 deletions example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const Scrappey = require('.');

// Replace 'YOUR_API_KEY' with your Scrappey API key
const apiKey = 'YOUR_API_KEY';

// Create an instance of Scrappey
const scrappey = new Scrappey(apiKey);

function getQueryString(object) {
const queryString = Object.keys(object)
.map(key => encodeURIComponent(key) + '=' + encodeURIComponent(object[key]))
.join('&');
return queryString;
}

async function run() {
try {
// Create a session
const sessionRequest = await scrappey.createSession();
const { session } = sessionRequest;

console.log('Created Session:', session);

// Make a GET request
const getRequestResult = await scrappey.getRequest({
url: 'https://reqres.in/api/users',
session,
});
console.log('GET Request Result:', getRequestResult);

// Make a POST request using FormData
const postFormData = { username: 'user123', password: 'pass456' };
const postRequestResultForm = await scrappey.postRequest({
url: 'https://reqres.in/api/users',
postData: getQueryString(postFormData),
session
});
console.log('POST Request Result (FormData):', postRequestResultForm);

// Make a POST request using JSON data
const postJsonData = { email: 'user@example.com', password: 'pass123' };
const postRequestResultJson = await scrappey.postRequest({
url: 'https://reqres.in/api/users',
postData: JSON.stringify(postJsonData),
headers: {
'Content-Type': 'application/json', // Optional. To avoid issues please still add if you send JSON Data.
},
session,
// customHeaders: {
// "auth": "token"
// },
// proxyCountry: "UnitedStates"
// & more!
});
console.log('POST Request Result (JSON):', postRequestResultJson);

// Manually destroy the session (automatically destroys after 4 minutes)
await scrappey.destroySession(session);
console.log('Session destroyed.');
} catch (error) {
console.error(error);
}
}

run();
Loading

0 comments on commit 816ed4b

Please sign in to comment.