Class: TentD::Model::App

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from UserScoped

included

Methods included from RandomPublicId

included

Class Method Details

.create_from_params(params) ⇒ Object



33
34
35
# File 'lib/tentd/model/app.rb', line 33

def self.create_from_params(params)
  create(params.slice(:name, :description, :url, :icon, :redirect_uris, :scopes))
end

.public_attributesObject



44
45
46
# File 'lib/tentd/model/app.rb', line 44

def self.public_attributes
  [:name, :description, :url, :icon, :scopes, :redirect_uris]
end

.update_from_params(id, params) ⇒ Object



37
38
39
40
41
42
# File 'lib/tentd/model/app.rb', line 37

def self.update_from_params(id, params)
  app = first(:id => id)
  return unless app
  app.update(params.slice(:name, :description, :url, :icon, :redirect_uris, :scopes))
  app
end

Instance Method Details

#as_json(options = {}) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/tentd/model/app.rb', line 52

def as_json(options = {})
  attributes = super

  if options[:mac]
    [:mac_key, :mac_key_id, :mac_algorithm].each { |key|
      attributes[key] = send(key)
    }
  end

  attributes[:authorizations] = authorizations.all.map { |a| a.as_json(options.merge(:self => nil)) }

  Array(options[:exclude]).each { |k| attributes.delete(k) if k }
  attributes
end

#auth_detailsObject



48
49
50
# File 'lib/tentd/model/app.rb', line 48

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