Class: OAuth::Base
- Inherits:
-
Object
- Object
- OAuth::Base
- Defined in:
- app/models/o_auth/base.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
Instance Method Summary collapse
- #get_data ⇒ Object
-
#initialize(params) ⇒ Base
constructor
A new instance of Base.
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
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'app/models/o_auth/base.rb', line 3 def data @data end |
#provider ⇒ Object (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_data ⇒ Object
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 |