Last active
August 29, 2015 14:12
-
-
Save weirdbricks/1fc0b7563a14fcbbdcaa to your computer and use it in GitHub Desktop.
atlantic.net describe instances in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Lampros Chaidas | |
## 01/01/2015 | |
## Sample code to list instances from Atlantic.net using Ruby | |
# tested with Ruby 1.9.3 | |
require 'rest_client' | |
require 'digest' | |
require 'uuidtools' | |
# replace with your access key | |
ACSAccessKeyId = "replace-with-your-access-key" | |
# replace with your private key | |
api_private_key = "replace-with-your-private-key" | |
# get the current time in unix epoch i.e. 1420184854 | |
current_time = Time.now.to_i | |
# get a GUID | |
Rndguid = UUIDTools::UUID.random_create.to_s | |
# concatenate the random GUID to the end of the timestamp - the result should look like this: | |
string_to_sign = current_time.to_s + Rndguid | |
# Use the api private key to create a SHA256 hash and Base64 encode the whole thing | |
signature = Digest::HMAC.base64digest(string_to_sign, api_private_key, Digest::SHA256) | |
# set the action you want to use | |
action = "list-instances" | |
# got the URI from http://kb.atlantic.net/api-methods-php-example/ | |
uri = "https://cloudapi.atlantic.net/api.php" | |
response = RestClient.post( | |
uri, | |
'Version' => '2010-12-30', | |
'ACSAccessKeyId' => ACSAccessKeyId, | |
'Format' => 'json', | |
'Timestamp' => current_time, | |
'Rndguid' => Rndguid, | |
'Signature' => signature, | |
'Action' => action) | |
puts response | |
puts response.code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment