Completed
Push — master ( 1cb36a...4ae179 )
by John
56s
created

AtomFeed.to_xml()   A

Complexity

Conditions 2

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 2
1
require 'atom'
2
3
module RingCentral
4
  module RSS
5
    class AtomFeed
0 ignored issues
show
Coding Style introduced by
This class should have a documentation comment as per coding style.
Loading history...
6
      attr_accessor :feed
7
8
      def initialize(response = nil, opts = {})
9
        if opts.key?(:feed_name) && opts[:feed_name]
10
          @feed_name = opts[:feed_name]
11
        else
12
          @feed_name = 'RingCentral Feed'
13
        end
14
        @feed = nil
15
        load_message_store_response(response) unless response.nil?
16
      end
17
18
      def load_message_store_response(response)
19
        @feed = Atom::Feed.new do |f|
20
          f.title = @feed_name
21
          f.links << Atom::Link.new(href: "#{response.body['uri']}")
22
          f.updated = Time.parse("#{response.headers['date']}")
23
          response.body['records'].each do |message|
24
            f.entries << RingCentral::RSS::AtomEntry.new(message).entry
25
          end
26
        end
27
      end
28
29
      def to_xml
30
        ([email protected]? && @feed.is_a?(Atom::Feed)) ? @feed.to_xml : nil
31
      end
32
    end
33
  end
34
end
35