Sha256: 2355e169405d491d7f379ef0f7e18898607cffec2f7b5542c13d6a9c655b056c

Contents?: true

Size: 981 Bytes

Versions: 7

Compression:

Stored size: 981 Bytes

Contents

require 'cgi'

module Whatser
  class Service < Whatser::Resource
    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 key; self.class.key; end
    
    def connection_url(params={}); self.class.connection_url(params) end
    def disconnection_url(params={}); self.class.disconnection_url(params) end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
whatser-0.6.1 lib/whatser/api/service.rb
whatser-0.6.0 lib/whatser/api/service.rb
whatser-0.5.0 lib/whatser/api/service.rb
whatser-0.4.0 lib/whatser/api/service.rb
whatser-0.3.2 lib/whatser/api/service.rb
whatser-0.3.1 lib/whatser/api/service.rb
whatser-0.3.0 lib/whatser/api/service.rb