Skip to content
Extraits de code Groupes Projets
request.rb 1,68 ko
Newer Older
  • Learn to ignore specific revisions
  • Raphael's avatar
    Raphael a validé
    #   Copyright (c) 2010, Diaspora Inc.  This file is
    
    Raphael's avatar
    Raphael a validé
    #   licensed under the Affero General Public License version 3.  See
    #   the COPYRIGHT file.
    
      require File.expand_path('../../../lib/diaspora/webhooks', __FILE__)
    
      include MongoMapper::Document
      include Diaspora::Webhooks
      include ROXML
    
      xml_accessor :_id
      xml_accessor :person, :as => Person
    
    maxwell's avatar
    maxwell a validé
      xml_accessor :destination_url
      xml_accessor :callback_url
    
      xml_accessor :exported_key, :cdata => true
    
    Daniel Grippi's avatar
    Daniel Grippi a validé
      key :person_id,       ObjectId
    
    Raphael's avatar
    Raphael a validé
      key :aspect_id,        ObjectId
    
    Daniel Grippi's avatar
    Daniel Grippi a validé
      key :callback_url,    String
      key :exported_key,    String
    
      validates_presence_of :destination_url, :callback_url
    
    TJ Peden's avatar
    TJ Peden a validé
      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) }
    
      def self.instantiate(options = {})
    
        self.new(:destination_url => options[:to],
    
                 :callback_url    => person.receive_url,
    
    danielvincent's avatar
    danielvincent a validé
                 :person          => person,
    
    Raphael's avatar
    Raphael a validé
                 :aspect_id        => options[:into])
    
    danielvincent's avatar
    danielvincent a validé
      def reverse_for accepting_user
        self.person          = accepting_user.person
    
        self.exported_key    = accepting_user.exported_key
    
        self.destination_url = self.callback_url
    
    danielvincent's avatar
    danielvincent a validé
        self.save
    
      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