Class: Auth::Image

Inherits:
Object
  • Object
show all
Includes:
Concerns::OwnerConcern, Mongoid::Document
Defined in:
app/models/auth/image.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#public_idObject

Returns the value of attribute public_id.



40
41
42
# File 'app/models/auth/image.rb', line 40

def public_id
  @public_id
end

#signed_requestObject

Returns the value of attribute signed_request.



38
39
40
# File 'app/models/auth/image.rb', line 38

def signed_request
  @signed_request
end

#timestampObject

Returns the value of attribute timestamp.



39
40
41
# File 'app/models/auth/image.rb', line 39

def timestamp
  @timestamp
end

Class Method Details

.permitted_paramsObject

CLASS METHODS

the parent id is the id of the object in which the image is uploaded. it need not exist. but has to be a valid bson object id.



21
22
23
# File 'app/models/auth/image.rb', line 21

def self.permitted_params
  [{:image => [:_id,:parent_id,:parent_class,:active,:timestamp,:public_id]},:id]
end

Instance Method Details

#get_signed_requestObject

OTHER CUSTOM DEFS.



95
96
97
98
99
# File 'app/models/auth/image.rb', line 95

def get_signed_request

  Cloudinary::Utils.sign_request({:public_id => self.id.to_s,:timestamp=> self.timestamp, :callback => "http://widget.cloudinary.com/cloudinary_cors.html"}, :options=>{:api_key=>Cloudinary.config.api_key, :api_secret=>Cloudinary.config.api_secret})

end

#parent_id_is_valid_bsonObject

CUSTOM VALIDATION DEFS.



76
77
78
79
80
81
82
# File 'app/models/auth/image.rb', line 76

def parent_id_is_valid_bson
  begin
    BSON::ObjectId.from_string(self.parent_id)
  rescue
    self.errors.add(:parent_id, "the parent id is not valid")
  end  
end

#public_id_equals_idObject



84
85
86
# File 'app/models/auth/image.rb', line 84

def public_id_equals_id
  self.errors.add(:public_id, "the public id and object id are not equal") if (self.id.to_s != self.public_id)
end

#text_representationObject

rendered in create, in the authenticated_controller.



102
103
104
# File 'app/models/auth/image.rb', line 102

def text_representation
  self.signed_request[:signature].to_s
end