lib/gooddata/models/profile.rb in gooddata-0.6.7 vs lib/gooddata/models/profile.rb in gooddata-0.6.8

- old
+ new

@@ -1,13 +1,16 @@ # encoding: UTF-8 +require 'pmap' + +require_relative '../rest/object' + require_relative 'project' module GoodData - # Account settings representation with some added sugar - class Profile - attr_reader :json + class Profile < GoodData::Rest::Object + attr_reader :user, :json EMPTY_OBJECT = { 'accountSetting' => { 'companyName' => nil, 'country' => nil, @@ -71,12 +74,11 @@ end # Gets user currently logged in # @return [GoodData::Profile] User currently logged-in def current - json = GoodData.get GoodData.connection.user['profile'] - GoodData::Profile.new(json) + GoodData.connection.user end # Gets hash representing diff of profiles # # @param user1 [GoodData::Profile] Original user @@ -205,11 +207,11 @@ DateTime.parse(@json['accountSetting']['created']) end # Deletes this account settings def delete - GoodData.delete uri + client.delete uri end # Gets hash representing diff of profiles # # @param user [GoodData::Profile] Another profile to compare with @@ -276,17 +278,10 @@ def login=(val) @dirty ||= login != val @json['accountSetting']['login'] = val end - # Get full name - # - # @return [String] Full name - def name - "#{first_name} #{last_name}" - end - # Gets the resource identifier # # @return [String] Resource identifier def obj_id uri.split('/').last @@ -326,18 +321,14 @@ # Gets the array of projects # # @return [Array<GoodData::Project>] Array of project where account settings belongs to def projects - res = [] - - projects = GoodData.get @json['accountSetting']['links']['projects'] - projects['projects'].each do |project| - res << GoodData::Project.new(project) + projects = client.get @json['accountSetting']['links']['projects'] + projects['projects'].map do |project| + client.create(GoodData::Project, project) end - - res end # Saves object if dirty, clears dirty flag def save! if @dirty @@ -377,8 +368,15 @@ # Gets the resource REST URI # # @return [String] Resource URI def uri @json['accountSetting']['links']['self'] + end + + private + + def initialize(json) + @json = json + @user = @json['accountSetting']['firstName'] + ' ' + @json['accountSetting']['lastName'] end end end