about summary refs log tree commit diff
path: root/app/services/process_feed_service.rb
blob: f77415a3070e44f3399b8473bc7e7f5fe0534a37 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class ProcessFeedService
  def call(body, account)
    xml = Nokogiri::XML(body)

    xml.xpath('/xmlns:feed/xmlns:entry').each do |entry|
      uri    = entry.at_xpath('./xmlns:id').content
      status = Status.find_by(uri: uri)

      next if !status.nil?

      status = Status.new
      status.account    = account
      status.uri        = uri
      status.text       = entry.at_xpath('./xmlns:content').content
      status.created_at = entry.at_xpath('./xmlns:published').content
      status.updated_at = entry.at_xpath('./xmlns:updated').content
      status.save!

      # todo: not everything is a status. there are follows, favourites
      # todo: RTs
    end
  end
end