Skip to content

Commit

Permalink
- Updated auth mechanics
Browse files Browse the repository at this point in the history
  • Loading branch information
whoisxmlapi committed May 26, 2021
1 parent cad9c77 commit 5e4b13c
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 83 deletions.
41 changes: 12 additions & 29 deletions java/src/main/java/bulkwhois/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
@Configuration
class AppConfig
{
private static final String username = "Your Bulk Whois Api username";
private static final String password = "Your Bulk Whois Api password";
private static final String apiKey = "Your Bulk Whois Api key";
private static final String format = "json";

private static final String url =
Expand All @@ -36,8 +35,7 @@ class AppConfig

public AppConfig()
{
System.setProperty(propPrefix + ".username", username);
System.setProperty(propPrefix + ".password", password);
System.setProperty(propPrefix + ".apiKey", apiKey;
System.setProperty(propPrefix + ".format", format);
System.setProperty(propPrefix + ".url", url);
}
Expand Down Expand Up @@ -116,16 +114,14 @@ public CommandLineRunner commandLineRunner(ApplicationContext ctx)
class CommonParams
{
private String outputFormat;
private String password;
private String username;
private String apiKey;

public static CommonParams create(
String username,
String password,
String apiKey,
String outputFormat
)
{
return new CommonParams(username, password, outputFormat);
return new CommonParams(apiKey, outputFormat);
}

public CommonParams()
Expand All @@ -134,13 +130,11 @@ public CommonParams()

@Autowired
public CommonParams(
@Value("${com.whoisxmlapi.bulkwhois.username}") String username,
@Value("${com.whoisxmlapi.bulkwhois.password}") String password,
@Value("${com.whoisxmlapi.bulkwhois.apiKey}") String apiKey,
@Value("${com.whoisxmlapi.bulkwhois.format}") String outputFormat
)
{
this.setUsername(username)
.setPassword(password)
this.setApiKey(apiKey)
.setOutputFormat(outputFormat);
}

Expand All @@ -149,14 +143,9 @@ public String getOutputFormat()
return outputFormat;
}

public String getPassword()
public String getApiKey()
{
return password;
}

public String getUsername()
{
return username;
return apiKey;
}

public CommonParams setOutputFormat(String outputFormat)
Expand All @@ -165,15 +154,9 @@ public CommonParams setOutputFormat(String outputFormat)
return this;
}

public CommonParams setPassword(String password)
{
this.password = password;
return this;
}

public CommonParams setUsername(String username)
public CommonParams setApiKey(String apiKey)
{
this.username = username;
this.apiKey = apiKey;
return this;
}
}
Expand Down Expand Up @@ -493,4 +476,4 @@ private HttpHeaders getHeaders()

return this.headers;
}
}
}
8 changes: 3 additions & 5 deletions js/bulk_whois_sample.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
var url = "https://www.whoisxmlapi.com/BulkWhoisLookup/bulkServices";

// Fill in your details
var username = "Your bulk whois api username";
var password = "Your bulk whois api password";
var apiKey = "Your bulk whois apiKey";

var domains = [
"google.com",
Expand All @@ -20,8 +19,7 @@

function api(path, data, callback) {
var baseData = {
password: password,
username: username,
apiKey: apiKey,
outputFormat: "json"
};

Expand Down Expand Up @@ -102,4 +100,4 @@
<div id="error"><div>
<div id="progress"></div>
<pre id="json"></pre>
</html>
</html>
14 changes: 5 additions & 9 deletions net/BulkWhoisApi/BulkWhoisApiSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
namespace BulkWhoisApi
{
public static class BulkWhoisApiSample
{
{
private static void Main()
{
//////////////////////////
// Fill in your details //
//////////////////////////
var apiClient = new BulkWhoisApi
{
Username = "Your bulk whois api username",
Password = "Your bulk whois api password",
apiKey = "Your bulk whois api key",
Url="https://www.whoisxmlapi.com/BulkWhoisLookup/bulkServices"
};

Expand Down Expand Up @@ -74,11 +73,9 @@ private static void PrintResponse(string response)

public class BulkWhoisApi
{
public string Password { get; set; }

public string Url { get; set; }

public string Username { get; set; }
public string apiKey { get; set; }

public string CreateRequest(IEnumerable<string> domains)
{
Expand Down Expand Up @@ -123,8 +120,7 @@ public int RecordsLeft(string id)
private string Post(string path, string data)
{
var baseData = $@"{{
username: '{Username}',
password: '{Password}',
apiKey: '{apiKey}',
outputFormat: 'json'
}}";

Expand Down Expand Up @@ -173,4 +169,4 @@ public static string SendPostJson(string url, string data)
return res;
}
}
}
}
8 changes: 3 additions & 5 deletions node/bulk_whois_api_sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ var fs = require('fs'), https = require('https');

var dom = ['google.com', 'youtube.com', 'facebook.com', 'whoisxmlapi.com'];
var srv = 'www.whoisxmlapi.com', url = '/BulkWhoisLookup/bulkServices/';
var username = 'Your bulk whois api username';
var pass = 'Your bulk whois api password';
var apiKey = 'Your bulk whois api key';
var file = 'bulk.csv';

function api(path, data, callback)
{
var baseData = {
password: pass,
username: username,
apiKey: apiKey,
outputFormat: 'json'
};

Expand Down Expand Up @@ -54,4 +52,4 @@ api('bulkWhois', {domains:dom}, function(body) {
});
});
}, 3000);
});
});
11 changes: 4 additions & 7 deletions perl/bulk_whois_api.pl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
########################
# Fill in your details #
########################
my $username = 'Your bulk whois api username';
my $password = 'Your bulk whois api password';
my $apiKey = 'Your bulk whois api key';

