lib/sk_sdk/oauth.rb in sk_sdk-0.3.0 vs lib/sk_sdk/oauth.rb in sk_sdk-0.4.0

- old
+ new

@@ -14,11 +14,11 @@ # # @param[Hash{String=>String}] opts containing id, secrete, scope, url of # your app # @option [String] id oAuth app id from SalesKing app registration # @option [String] secret oAuth app secret from SalesKing app registration - # @option [String] scope permission your app requests + # @option [String|Array[String]] permission scopes for your app requests # @option [String] redirect_url inside your app for auth dialog # @option [String] sk_url SalesKing base url, * is replaced with users subdomain, # no trailing slash, optional defaults to https://*.salesking.eu # @option [String] sub_domain optional, will probably be set later after a users # provided his subdomain @@ -32,13 +32,14 @@ @sub_domain = opts['sub_domain'] end # @return [String] URL with parameter to show the auth dialog to the user def auth_dialog + scope_string = Array === @scope ? @scope.join(' ') : @scope params = { :client_id => @id, :redirect_uri=> @redirect_url, - :scope => @scope } + :scope => scope_string } "#{sk_url}/oauth/authorize?#{to_url_params(params)}" end # @return [String] app's canvas url inside SalesKing def sk_canvas_url @@ -86,12 +87,10 @@ def sk_url @sk_url.gsub('*', sub_domain).gsub(/\/\z/, '' ) end def to_url_params(params_hash) - out = [] - params_hash.each { |k,v| out << "#{CGI::escape k.to_s}=#{CGI::escape v.to_s}" } - out.join('&') + params_hash.map { |k,v| "#{CGI::escape k.to_s}=#{CGI::escape v.to_s}" }.join('&') end end -end \ No newline at end of file +end