Skip to content

Instantly share code, notes, and snippets.

@rafaltrojanowski
Created December 12, 2015 18:53
Show Gist options
  • Select an option

  • Save rafaltrojanowski/a5ed50681a2d32df7253 to your computer and use it in GitHub Desktop.

Select an option

Save rafaltrojanowski/a5ed50681a2d32df7253 to your computer and use it in GitHub Desktop.
def self.to_google_params(params)
def self.map_it(hash, mappings)
sliced_hash = hash.slice(*mappings.keys)
Hash[sliced_hash.map {|k, v| [mappings[k], v] }]
end
# Our style is exclude = true. Google's is include = true. So we need to invert the value.
params[:privacy] = !params[:privacy] if params.has_key? :privacy
{}.tap do |google_params|
google_params = map_it(params,
address: :primaryEmail,
password: :password,
privacy: :includeInGlobalAddressList,
org_unit_path: :orgUnitPath
)
name_params = map_it(params, first_name: :givenName, last_name: :familyName)
google_params[:name] = name_params if name_params.any?
org_params = map_it(params, department: :department, title: :title)
google_params[:organizations] = [org_params] if org_params.any?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment