Sha256: c9abc591d3be805cf0c1d698caa63eadbaa15587c44f0f3ad36cb47c7483e2bf

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

require 'atom'

module RingCentral
  module RSS
    class AtomEntry
      attr_accessor :entry

      def initialize(data = nil)
        load_message(data) unless data.nil?
      end

      def load_message(data)
        raise 'Data is not a hash' unless data.is_a? Hash

        @entry = Atom::Entry.new do |e|
          e.title = build_title data
          e.links << Atom::Link.new(href: data['uri'])
          e.id = data['id']
          e.updated = Time.parse(data['lastModifiedTime'])
          e.summary = data['subject']
        end
      end

      def build_title(data)
        raise 'Data is not a hash' unless data.is_a? Hash

        parts = []

        if data.key?('to') && (data['to'].length > 0) && data['to'][0]['phoneNumber']
          to_phone_number = "#{data['to'][0]['phoneNumber']}"
          parts << "To: #{to_phone_number}" unless to_phone_number.empty?
        end

        if data.key?('from') && !data['from']['phoneNumber'].empty?
          from_phone_number = "#{data['from']['phoneNumber']}"
          parts << "From: #{from_phone_number}"
        end

        "[#{data['direction']} #{data['type']}] " + parts.join('; ')
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ringcentral-rss-0.0.3 lib/ringcentral-rss/atom_entry.rb
ringcentral-rss-0.0.2 lib/ringcentral-rss/atom_entry.rb
ringcentral-rss-0.0.1 lib/ringcentral-rss/atom_entry.rb