Merge pull request #536 from thomasdarde/a
Add a new impersonate sample
This commit is contained in:
commit
6bdb7c1c9d
|
@ -120,5 +120,38 @@ module Samples
|
||||||
end
|
end
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue