module SocialStream::Ostatus::ActivityStreams
Public Instance Methods
activity_from_entry!(entry, receiver = nil)
click to toggle source
Parses an activity form a PuSH or Salmon notification Decides what action should be taken from an ActivityStreams
entry
# File lib/social_stream/ostatus/activity_streams.rb, line 20 def activity_from_entry! entry, receiver = nil # FIXME: should not use to_sym # https://github.com/shf/proudhon/issues/7 case entry.verb.to_sym when :follow, :subscribe, :join Tie.create_from_entry! entry, receiver when :unsubscribe, :leave, 'http://ostatus.org/schema/1.0/unfollow' Tie.destroy_from_entry! entry, receiver else # :post is the default verb r = record_from_entry! entry, receiver r.post_activity end end
actor_from_entry!(entry)
click to toggle source
Finds or creates a {RemoteSubject} from an ActivityStreams
entry
# File lib/social_stream/ostatus/activity_streams.rb, line 42 def actor_from_entry! entry webfinger_id = entry.author.uri if webfinger_id.blank? raise "Entry author without uri: #{ entry.to_xml }" end RemoteSubject.find_or_create_by_webfinger_uri! webfinger_id end
from_pshb_callback(body)
click to toggle source
Parses the body from a {PshbController#index} and dispatches entries for parsing to {#record_from_entry!}
# File lib/social_stream/ostatus/activity_streams.rb, line 6 def from_pshb_callback(body) atom = Proudhon::Atom.parse body atom.entries.each do |entry| # FIXME: get author from feed # https://github.com/shf/proudhon/issues/8 entry.author.uri ||= feed.author.uri activity_from_entry! entry end end
from_salmon_callback(body, receiver)
click to toggle source
Parses the body from a {Salmon#index} and receiving actor
# File lib/social_stream/ostatus/activity_streams.rb, line 53 def from_salmon_callback(body, receiver) salmon = Proudhon::Salmon.new body validate_salmon salmon activity_from_entry! salmon.to_entry, receiver end
record_from_entry!(entry, receiver)
click to toggle source
Redirects parsing to the suitable SocialStream's model
# File lib/social_stream/ostatus/activity_streams.rb, line 36 def record_from_entry! entry, receiver model!(entry.objtype).from_entry! entry, receiver end
validate_salmon(salmon)
click to toggle source
# File lib/social_stream/ostatus/activity_streams.rb, line 61 def validate_salmon salmon remote_subject = RemoteSubject.find_or_create_by_webfinger_uri!(salmon.to_entry.author.uri) key = remote_subject.rsa_key unless salmon.verify(key) raise "Invalid salmon: #{ salmon }" end end
verb(orig)
click to toggle source
Translate SocialStream
activity verb to Proudhon verb
# File lib/social_stream/ostatus/activity_streams.rb, line 71 def verb orig case orig when 'make-friend' :follow else orig.to_sym end end