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

AtomFeed   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
dl 0
loc 28
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A load_message_store_response() 0 10 1
A initialize() 0 9 4
A to_xml() 0 3 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