lib/whatser/api/service.rb in whatser-0.2.0 vs lib/whatser/api/service.rb in whatser-0.3.0

- old
+ new

@@ -1,15 +1,35 @@ +require 'cgi' + module Whatser class Service < Whatser::Resource - def key - self.class.name.split('::').last.downcase + class << self + def key + self.name.split('::').last.downcase + end + + def connection_url(params={}) + "#{client.api_uri}/oauth/services/#{key}/authorize?#{connection_querystring(params)}" + end + + def disconnection_url(params={}) + "#{client.api_uri}/oauth/services/#{key}/disconnect" + end + + def connection_querystring(params={}) + auth_params( params ).map{|k,v| "#{CGI.escape( (k || '').to_s )}=#{CGI.escape( (v || '').to_s )}"}.join('&') + end + + def auth_params(params={}) + { + :client_id => client.api_key, + :redirect_uri => client.redirect_uri + }.merge( params ) + end end - def connection_url - "#{client.api_uri}/oauth/services/#{key}/authorize" - end + def key; self.class.key; end - def disconnection_url - "#{client.api_uri}/oauth/services/#{key}/disconnect" - end + def connection_url(params={}); self.class.connection_url(params) end + def disconnection_url(params={}); self.class.disconnection_url(params) end end end \ No newline at end of file