Sha256: 6e86c5a21a2250fe9725cb99f35e1040d591828d354b2987194c40ef892cceb1
Contents?: true
Size: 1.26 KB
Versions: 15
Compression:
Stored size: 1.26 KB
Contents
require 'digest/md5' require 'cgi' require 'open-uri' require 'json' class GoGridClient 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 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 def getSignature(key,secret) Digest::MD5.hexdigest(key+secret+"%.0f"%Time.new.to_f) end def sendAPIRequest(method,params={}) open(getRequestURL(method,params)).read end 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.message}") end end def encode_params(params) params.map {|k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}" }.join("&") end end
Version data entries
15 entries across 15 versions & 3 rubygems