Class: Applicaster::Accounts

Inherits:
Object
  • Object
show all
Defined in:
lib/applicaster/accounts.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id, client_secret) ⇒ Accounts

Returns a new instance of Accounts.



16
17
18
19
# File 'lib/applicaster/accounts.rb', line 16

def initialize(client_id, client_secret)
  @client_id = client_id
  @client_secret = client_secret
end

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id.



3
4
5
# File 'lib/applicaster/accounts.rb', line 3

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



4
5
6
# File 'lib/applicaster/accounts.rb', line 4

def client_secret
  @client_secret
end

Class Method Details

.default_siteObject



7
8
9
# File 'lib/applicaster/accounts.rb', line 7

def default_site
  "https://accounts2.applicaster.com"
end

.siteObject



11
12
13
# File 'lib/applicaster/accounts.rb', line 11

def site
  URI.parse(ENV["ACCOUNTS_BASE_URL"] || default_site)
end

Instance Method Details

#access_token(omniauth_credentials) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/applicaster/accounts.rb', line 34

def access_token(omniauth_credentials)
  @access_token ||= OAuth2::AccessToken.new(
    client,
    omniauth_credentials["token"],
    omniauth_credentials.except("token", "expires"),
  )
end

#clientObject



25
26
27
28
29
30
31
32
# File 'lib/applicaster/accounts.rb', line 25

def client
  @client ||= ::OAuth2::Client.new(
    client_id,
    client_secret,
    site: Applicaster::Accounts.site,
    authorize_url: "/oauth/authorize",
  )
end

#user_data_from_omniauth(omniauth_credentials) ⇒ Object



21
22
23
# File 'lib/applicaster/accounts.rb', line 21

def user_data_from_omniauth(omniauth_credentials)
  access_token(omniauth_credentials).get("/api/v1/users/current.json").parsed
end