Class: Googletastic::Row
Constant Summary
Constants included from Mixins::Namespaces
Mixins::Namespaces::NAMESPACES
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#spreadsheet_id ⇒ Object
Returns the value of attribute spreadsheet_id.
-
#title ⇒ Object
Returns the value of attribute title.
-
#worksheet_id ⇒ Object
Returns the value of attribute worksheet_id.
Attributes inherited from Base
#acl, #attachment_path, #created_at, #etag, #head, #id, #keep_raw, #raw, #response, #synced_with, #updated_at
Attributes included from Mixins::Attributes
Class Method Summary collapse
- .build_url(options) ⇒ Object
- .client_class ⇒ Object
- .get_url(path, id) ⇒ Object
- .index_url(path) ⇒ Object
-
.marshall(record) ⇒ Object
for save and update.
- .show_url(path, id) ⇒ Object
- .unmarshall(xml) ⇒ Object
Instance Method Summary collapse
Methods inherited from Base
Methods included from Mixins::Pagination
Methods included from Mixins::Finders
Methods included from Mixins::Parsing
Methods included from Mixins::Requesting
Methods included from Mixins::Attributes
#attribute_names, #has_attribute?, #inspect
Methods included from Mixins::Namespaces
Constructor Details
This class inherits a constructor from Googletastic::Base
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
3 4 5 |
# File 'lib/googletastic/row.rb', line 3 def data @data end |
#spreadsheet_id ⇒ Object
Returns the value of attribute spreadsheet_id.
3 4 5 |
# File 'lib/googletastic/row.rb', line 3 def spreadsheet_id @spreadsheet_id end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/googletastic/row.rb', line 3 def title @title end |
#worksheet_id ⇒ Object
Returns the value of attribute worksheet_id.
3 4 5 |
# File 'lib/googletastic/row.rb', line 3 def worksheet_id @worksheet_id end |
Class Method Details
.build_url(options) ⇒ Object
36 37 38 39 40 |
# File 'lib/googletastic/row.rb', line 36 def build_url() raise "You must specify a spreadsheet key 'key' and a 'worksheet_id' for a list of rows" unless ([:key] and [:worksheet_id]) [:url] ||= index_url(File.join([:key], [:worksheet_id])) super() end |
.client_class ⇒ Object
20 21 22 |
# File 'lib/googletastic/row.rb', line 20 def client_class "Spreadsheets" end |
.get_url(path, id) ⇒ Object
32 33 34 |
# File 'lib/googletastic/row.rb', line 32 def get_url(path, id) "http://spreadsheets.google.com/feeds/list/#{path}/private/full/#{id}" end |
.index_url(path) ⇒ Object
24 25 26 |
# File 'lib/googletastic/row.rb', line 24 def index_url(path) "http://spreadsheets.google.com/feeds/list/#{path}/private/full" end |
.marshall(record) ⇒ Object
for save and update
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/googletastic/row.rb', line 77 def marshall(record) Nokogiri::XML::Builder.new { |xml| attributes = nil if record.id attributes = {"etag" => record.etag}.merge(ns_xml("atom", "gsx")) else attributes = ns_xml("atom", "gsx") end xml.entry(attributes) { if record.id # PUT = update xml.id_ { xml.text record.get_url } #xml.updated { # xml.text record.updated.to_s #} end if record.title xml.title(:type => "text") { xml.text record.title } end record.data.each do |k,v| xml["gsx"].send(k) { xml.text v } end } }.to_xml end |
.show_url(path, id) ⇒ Object
28 29 30 |
# File 'lib/googletastic/row.rb', line 28 def show_url(path, id) "http://spreadsheets.google.com/feeds/list/#{path}/private/full/#{id}" end |
.unmarshall(xml) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/googletastic/row.rb', line 42 def unmarshall(xml) head = unmarshall_head(xml) records = xml.xpath("//atom:entry", ns_tag("atom")).collect do |record| etag = record["etag"].to_s id = record.xpath("atom:id", ns_tag("atom")).first.text ids = id =~ /http:\/\/spreadsheets\.google\.com\/feeds\/list\/([^\/]+)\/([^\/]+)\/([^\/]+)/ spreadsheet_id = $1 worksheet_id = $2 id = $3 title = record.xpath("atom:title", ns_tag("atom")).first.text content = record.xpath("atom:content", ns_tag("atom")).first.text created_at = record.xpath("atom:published", ns_tag("atom")).text updated_at = record.xpath("atom:updated", ns_tag("atom")).text data = {} record.xpath("gsx:*", ns_tag('gsx')).each do |node| next unless node.elem? data[node.name] = node.text end Googletastic::Row.new( :id => id, :etag => etag, :title => title, :spreadsheet_id => spreadsheet_id, :worksheet_id => worksheet_id, :data => data, :updated_at => DateTime.parse(updated_at), :head => head ) end records end |
Instance Method Details
#edit_url ⇒ Object
13 14 15 |
# File 'lib/googletastic/row.rb', line 13 def edit_url "http://spreadsheets.google.com/feeds/list/#{self.spreadsheet_id}/#{self.worksheet_id}/private/full/#{self.id}" end |
#get_url ⇒ Object
5 6 7 |
# File 'lib/googletastic/row.rb', line 5 def get_url self.class.get_url(File.join(self.spreadsheet_id, self.worksheet_id), self.id) end |
#index_url ⇒ Object
9 10 11 |
# File 'lib/googletastic/row.rb', line 9 def index_url "http://spreadsheets.google.com/feeds/list/#{self.spreadsheet_id}/#{self.worksheet_id}/private/full" end |