class GoogleAppsOauth2::Atom::Feed

Attributes

doc[R]
items[R]
next_page[R]

Public Class Methods

new(body) click to toggle source
Calls superclass method GoogleAppsOauth2::Atom::Document::new
# File lib/google_apps_oauth2/atom/feed.rb, line 5
def initialize(body)
  super(body)

  @items = entries_from(document: @doc, entry_tag: 'entry')
end

Public Instance Methods

add_category(content_array) click to toggle source

add_category adds the proper atom:category node to the content_array

add_category content_array, ‘user’

add_category returns the modified content_array

# File lib/google_apps_oauth2/atom/feed.rb, line 60
def add_category(content_array)
  content_array.unshift(create_node(type: 'atom:category', attrs: Atom::CATEGORY[:user]).to_s)
end
entries_from(properties) click to toggle source
# File lib/google_apps_oauth2/atom/feed.rb, line 11
def entries_from(properties)
  properties[:document].root.inject([]) do |results, entry|
    if entry.name == properties[:entry_tag]
      results << new_doc(node_to_ary(entry), ['apps:', 'atom:', 'gd:'])
    end
    set_next_page(entry) if entry.name == 'link' and entry.attributes[:rel] == 'next'
    results
  end
end
entry_wrap(content_array) click to toggle source

entry_wrap adds atom:entry opening and closing tags to the provided content_array and the beginning and end.

entry_wrap content_array

entry_wrap returns an array with an opening atom:entry element prepended to the front and a closing atom:entry tag appended to the end.

# File lib/google_apps_oauth2/atom/feed.rb, line 85
def entry_wrap(content_array)
  content_array.unshift(Atom::ENTRY_TAG[0]).push(Atom::ENTRY_TAG[1])
end
grab_elements(content_array, filter) click to toggle source

grab_elements applies the specified filter to the provided array. Google’s feed provides a lot of data that we don’t need in an entry document.

grab_elements content_array, ‘apps:’

grab_elements returns an array of items from content_array that match the given filter.

# File lib/google_apps_oauth2/atom/feed.rb, line 72
def grab_elements(content_array, filter)
  content_array.grep(Regexp.new filter)
end
new_doc(content_array, filters) click to toggle source

new_doc creates a new Atom document from the data provided in the feed. new_doc takes a type, an array of content to be placed into the document as well as an array of filters.

new_doc ‘user’, content_array, [‘apps:’]

new_doc returns an GoogleApps::Atom document of the specified type.

# File lib/google_apps_oauth2/atom/feed.rb, line 44
def new_doc(content_array, filters)
  content_array = filters.map do |filter|
    grab_elements(content_array, filter)
  end

  add_category(content_array)

  Atom.send :user, entry_wrap(content_array.flatten).join("\n")
end
node_to_ary(node) click to toggle source

node_to_ary converts a Atom::XML::Node to an array.

node_to_ary node

node_to_ary returns the string representation of the given node split on n.

# File lib/google_apps_oauth2/atom/feed.rb, line 31
def node_to_ary(node)
  node.to_s.split("\n")
end
set_next_page(node) click to toggle source
# File lib/google_apps_oauth2/atom/feed.rb, line 21
def set_next_page(node)
  @next_page = node.attributes[:href]
end