diff --git a/samples/cli/lib/samples/gmail.rb b/samples/cli/lib/samples/gmail.rb index bafa04e35..cff3cd011 100644 --- a/samples/cli/lib/samples/gmail.rb +++ b/samples/cli/lib/samples/gmail.rb @@ -120,5 +120,38 @@ module Samples end end end + + + desc 'impersonate and update email signature', 'Update the email signature of another user' + method_option :impersonated_email, type: :string, required: true + def update_email_signature(new_signature_content) + gmail = Gmail::GmailService.new + + # You can download a client_secret.json from the service account page + # of your developer's console + + attrs = { + json_key_io: 'client_secret.json', + scope: [ Gmail::AUTH_GMAIL_SETTINGS_BASIC ] + } + + auth = Google::Auth::ServiceAccountCredentials.make_creds(attrs) + impersonate_auth = auth.dup + impersonate_auth.sub = impersonated_email + + user_id = impersonated_email + send_as_email = update_user_setting_send_as + + + gmail.authorization = impersonate_auth + + send_as_object = {"signature": new_signature_content} + # options: {} is necessary for method to be called correctly. + result = service.patch_user_setting_send_as(user_id, send_as_email, send_as_object, options: {}) + + + puts "signature of #{impersonated_email} is now: #{result.signature}" + end + end end