Module: SocialStream::Ostatus::ActivityStreams

Defined in:
lib/social_stream/ostatus/activity_streams.rb

Instance Method Summary collapse

Instance Method Details

#activity_from_entry!(entry, receiver = nil) ⇒ Object

Parses an activity form a PuSH or Salmon notification Decides what action should be taken from an ActivityStreams entry



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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) ⇒ Object

Finds or creates a RemoteSubject from an ActivityStreams entry



42
43
44
45
46
47
48
49
50
# 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) ⇒ Object

Parses the body from a PshbController#index and dispatches entries for parsing to #record_from_entry!



6
7
8
9
10
11
12
13
14
15
16
# 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) ⇒ Object

Parses the body from a Salmon#index and receiving actor



53
54
55
56
57
58
59
# 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) ⇒ Object

Redirects parsing to the suitable SocialStream’s model



36
37
38
# 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) ⇒ Object



61
62
63
64
65
66
67
68
# 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) ⇒ Object

Translate SocialStream activity verb to Proudhon verb



71
72
73
74
75
76
77
78
# 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