class GoodData::Profile

Constants

ASSIGNABLE_MEMBERS
EMPTY_OBJECT
PROFILE_PATH

Attributes

json[R]
user[R]

Public Class Methods

[](id, opts = { client: GoodData.connection }) click to toggle source

Get profile by ID or URI

@param id ID or URI of user to be found @param [Hash] opts Additional optional options @option opts [GoodData::Rest::Client] :client Client used for communication with server @return GoodData::Profile User Profile

# File lib/gooddata/models/profile.rb, line 61
def [](id, opts = { client: GoodData.connection })
  return id if id.instance_of?(GoodData::Profile) || id.respond_to?(:profile?) && id.profile?

  if id.to_s !~ %r{^(\/gdc\/account\/profile\/)?[a-zA-Z\d]+$}
    fail(ArgumentError, 'wrong type of argument. Should be either profile ID or path')
  end

  id = id.match(/[a-zA-Z\d]+$/)[0] if id =~ %r{/}

  c = client(opts)
  fail ArgumentError, 'No :client specified' if c.nil?

  response = c.get(PROFILE_PATH % id)
  c.factory.create(Profile, response)
end
create(attributes) click to toggle source

Creates new instance from hash with attributes

@param attributes [Hash] Hash with initial attributes @return [GoodData::Profile] New profile instance

# File lib/gooddata/models/profile.rb, line 81
def create(attributes)
  res = create_object(attributes)
  res.save!
  res
end
create_object(attributes) click to toggle source
# File lib/gooddata/models/profile.rb, line 87
def create_object(attributes)
  json = GoodData::Helpers.deep_dup(EMPTY_OBJECT)
  json['accountSetting']['links']['self'] = attributes[:uri] if attributes[:uri]
  res = client.create(GoodData::Profile, json)

  attributes.each do |k, v|
    res.send("#{k}=", v) if ASSIGNABLE_MEMBERS.include? k
  end
  res
end
current() click to toggle source

Gets user currently logged in @return [GoodData::Profile] User currently logged-in

# File lib/gooddata/models/profile.rb, line 110
def current
  client.user
end
diff(item1, item2) click to toggle source
# File lib/gooddata/models/profile.rb, line 98
def diff(item1, item2)
  x = diff_list([item1], [item2])
  return {} if x[:changed].empty?
  x[:changed].first[:diff]
end
diff_list(list1, list2) click to toggle source
# File lib/gooddata/models/profile.rb, line 104
def diff_list(list1, list2)
  GoodData::Helpers.diff(list1, list2, key: :login)
end
new(json) click to toggle source

Creates new instance

@return [Profile] New Profile instance

# File lib/gooddata/models/profile.rb, line 118
def initialize(json)
  @json = json
  @dirty = false
end

Public Instance Methods

!=(other) click to toggle source

Checks objects for non-equality

@param right [GoodData::Profile] Project to compare with @return [Boolean] True if different else false

# File lib/gooddata/models/profile.rb, line 136
def !=(other)
  !(self == other)
end
==(other) click to toggle source

Checks objects for equality

@param right [GoodData::Profile] Project to compare with @return [Boolean] True if same else false

# File lib/gooddata/models/profile.rb, line 127
def ==(other)
  return false unless other.respond_to?(:to_hash)
  to_hash == other.to_hash
end
account_setting_id()
Alias for: obj_id
authentication_modes() click to toggle source
# File lib/gooddata/models/profile.rb, line 445
def authentication_modes
  @json['accountSetting']['authenticationModes'].map { |x| x.downcase.to_sym }
end
authentication_modes=(modes) click to toggle source
# File lib/gooddata/models/profile.rb, line 449
def authentication_modes=(modes)
  modes = Array(modes)
  @dirty = true
  @json['accountSetting']['authenticationModes'] = modes.map { |x| x.to_s.upcase }
end
channels() click to toggle source
# File lib/gooddata/models/profile.rb, line 476
def channels
  GoodData::ChannelConfiguration.all(client: client)
end
company() click to toggle source

Gets the company name

@return [String] Company name

# File lib/gooddata/models/profile.rb, line 151
def company
  @json['accountSetting']['companyName'] || ''
end
company=(val) click to toggle source

Set the company name

@param val [String] Company name to be set

# File lib/gooddata/models/profile.rb, line 158
def company=(val)
  @dirty ||= company != val
  @json['accountSetting']['companyName'] = val
end
content() click to toggle source
# File lib/gooddata/models/profile.rb, line 418
def content
  keys = (data.keys - ['links'])
  data.slice(*keys)
