Class: TentD::Model::Following

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Resource, Permissible, RandomPublicId, Serializable, UserScoped
Defined in:
lib/tentd/model/following.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from UserScoped

included

Methods included from RandomPublicId

included

Methods included from Permissible

#assign_permissions, included, #permissions_json

Class Method Details

.public_attributesObject



43
44
45
# File 'lib/tentd/model/following.rb', line 43

def self.public_attributes
  [:remote_id, :entity]
end

.update_profile(id) ⇒ Object



47
48
49
# File 'lib/tentd/model/following.rb', line 47

def self.update_profile(id)
  first(:id => id).update_profile
end

Instance Method Details

#as_json(options = {}) ⇒ Object



88
89
90
91
92
93
94
95
96
97
# File 'lib/tentd/model/following.rb', line 88

def as_json(options = {})
  attributes = super

  if options[:app]
    attributes[:profile] = profile
    attributes[:licenses] = licenses
  end

  attributes
end

#auth_detailsObject



75
76
77
# File 'lib/tentd/model/following.rb', line 75

def auth_details
  attributes.slice(:mac_key_id, :mac_key, :mac_algorithm)
end

#confirm_from_params(params) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/tentd/model/following.rb', line 32

def confirm_from_params(params)
  update(
    :remote_id => params.id,
    :profile => params.profile || {},
    :mac_key_id => params.mac_key_id,
    :mac_key => params.mac_key,
    :mac_algorithm => params.mac_algorithm,
    :confirmed => true
  )
end

#core_profileObject



63
64
65
# File 'lib/tentd/model/following.rb', line 63

def core_profile
  API::CoreProfileData.new(profile)
end

#notification_pathObject



67
68
69
# File 'lib/tentd/model/following.rb', line 67

def notification_path
  'posts'
end

#notification_serversObject



71
72
73
# File 'lib/tentd/model/following.rb', line 71

def notification_servers
  core_profile.servers
end

#update_from_params(params, authorized_scopes = []) ⇒ Object



79
80
81
82
83
84
85
86
# File 'lib/tentd/model/following.rb', line 79

def update_from_params(params, authorized_scopes = [])
  whitelist = [:remote_id, :entity, :groups, :public, :licenses, :profile]
  if authorized_scopes.include?(:write_secrets)
    whitelist.concat([:mac_key_id, :mac_key, :mac_algorithm, :mac_timestamp_delta])
  end
  attributes = params.slice(*whitelist)
  update(attributes)
end

#update_profileObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/tentd/model/following.rb', line 51

def update_profile
  client = TentClient.new(core_profile.servers, auth_details.merge(:faraday_adapter => TentD.faraday_adapter))
  res = client.profile.get
  if res.status == 200
    self.profile = res.body
    self.licenses = core_profile.licenses
    self.entity = core_profile.entity
  end
  save
  profile
end