Class: OAuth::Base

Inherits:
Object
  • Object
show all
Defined in:
app/models/o_auth/base.rb

Direct Known Subclasses

Facebook, Google

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Base

Returns a new instance of Base.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/models/o_auth/base.rb', line 5

def initialize params
  @provider = self.class.name.split('::').last.downcase

  @params = {
    code: params[:code],
    redirect_uri: params[:redirectUri],
    client_id: params[:clientId],
    client_secret: ENV["#{ @provider }_oauth_secret"]
  }
  
  @client = HTTPClient.new
  @access_token = params[:access_token].presence || get_access_token
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'app/models/o_auth/base.rb', line 3

def data
  @data
end

#providerObject (readonly)

Returns the value of attribute provider.



3
4
5
# File 'app/models/o_auth/base.rb', line 3

def provider
  @provider
end

Instance Method Details

#get_dataObject



19
20
21
22
23
24
25
# File 'app/models/o_auth/base.rb', line 19

def get_data
  response = @client.get(self.class::DATA_URL, access_token: @access_token)

  @data = JSON.parse(response.body).with_indifferent_access

  @data[:id] ||= @data[:sub]
end