Last active
August 29, 2015 14:04
-
-
Save funzoneq/7226d81e271e5f6f86d3 to your computer and use it in GitHub Desktop.
Login for LeasewebCDN API
This file contains 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
#!/usr/bin/env ruby | |
require 'digest/sha1' | |
require 'httparty' | |
require 'pp' | |
api_key = '0bf62365d36d6114ea546e47f3d0c9ecf57c2de9' | |
customer_number = '140760000' | |
class LeasewebCDN | |
include HTTParty | |
debug_output $stderr | |
base_uri 'https://api.leasewebcdn.com' | |
def initialize (key, customerNumber) | |
@key = key | |
@customerNumber = customerNumber.to_s | |
end | |
def create_url (path) | |
path = path.gsub("#customerNumber", @customerNumber) | |
timestamp = Time.now.utc.to_i.to_s | |
signature = Digest::SHA1.hexdigest("#{@key}#{timestamp}#{path}") | |
return "#{path}/#{timestamp}/#{signature}" | |
end | |
def pull_zone (zoneID = 'all') | |
self.class.get create_url("/zones/pull/#customerNumber/#{zoneID}") | |
end | |
def version | |
self.class.get create_url("/version") | |
end | |
end | |
l = LeasewebCDN.new(api_key, customer_number) | |
pp l.version | |
pp l.pull_zone |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment