Top Level Namespace

Defined Under Namespace

Modules: Lasso

Instance Method Summary collapse

Instance Method Details

#define_oauth_one(parent) ⇒ Object



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/lasso/model/oauth_one.rb', line 1

def define_oauth_one(parent)
  eval <<OAUTHONE
    class OAuthOne#{parent} < #{parent}

      alias_attribute :oauth_token,        :token_a
      alias_attribute :oauth_token_secret, :token_b

      validates_presence_of :oauth_token, :oauth_token_secret

      def consumer
        @consumer ||= OAuth::Consumer.new(config(:key), config(:secret), :site => config(:site), :request_token_path => config(:request_token_path), :authorize_path => config(:authorize_path), :access_token_path => config(:access_token_path))
      end

      def client
        @client ||= case service
          when 'linkedin'
            LinkedIn::Client.new(config(:key), config(:secret))
          when 'twitter'
            Twitter::OAuth.new(config(:key), config(:secret))
        end
      end

      def access
        unless @access
          client.authorize_from_access(oauth_token, oauth_token_secret)
          @access ||= case service
            when 'linkedin'
              client
            when 'twitter'
              Twitter::Base.new(client)
          end
        end
        @access
      end

    end
OAUTHONE
end

#define_oauth_two(parent) ⇒ Object



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/lasso/model/oauth_two.rb', line 1

def define_oauth_two(parent)
  eval <<OAUTHTWO
    class OAuthTwo#{parent} < #{parent}

      alias_attribute :access_token,  :token_a
      alias_attribute :refresh_token, :token_b
  
      validates_presence_of :access_token
  
      def client
        @client ||= OAuth2::Client.new(config(:key), config(:secret), :site => config(:site), :authorize_path => config(:authorize_path), :type => 'web_server', :access_token_path => config(:access_token_path))
      end
  
      def access
        @access ||= OAuth2::AccessToken.new(client, access_token, refresh_token)
      end
    end
OAUTHTWO
end