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.



42
43
44
# File 'app/models/auth/image.rb', line 42

def public_id
  @public_id
end

#signed_requestObject

Returns the value of attribute signed_request.



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

def signed_request
  @signed_request
end

#timestampObject

Returns the value of attribute timestamp.



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

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.



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

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

Instance Method Details

#get_signed_requestObject

OTHER CUSTOM DEFS.



101
102
103
104
105
106
107
# File 'app/models/auth/image.rb', line 101

def get_signed_request
  ## these should be merged only if they exist.
  params_to_sign = {:public_id => self.id.to_s,:timestamp=> self.timestamp, :callback => "http://widget.cloudinary.com/cloudinary_cors.html"}
  params_to_sign.merge!({:custom_coordinates => self.custom_coordinates}) unless self.custom_coordinates.blank?
  Cloudinary::Utils.sign_request(params_to_sign, :options=>{:api_key=>Cloudinary.config.api_key, :api_secret=>Cloudinary.config.api_secret})

end

#get_urlObject



114
115
116
117
118
119
120
# File 'app/models/auth/image.rb', line 114

def get_url
  if self.custom_coordinates
    Cloudinary::Utils.cloudinary_url self.id.to_s, gravity: "custom", crop: "crop"
  else
    Cloudinary::Utils.cloudinary_url self.id.to_s
  end
end

#parent_id_is_valid_bsonObject

CUSTOM VALIDATION DEFS.



82
83
84
85
86
87
88
# File 'app/models/auth/image.rb', line 82

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



90
91
92
# File 'app/models/auth/image.rb', line 90

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.



110
111
112
# File 'app/models/auth/image.rb', line 110

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