end
country() click to toggle source

Gets the country

@return [String] Country

# File lib/gooddata/models/profile.rb, line 181
def country
  @json['accountSetting']['country'] || ''
end
country=(val) click to toggle source

Set the country

@param val [String] Country to be set

# File lib/gooddata/models/profile.rb, line 188
def country=(val)
  @dirty ||= country != val
  @json['accountSetting']['country'] = val
end
create_channel() click to toggle source
# File lib/gooddata/models/profile.rb, line 472
def create_channel
  GoodData::ChannelConfiguration.create(to: email, title: email, client: client)
end
created() click to toggle source

Gets date when created

@return [DateTime] Created date

# File lib/gooddata/models/profile.rb, line 196
def created
  DateTime.parse(@json['accountSetting']['created'])
end
data() click to toggle source
# File lib/gooddata/models/profile.rb, line 409
def data
  data = @json || {}
  data['accountSetting'] || {}
end
delete() click to toggle source

Deletes this account settings

# File lib/gooddata/models/profile.rb, line 201
def delete
  client.delete uri
end
diff(user) click to toggle source

Gets hash representing diff of profiles

@param user [GoodData::Profile] Another profile to compare with @return [Hash] Hash representing diff

# File lib/gooddata/models/profile.rb, line 209
def diff(user)
  GoodData::Profile.diff(self, user)
end
email() click to toggle source

Gets the email

@return [String] Email address

# File lib/gooddata/models/profile.rb, line 216
def email
  @json['accountSetting']['email'].is_a?(String) ? @json['accountSetting']['email'].downcase : ''
end
email=(val) click to toggle source

Set the email

@param val [String] Email to be set

# File lib/gooddata/models/profile.rb, line 223
def email=(val)
  @dirty ||= email != val
  @json['accountSetting']['email'] = val
end
first_name() click to toggle source

Gets the first name

@return [String] First name

# File lib/gooddata/models/profile.rb, line 231
def first_name
  @json['accountSetting']['firstName'] || ''
end
first_name=(val) click to toggle source

Set the first name

@param val [String] First name to be set

# File lib/gooddata/models/profile.rb, line 238
def first_name=(val)
  @dirty ||= first_name != val
  @json['accountSetting']['firstName'] = val
end
full_name() click to toggle source

Get full name

@return String Full Name NOTE: This can be tricky to implement correctly for i18n

# File lib/gooddata/models/profile.rb, line 247
def full_name
  "#{first_name} #{last_name}"
end
Also aliased as: title
language() click to toggle source

Gets the language

@return [String] Language

# File lib/gooddata/models/profile.rb, line 166
def language
  @json['accountSetting']['language'] || 'en-US'
end
language=(val) click to toggle source

Set the language

@param val [String] Language to be set

# File lib/gooddata/models/profile.rb, line 173
def language=(val)
  @dirty ||= language != val
  @json['accountSetting']['language'] = val
end
last_name() click to toggle source

Gets the last name

@return [String] Last name

# File lib/gooddata/models/profile.rb, line 256
def last_name
  @json['accountSetting']['lastName'] || ''
end
last_name=(val) click to toggle source

Set the last name

@param val [String] Last name to be set

# File lib/gooddata/models/profile.rb, line 263
def last_name=(val)
  @dirty ||= last_name != val
  @json['accountSetting']['lastName'] = val
end
login() click to toggle source

Gets the login

@return [String] Login

# File lib/gooddata/models/profile.rb, line 271
def login
  @json['accountSetting']['login'] || ''
end
login=(val) click to toggle source

Set the login

@param val [String] Login to be set

# File lib/gooddata/models/profile.rb, line 278
def login=(val)
  @dirty ||= login != val
  @json['accountSetting']['login'] = val
end
name() click to toggle source
# File lib/gooddata/models/profile.rb, line 423
def name
  (first_name || '') + (last_name || '')
end
obj_id() click to toggle source

Gets the resource identifier

@return [String] Resource identifier

# File lib/gooddata/models/profile.rb, line 286
def obj_id
  uri.split('/').last
end
Also aliased as: account_setting_id
password() click to toggle source
# File lib/gooddata/models/profile.rb, line 427
def password
  @json['accountSetting']['password']
end
password=(a_password) click to toggle source
# File lib/gooddata/models/profile.rb, line 431
def password=(a_password)
  @dirty = true
  @json['accountSetting']['password'] = a_password
end
phone() click to toggle source

Gets the phone

