Class: GoogleR::Group
- Inherits:
-
Object
- Object
- GoogleR::Group
- Defined in:
- lib/google_r/group.rb
Defined Under Namespace
Classes: Property
Instance Attribute Summary collapse
-
#etag ⇒ Object
Returns the value of attribute etag.
-
#google_id ⇒ Object
Returns the value of attribute google_id.
-
#property ⇒ Object
Returns the value of attribute property.
-
#title ⇒ Object
Returns the value of attribute title.
-
#updated ⇒ Object
Returns the value of attribute updated.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#etag ⇒ Object
Returns the value of attribute etag.
6 7 8 |
# File 'lib/google_r/group.rb', line 6 def etag @etag end |
#google_id ⇒ Object
Returns the value of attribute google_id.
6 7 8 |
# File 'lib/google_r/group.rb', line 6 def google_id @google_id end |
#property ⇒ Object
Returns the value of attribute property.
6 7 8 |
# File 'lib/google_r/group.rb', line 6 def property @property end |
#title ⇒ Object
Returns the value of attribute title.
6 7 8 |
# File 'lib/google_r/group.rb', line 6 def title @title end |
#updated ⇒ Object
Returns the value of attribute updated.
6 7 8 |
# File 'lib/google_r/group.rb', line 6 def updated @updated end |
Class Method Details
.api_headers ⇒ Object
16 17 18 19 20 21 |
# File 'lib/google_r/group.rb', line 16 def self.api_headers { 'GData-Version' => '3.0', 'Content-Type' => 'application/atom+xml', } end |
.from_xml(doc, *attrs) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/google_r/group.rb', line 54 def self.from_xml(doc, *attrs) is_collection = doc.search("totalResults").size > 0 return doc.search("entry").map { |e| from_xml(e) } if is_collection group = self.new google_id = doc.search("id") if google_id.empty? group.etag = group.google_id = nil else group.etag = doc["etag"] group.google_id = google_id.inner_text end title = doc.search("title") group.title = title.inner_text unless title.size == 0 updated = doc.search("updated") group.updated = Time.parse(updated.inner_text) unless updated.empty? extended = doc.search("extendedProperty") if extended.size != 0 info = extended.search("info") info = info.size == 0 ? nil : info.inner_text property = GoogleR::Group::Property.new(extended[0][:name], info) group.property = property end group end |
.path ⇒ Object
12 13 14 |
# File 'lib/google_r/group.rb', line 12 def self.path "/m8/feeds/groups/default/full/" end |
.url ⇒ Object
8 9 10 |
# File 'lib/google_r/group.rb', line 8 def self.url "https://www.google.com" end |
Instance Method Details
#new? ⇒ Boolean
85 86 87 |
# File 'lib/google_r/group.rb', line 85 def new? self.google_id.nil? end |
#path ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/google_r/group.rb', line 23 def path if new? self.class.path else self.class.path + google_id.split("/")[-1] end end |
#to_google ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/google_r/group.rb', line 31 def to_google builder = Nokogiri::XML::Builder.new(:encoding => "UTF-8") do |xml| root_attrs = { 'xmlns:atom' => 'http://www.w3.org/2005/Atom', 'xmlns:gd' => 'http://schemas.google.com/g/2005', } root_attrs["gd:etag"] = self.etag unless new? xml.entry(root_attrs) do xml.id_ self.google_id unless new? xml.updated self.updated.strftime("%Y-%m-%dT%H:%M:%S.%LZ") unless self.updated.nil? xml['atom'].title({:type => "text"}, self.title) unless self.title.nil? if self.property xml['gd'].extendedProperty({:name => self.property.name}) do xml.info self.property.info unless self.property.info.nil? end end xml.parent.namespace = xml.parent.namespace_definitions.find { |ns| ns.prefix == "atom" } end end builder.to_xml end |