Class: TentD::Model::Follower
- Inherits:
-
Object
- Object
- TentD::Model::Follower
- Includes:
- DataMapper::Resource, Permissible, RandomPublicId, Serializable, UserScoped
- Defined in:
- lib/tentd/model/follower.rb
Class Method Summary collapse
- .create_follower(data, authorized_scopes = []) ⇒ Object
- .public_attributes ⇒ Object
- .update_follower(id, data, authorized_scopes = []) ⇒ Object
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #auth_details ⇒ Object
- #core_profile ⇒ Object
- #notification_servers ⇒ Object
- #permissible_foreign_key ⇒ Object
Methods included from UserScoped
Methods included from RandomPublicId
Methods included from Permissible
#assign_permissions, included, #permissions_json
Class Method Details
.create_follower(data, authorized_scopes = []) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/tentd/model/follower.rb', line 38 def self.create_follower(data, = []) if .include?(:write_followers) && .include?(:write_secrets) follower = create(data.slice(:entity, :groups, :public, :profile, :licenses, :notification_path, :mac_key_id, :mac_key, :mac_algorithm, :mac_timestamp_delta)) else follower = create(data.slice('entity', 'licenses', 'profile', 'notification_path')) end (data.types || ['all']).each do |type_url| follower.notification_subscriptions.create(:type => type_url) end follower end |
.public_attributes ⇒ Object
71 72 73 |
# File 'lib/tentd/model/follower.rb', line 71 def self.public_attributes [:entity] end |
.update_follower(id, data, authorized_scopes = []) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/tentd/model/follower.rb', line 50 def self.update_follower(id, data, = []) follower = first(:id => id) return unless follower whitelist = ['licenses'] if .include?(:write_followers) whitelist.concat(['entity', 'profile', 'public', 'groups']) if .include?(:write_secrets) whitelist.concat(['mac_key_id', 'mac_key', 'mac_algorithm', 'mac_timestamp_delta']) end end follower.update(data.slice(*whitelist)) if data['types'] follower.notification_subscriptions.destroy data['types'].each do |type_url| follower.notification_subscriptions.create(:type => type_url) end end follower end |
Instance Method Details
#as_json(options = {}) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/tentd/model/follower.rb', line 91 def as_json( = {}) attributes = super attributes.merge!(:profile => profile) if [:app] if [:app] || [:self] types = notification_subscriptions.all.map { |s| s.type.uri } attributes.merge!(:licenses => licenses, :types => types) end attributes end |
#auth_details ⇒ Object
87 88 89 |
# File 'lib/tentd/model/follower.rb', line 87 def auth_details attributes.slice(:mac_key_id, :mac_key, :mac_algorithm) end |
#core_profile ⇒ Object
79 80 81 |
# File 'lib/tentd/model/follower.rb', line 79 def core_profile API::CoreProfileData.new(profile) end |
#notification_servers ⇒ Object
83 84 85 |
# File 'lib/tentd/model/follower.rb', line 83 def notification_servers core_profile.servers end |
#permissible_foreign_key ⇒ Object
75 76 77 |
# File 'lib/tentd/model/follower.rb', line 75 def permissible_foreign_key :follower_access_id end |