@return [String] Phone

# File lib/gooddata/models/profile.rb, line 295
def phone
  @json['accountSetting']['phoneNumber'] || ''
end
Also aliased as: phone_number
phone=(val) click to toggle source

Set the phone

@param val [String] Phone to be set

# File lib/gooddata/models/profile.rb, line 304
def phone=(val)
  @dirty ||= phone != val
  @json['accountSetting']['phoneNumber'] = val
end
Also aliased as: phone_number=
phone_number()
Alias for: phone
phone_number=(val)
Alias for: phone=
position() click to toggle source

Gets the position in company

@return [String] Position in company

# File lib/gooddata/models/profile.rb, line 314
def position
  @json['accountSetting']['position'] || ''
end
position=(val) click to toggle source

Set the position

@param val [String] Position to be set

# File lib/gooddata/models/profile.rb, line 321
def position=(val)
  @dirty ||= position != val
  @json['accountSetting']['position'] = val
end
projects(limit = nil, offset = nil) click to toggle source

Gets the array of projects @param limit [Integer] maximum number of projects to get. @param offset [Integer] offset of the first project, start from 0. @return [Array<GoodData::Project>] Array of project where account settings belongs to

# File lib/gooddata/models/profile.rb, line 330
def projects(limit = nil, offset = nil)
  url = @json['accountSetting']['links']['projects']

  all_projects = []

  raise ArgumentError, 'Params limit and offset are expected' if !offset.nil? && limit.nil?

  if limit.nil?
    url += "?limit=500"
    loop do
      projects = client.get url
      projects['projects']['items'].each do |project|
        all_projects << client.create(GoodData::Project, project)
      end
      if !projects['projects']['paging'].nil? && !projects['projects']['paging']['next'].nil?
        url = projects['projects']['paging']['next']
      else
        break
      end
    end
  else
    limit = [limit, 500].min if limit.is_a?(Integer) && limit > 0

    url += "?limit=#{limit}"
    url += "&offset=#{offset}" if !offset.nil? && offset.is_a?(Integer) && offset > 0

    projects = client.get url
    projects['projects']['items'].each do |project|
      all_projects << client.create(GoodData::Project, project)
    end
  end

  all_projects
end
save!() click to toggle source

Saves object if dirty, clears dirty flag

# File lib/gooddata/models/profile.rb, line 366
def save!
  if @dirty
    raw = @json.dup
    raw['accountSetting'].delete('login')

    if uri && !uri.empty?
      url = "/gdc/account/profile/#{obj_id}"
      @json = client.put url, raw
      @dirty = false
    end
  end
  self
end
sso_provider() click to toggle source
# File lib/gooddata/models/profile.rb, line 436
def sso_provider
  @json['accountSetting']['ssoProvider']
end
sso_provider=(an_sso_provider) click to toggle source
# File lib/gooddata/models/profile.rb, line 440
def sso_provider=(an_sso_provider)
  @dirty = true
  @json['accountSetting']['ssoProvider'] = an_sso_provider
end
timezone() click to toggle source

Gets the preferred timezone

@return [String] Preferred timezone

# File lib/gooddata/models/profile.rb, line 383
def timezone
  @json['accountSetting']['timezone'] || ''
end
timezone=(val) click to toggle source

Set the timezone

@param val [String] Timezone to be set

# File lib/gooddata/models/profile.rb, line 390
def timezone=(val)
  @dirty ||= timezone != val
  @json['accountSetting']['timezone'] = val
end
title()
Alias for: full_name
to_hash() click to toggle source
# File lib/gooddata/models/profile.rb, line 455
def to_hash
  tmp = GoodData::Helpers.symbolize_keys(content.merge(uri: uri))
  [
    [:companyName, :company],
    [:phoneNumber, :phone],
    [:firstName, :first_name],
    [:lastName, :last_name],
    [:authenticationModes, :authentication_modes],
    [:ssoProvider, :sso_provider]
  ].each do |vals|
    wire, rb = vals
    tmp[rb] = tmp[wire]
    tmp.delete(wire)
  end
  tmp
end
updated() click to toggle source

Gets the date when updated

@return [DateTime] Updated date

# File lib/gooddata/models/profile.rb, line 398
def updated
  DateTime.parse(@json['accountSetting']['updated'])
end
uri() click to toggle source

Gets the resource REST URI

@return [String] Resource URI

# File lib/gooddata/models/profile.rb, line 405
def uri
  GoodData::Helpers.get_path(@json, %w(accountSetting links self))
end