Class: GoGridClient
- Inherits:
-
Object
- Object
- GoGridClient
- Defined in:
- lib/deltacloud/drivers/gogrid/gogrid_client.rb
Instance Method Summary collapse
- #encode_params(params) ⇒ Object
- #getRequestURL(method, params) ⇒ Object
- #getSignature(key, secret) ⇒ Object
-
#initialize(server = 'https://api.gogrid.com/api', apikey = 'YOUR API KEY', secret = 'YOUR SHARED SECRET', format = 'json', version = '1.5') ⇒ GoGridClient
constructor
A new instance of GoGridClient.
- #request(method, params = {}, version = nil) ⇒ Object
- #sendAPIRequest(method, params = {}) ⇒ Object
Constructor Details
#initialize(server = 'https://api.gogrid.com/api', apikey = 'YOUR API KEY', secret = 'YOUR SHARED SECRET', format = 'json', version = '1.5') ⇒ GoGridClient
Returns a new instance of GoGridClient.
8 9 10 11 12 13 14 15 16 |
# File 'lib/deltacloud/drivers/gogrid/gogrid_client.rb', line 8 def initialize(server='https://api.gogrid.com/api', apikey='YOUR API KEY', secret='YOUR SHARED SECRET', format='json', version='1.5') @server = server @secret = secret @default_params = {'format'=>format, 'v'=>version,'api_key' => apikey} end |
Instance Method Details
#encode_params(params) ⇒ Object
46 47 48 |
# File 'lib/deltacloud/drivers/gogrid/gogrid_client.rb', line 46 def encode_params(params) params.map {|k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}" }.join("&") end |
#getRequestURL(method, params) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/deltacloud/drivers/gogrid/gogrid_client.rb', line 18 def getRequestURL(method,params) requestURL = @server+'/'+method+'?' call_params = @default_params.merge(params) call_params['sig']=getSignature(@default_params['api_key'],@secret) requestURL = requestURL+encode_params(call_params) end |
#getSignature(key, secret) ⇒ Object
25 26 27 |
# File 'lib/deltacloud/drivers/gogrid/gogrid_client.rb', line 25 def getSignature(key,secret) Digest::MD5.hexdigest(key+secret+"%.0f"%Time.new.to_f) end |
#request(method, params = {}, version = nil) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/deltacloud/drivers/gogrid/gogrid_client.rb', line 33 def request(method, params={}, version=nil) if version @default_params['v'] = version else @default_params['v'] = '1.5' end begin JSON::parse(sendAPIRequest(method, params)) rescue Exception => e STDERR.puts("ERROR: #{e.}") end end |
#sendAPIRequest(method, params = {}) ⇒ Object
29 30 31 |
# File 'lib/deltacloud/drivers/gogrid/gogrid_client.rb', line 29 def sendAPIRequest(method,params={}) open(getRequestURL(method,params)).read end |