lib/gooddata/models/project_role.rb in gooddata-0.6.4 vs lib/gooddata/models/project_role.rb in gooddata-0.6.5

- old
+ new

@@ -1,81 +1,42 @@ # encoding: UTF-8 require_relative 'profile' +require_relative '../mixins/mixins' + module GoodData class ProjectRole - def initialize(json) - @json = json - end + attr_accessor :json - # Gets Project Role Identifier - # - # @return [string] Project Role - def identifier - @json['projectRole']['meta']['identifier'] - end + include GoodData::Mixin::RestGetters - # Gets Project Role Author - # - # @return [GoodData::Profile] Project Role author - def author - url = @json['projectRole']['meta']['author'] - tmp = GoodData.get url - GoodData::Profile.new(tmp) + class << self + include GoodData::Mixin::RestResource end - # Gets Project Role Contributor - # - # @return [GoodData::Profile] Project Role Contributor - def contributor - url = @json['projectRole']['meta']['contributor'] - tmp = GoodData.get url - GoodData::Profile.new(tmp) - end + ProjectRole.root_key :projectRole - # Gets DateTime time when created - # - # @return [DateTime] Date time of creation - def created - DateTime.parse(@json['projectRole']['meta']['created']) - end + include GoodData::Mixin::RootKeyGetter + include GoodData::Mixin::Author + include GoodData::Mixin::Contributor + include GoodData::Mixin::Timestamps - # Gets Project Role Permissions - # - # @return [string] Project Role - def permissions - @json['projectRole']['permissions'] + def initialize(json) + @json = json end - # Gets Project Role Title - # - # @return [string] Project Role Title - def title - @json['projectRole']['meta']['title'] - end + ProjectRole.data_property_reader :permissions - # Gets Project Role Summary - # - # @return [string] Project Role Summary - def summary - @json['projectRole']['meta']['summary'] - end + ProjectRole.metadata_property_reader :identifier, :title, :summary - # Gets DateTime time when updated - # - # @return [DateTime] Date time of last update - def updated - DateTime.parse(@json['projectRole']['meta']['updated']) - end - # Gets Users with this Role # # @return [Array<GoodData::Profile>] List of users def users res = [] - url = @json['projectRole']['links']['roleUsers'] + url = data['links']['roleUsers'] tmp = GoodData.get url tmp['associatedUsers']['users'].each do |user_url| user = GoodData.get user_url res << GoodData::Profile.new(user) end @@ -85,8 +46,12 @@ # Gets Raw object URI # # @return [string] URI of this project role def uri @json['projectRole']['links']['roleUsers'].split('/')[0...-1].join('/') + end + + def ==(other) + uri == other.uri end end end