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.6') ⇒ 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.6') ⇒ GoGridClient
Returns a new instance of GoGridClient.
7 8 9 10 11 12 13 14 15 |
# File 'lib/deltacloud/drivers/gogrid/gogrid_client.rb', line 7 def initialize(server='https://api.gogrid.com/api', apikey='YOUR API KEY', secret='YOUR SHARED SECRET', format='json', version='1.6') @server = server @secret = secret @default_params = {'format'=>format, 'v'=>version,'api_key' => apikey} end |
Instance Method Details
#encode_params(params) ⇒ Object
42 43 44 |
# File 'lib/deltacloud/drivers/gogrid/gogrid_client.rb', line 42 def encode_params(params) params.map {|k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}" }.join("&") end |
#getRequestURL(method, params) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/deltacloud/drivers/gogrid/gogrid_client.rb', line 17 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
24 25 26 |
# File 'lib/deltacloud/drivers/gogrid/gogrid_client.rb', line 24 def getSignature(key,secret) Digest::MD5.hexdigest(key+secret+"%.0f"%Time.new.to_f) end |
#request(method, params = {}, version = nil) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/deltacloud/drivers/gogrid/gogrid_client.rb', line 32 def request(method, params={}, version=nil) if version @default_params['v'] = version else @default_params['v'] = '1.5' end request = sendAPIRequest(method, params) JSON::parse(request) end |
#sendAPIRequest(method, params = {}) ⇒ Object
28 29 30 |
# File 'lib/deltacloud/drivers/gogrid/gogrid_client.rb', line 28 def sendAPIRequest(method,params={}) open(getRequestURL(method,params)).read end |