Class: SportNginAwsAuditor::Google
- Inherits:
-
Object
- Object
- SportNginAwsAuditor::Google
- Defined in:
- lib/sport_ngin_aws_auditor/google.rb
Constant Summary collapse
- FILE_NAMES =
%w[.google.yml]
Class Method Summary collapse
- .config_path ⇒ Object
- .configuration ⇒ Object
- .file ⇒ Object
- .get_authorization ⇒ Object
- .load_config ⇒ Object
Class Method Details
.config_path ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/sport_ngin_aws_auditor/google.rb', line 45 def self.config_path if filepath = FILE_NAMES.detect {|filename| File.exists?(filename)} File.join(Dir.pwd, filepath) else old_dir = Dir.pwd Dir.chdir('..') if old_dir != Dir.pwd config_path else puts "Could not find #{FILE_NAMES.join(' or ')}" exit end end end |
.configuration ⇒ Object
12 13 14 |
# File 'lib/sport_ngin_aws_auditor/google.rb', line 12 def self.configuration GoogleDrive.login_with_oauth() end |
.file ⇒ Object
36 37 38 |
# File 'lib/sport_ngin_aws_auditor/google.rb', line 36 def self.file load_config[:file] end |
.get_authorization ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sport_ngin_aws_auditor/google.rb', line 16 def self. creds = load_config[:credentials] client = ::Google::APIClient.new auth = client. auth.client_id = creds[:client_id] auth.client_secret = creds[:client_secret] auth.scope = "https://www.googleapis.com/auth/drive " + "https://docs.google.com/feeds/ " + "https://docs.googleusercontent.com/ " + "https://spreadsheets.google.com/feeds/" auth.redirect_uri = "urn:ietf:wg:oauth:2.0:oob" print("1. If it doesn't automatically open, open this page:\n%s\n\n" % auth.) `open "#{auth.}"` print("2. Enter the authorization code shown in the page: ") auth.code = $stdin.gets.chomp auth.fetch_access_token! access_token = auth.access_token end |
.load_config ⇒ Object
40 41 42 43 |
# File 'lib/sport_ngin_aws_auditor/google.rb', line 40 def self.load_config return @config if @config @config = GoogleConfig[YAML.load_file(config_path)] end |