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.



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

def public_id
  @public_id
end

#signed_requestObject

Returns the value of attribute signed_request.



35
36
37
# File 'app/models/auth/image.rb', line 35

def signed_request
  @signed_request
end

#timestampObject

Returns the value of attribute timestamp.



36
37
38
# File 'app/models/auth/image.rb', line 36

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.



18
19
20
# File 'app/models/auth/image.rb', line 18

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.



92
93
94
95
96
# File 'app/models/auth/image.rb', line 92

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.



73
74
75
76
77
78
79
# File 'app/models/auth/image.rb', line 73

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



81
82
83
# File 'app/models/auth/image.rb', line 81

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.



99
100
101
# File 'app/models/auth/image.rb', line 99

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