Newer
Older
# licensed under the Affero General Public License version 3. See
# the COPYRIGHT file.
Daniel Vincent Grippi
a validé
maxwell
a validé
class Request
require File.expand_path('../../../lib/diaspora/webhooks', __FILE__)
maxwell
a validé
include MongoMapper::Document
include Diaspora::Webhooks
include ROXML
xml_accessor :_id
xml_accessor :person, :as => Person
xml_accessor :exported_key, :cdata => true
maxwell
a validé
maxwell
a validé
key :destination_url, String
key :callback_url, String
key :exported_key, String
belongs_to :person
maxwell
a validé
validates_presence_of :destination_url, :callback_url
maxwell
a validé
before_validation :clean_link
scope :for_user, lambda{ |user| where(:destination_url => user.person.receive_url) }
scope :from_user, lambda{ |user| where(:destination_url.ne => user.person.receive_url) }
maxwell
a validé
def self.instantiate(options = {})
maxwell
a validé
person = options[:from]
self.new(:destination_url => options[:to],
Raphael
a validé
:exported_key => person.exported_key,
maxwell
a validé
end
def reverse_for accepting_user
self.person = accepting_user.person
Raphael
a validé
self.exported_key = accepting_user.exported_key
Raphael
a validé
protected
maxwell
a validé
def clean_link
if self.destination_url
self.destination_url = 'http://' + self.destination_url unless self.destination_url.match('https?://')
self.destination_url = self.destination_url + '/' if self.destination_url[-1,1] != '/'
end
end