Class: Base4R::Item

Inherits:
Object
  • Object
show all
Includes:
ItemAttributeMethods
Defined in:
lib/item.rb

Overview

Item describes a single entry that will be or is already stored in Google Base

Direct Known Subclasses

UniversalItem

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ItemAttributeMethods

included

Instance Attribute Details

#attributesObject

array of Attribute objects that describe the Item



124
125
126
# File 'lib/item.rb', line 124

def attributes
  @attributes
end

#base_idObject

ID of this Item as assigned by Google



130
131
132
# File 'lib/item.rb', line 130

def base_id
  @base_id
end

#draftObject

Returns the value of attribute draft.



138
139
140
# File 'lib/item.rb', line 138

def draft
  @draft
end

#titleObject

Title of the Item



127
128
129
# File 'lib/item.rb', line 127

def title
  @title
end

#unique_idObject

unique alphnumeric identifier for the item - e.g. your internal ID code. IMPORTANT: Once you submit an item with a unique id, this identifier must not change when you send in a new data feed. Each item must retain the same id in subsequent feeds.



136
137
138
# File 'lib/item.rb', line 136

def unique_id
  @unique_id
end

Instance Method Details

#draft?Boolean

Returns:

  • (Boolean)


186
# File 'lib/item.rb', line 186

def draft?; @draft; end

#options_from_value(value, default_options = {}) ⇒ Object

:nodoc:



143
144
145
# File 'lib/item.rb', line 143

def options_from_value(value, default_options={})#:nodoc:
  default_options.merge(value.is_a?(Hash) ? value : {:value => value})
end

#to_xmlObject

Represents this Item as Atom XML which is the format required by the Base API.



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/item.rb', line 148

def to_xml
  
  doc = REXML::Document.new('<?xml version="1.0" ?>')

  entry = doc.add_element 'entry',
                          'xmlns'=>'http://www.w3.org/2005/Atom', 
                          'xmlns:g' => 'http://base.google.com/ns/1.0',
                          'xmlns:app'=>'http://purl.org/atom/app#',
                          'xmlns:gm'=>'http://base.google.com/ns-metadata/1.0'

  #bjd: not sure why these are instance variables but others are not
  #if @author_name || @author_email
  #  AuthorAttribute.to_xml(entry, :author, nil, :email => @author_email, :name => @author_name)
  #end

  entry.add_element 'category',
                    'scheme'=>'http://www.google.com/type',
                    'term' => 'googlebase.item'

  if draft?
    goog_control = entry.add_element('app:control', 'xmlns:app'=>'http://purl.org/atom/app#')
    goog_control.add_element('app:draft').text = 'yes'
  end

  entry.add_element('title').text= @title

  @attributes.each do |attr|
    attr.to_xml(entry)
  end

  doc
end