my @domains = ('google.com', 'whoisxmlapi.com');

Expand Down Expand Up @@ -56,8 +55,7 @@ sub create_request {
my $domains_str = '"' . join('", "', @domain_array) . '"';

my $data = '{
"username": "' . $username . '",
"password": "' . $password . '",
"apiKey": "' . $apiKey . '",
"outputFormat": "json",
"domains": [
'. $domains_str . '
Expand All @@ -79,8 +77,7 @@ sub get_records {
my ($id, $start, $max) = @_;

my $data = '{
"username": "' . $username . '",
"password": "' . $password . '",
"apiKey": "' . $apiKey . '",
"outputFormat": "json",
"requestId": "' . $id . '",
"startIndex": ' . $start . ',
Expand All @@ -107,4 +104,4 @@ sub post_data {
my $result = $ua->request($req);

return $result->content;
}
}
25 changes: 8 additions & 17 deletions php/bulk_whois_api_sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

namespace {
define('DOMAINS', 'google.com,youtube.com,facebook.com,gmail.com');
define('PASSWORD', 'Your Bulk Whois Api password');
define('URL', 'https://www.whoisxmlapi.com/BulkWhoisLookup/bulkServices');
define('USERNAME', 'Your Bulk Whois Api username');
define('API_KEY', 'Your Bulk Whois Api key');
}

namespace whoisxmlapi\samples\bulkwhois
Expand Down Expand Up @@ -355,25 +354,18 @@ class BulkWhoisClient extends BaseClass implements ApiClientInterface
/**
* @var string
*/
protected $_password;

/**
* @var string
*/
protected $_username;
protected $_apiKey;

/**
* BulkWhoisClient constructor.
* @param HttpClientInterface $httpClient
* @param string $username
* @param string $password
* @param string $apiKey
*/
public function __construct(
HttpClientInterface $httpClient, $username, $password)
HttpClientInterface $httpClient, $apiKey)
{
$this->_httpClient = $httpClient;
$this->_username = $username;
$this->_password = $password;
$this->_apiKey = $apiKey;
}

/**
Expand Down Expand Up @@ -415,8 +407,7 @@ public function getRecords($requestId, $startIndex=1, $maxRecords=10)
protected function _callApi($path, array $data)
{
$params = array(
'username' => $this->_username,
'password' => $this->_password,
'apiKey' => $this->_apiKey,
'outputFormat' => static::OUTPUT
);

Expand Down Expand Up @@ -515,7 +506,7 @@ public function post($path, $content, $header='')

whoisxmlapi\samples\bulkwhois\ApiClientInterface::CLASS_NAME => array(
whoisxmlapi\samples\bulkwhois\BulkWhoisClient::className()=>array(
'password' => @PASSWORD, 'username' => @USERNAME
'apiKey' => @apiKey
)
),
'example' => array(
Expand All @@ -529,4 +520,4 @@ public function post($path, $content, $header='')
);

(new AppBulkWhois($config))->boot()->make('example')->run();
}
}
11 changes: 4 additions & 7 deletions powershell/bulk_whois_api.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ $url = 'https://www.whoisxmlapi.com/BulkWhoisLookup/bulkServices'
# Fill in your details #
########################

$username = 'Your bulk whois api username'
$password = 'Your bulk whois api password'
$apiKey = 'Your bulk whois api key'

$domains = @('google.com', 'whoisxmlapi.com')

Expand All @@ -16,8 +15,7 @@ function Bulk-Whois-Json-Post ($Path, $Body) {

function Create-Bulk-Whois-Request ([string[]] $Domains) {
$body = @{
username = $username
password = $password
apiKey = $apiKey
outputFormat = 'json'
domains = $Domains
} | ConvertTo-Json
Expand All @@ -34,8 +32,7 @@ function Create-Bulk-Whois-Request ([string[]] $Domains) {

function Get-Bulk-Whois-Records ($Id, $Start, $Max) {
$body = @{
username = $username
password = $password
apiKey = $apiKey
outputFormat = 'json'
requestId = $Id
startIndex = $Start
Expand Down Expand Up @@ -71,4 +68,4 @@ echo 'Downloading data...'

$records = (Get-Bulk-Whois-Records $id 1 $domains.Count).whoisRecords

echo $records | ConvertTo-Json -depth 10
echo $records | ConvertTo-Json -depth 10
6 changes: 2 additions & 4 deletions python/bulk_whois_api_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

# Preparing arguments
argparser = ArgumentParser(description='BulkWhois querry')
argparser.add_argument('-u', '--username', help='Your bulk whois username', type=str, required=True)
argparser.add_argument('-p', '--password', help='Your bulk whois password', type=str, required=True)
argparser.add_argument('-u', '--apiKey', help='Your bulk whois api key', type=str, required=True)
argparser.add_argument('-d', '--domains', help='list of domains separated by spaces',
type=str, nargs='+', required=True)
argparser.add_argument('--interval', help='requesting interval', type=int, default=15)
Expand All @@ -30,8 +29,7 @@

data = {
"domains": args.domains,
"password": args.password,
"username": args.username,
"apiKey": args.apiKey,
"outputFormat": args.format
}

Expand Down

0 comments on commit 5e4b13c

Please sign in to comment.