Skip to content

Commit

Permalink
Merge pull request googleapis#536 from thomasdarde/a
Browse files Browse the repository at this point in the history
Add a new impersonate sample
  • Loading branch information
sqrrrl authored Mar 30, 2017
2 parents 7085627 + 172e04b commit 6bdb7c1
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions samples/cli/lib/samples/gmail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,38 @@ def search(query)
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

0 comments on commit 6bdb7c1

Please sign in to comment.