Class: AngelList::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/angel_list/auth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Auth

Returns a new instance of Auth.



7
8
9
10
11
12
13
14
# File 'lib/angel_list/auth.rb', line 7

def initialize(opts)
  self.options = Hashie::Mash.new
  self.options = self.options.merge(AngelList::Config.options) if AngelList::Config.methods.include? :options
  self.options = self.options.merge(opts)
  self.options = self.options.merge(:site => 'https://angel.co/') if self.options[:site] == nil
  self.client = get_client
  self
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



5
6
7
# File 'lib/angel_list/auth.rb', line 5

def client
  @client
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/angel_list/auth.rb', line 5

def options
  @options
end

#tokenObject

Returns the value of attribute token.



5
6
7
# File 'lib/angel_list/auth.rb', line 5

def token
  @token
end

Instance Method Details

#code(c) ⇒ Object



27
28
29
30
# File 'lib/angel_list/auth.rb', line 27

def code(c)
  self.token = self.client.auth_code.get_token(c, :redirect_uri => self.options[:redirect_uri])
  self
end

#from_hash(token) ⇒ Object



32
33
34
35
# File 'lib/angel_list/auth.rb', line 32

def from_hash(token)
  self.token = OAuth2::AccessToken.new(self.client, token)
  self
end

#get_clientObject



20
21
22
23
24
25
# File 'lib/angel_list/auth.rb', line 20

def get_client
  OAuth2::Client.new(self.options[:client_id], self.options[:client_secret], 
        :site => self.options[:site], 
        :authorize_url    => '/api/oauth/authorize',
        :token_url        => '/api/oauth/token')
end

#redirect_urlObject



16
17
18
# File 'lib/angel_list/auth.rb', line 16

def redirect_url
  self.client.auth_code.authorize_url(:redirect_uri => self.options[:redirect_uri])
end