Module: Sufia::Analytics

Defined in:
app/services/sufia/analytics.rb

Defined Under Namespace

Classes: Config

Class Method Summary collapse

Class Method Details

.auth_client(scope) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/services/sufia/analytics.rb', line 60

def self.auth_client(scope)
  unless File.exist?(config.privkey_path)
    raise "Private key file for Google analytics was expected at '#{config.privkey_path}', but no file was found."
  end
  private_key = File.read(config.privkey_path)
  Signet::OAuth2::Client.new token_credential_uri: 'https://accounts.google.com/o/oauth2/token',
                             audience: 'https://accounts.google.com/o/oauth2/token',
                             scope: scope,
                             issuer: config.client_email,
                             signing_key: OpenSSL::PKCS12.new(private_key, config.privkey_secret).key,
                             sub: config.client_email
end

.oauth_clientObject



55
56
57
58
# File 'app/services/sufia/analytics.rb', line 55

def self.oauth_client
  OAuth2::Client.new('', '', authorize_url: 'https://accounts.google.com/o/oauth2/auth',
                             token_url: 'https://accounts.google.com/o/oauth2/token')
end

.profileObject

Return a Google Analytics profile matching specified ID @ return [Legato::Management::Profile] A user profile associated with GA



84
85
86
87
88
89
# File 'app/services/sufia/analytics.rb', line 84

def self.profile
  return unless config.valid?
  user.profiles.detect do |profile|
    profile.web_property_id == Sufia.config.google_analytics_id
  end
end