Module: Hyrax::Analytics

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

Defined Under Namespace

Classes: Config

Class Method Summary collapse

Class Method Details

.auth_client(scope) ⇒ Object



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

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



54
55
56
57
# File 'app/services/hyrax/analytics.rb', line 54

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



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

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