lib/google_client/event.rb in google_client-0.1.0 vs lib/google_client/event.rb in google_client-0.2.0
- old
+ new
@@ -11,10 +11,11 @@
attr_accessor :attendees
attr_accessor :start_time
attr_accessor :end_time
attr_accessor :location
attr_accessor :attendees
+ attr_accessor :send_event_notifications
attr_accessor :comments
def initialize(params = {})
@id = params[:event_id] || params[:id] || nil
@title = params[:title]
@@ -23,28 +24,31 @@
@start_time = params[:start_time]
@end_time = params[:end_time]
@calendar_id = params[:calendar_id]
@calendar = params[:calendar]
@comments = params[:comments]
- @attendees = params[:attendees]
+ @attendees = params[:attendees].nil? ? [] : params[:attendees].map{|x| x.kind_of?(String) ? {:email => x} : x}
+ @send_event_notifications = params[:send_event_notifications]
@calendar.nil? or @connection = @calendar.connection
@json_mode = true
block_given? and yield self
end
def to_s
- "#{self.class.name} => { id: #{@id}, title: #{@title}, description: #{@description}, :start_time => #{@start_time}, :end_time => #{@end_time}, :location => #{@location}, :attendees => #{@attendees} }"
+ "#{self.class.name} => { id: #{@id}, title: #{@title}, description: #{@description}, :start_time => #{@start_time}, :end_time => #{@end_time}, :location => #{@location}, :attendees => #{@attendees}, :send_event_notifications => #{@send_event_notifications}, :calendar => #{@calendar} }"
end
def to_hash
{
:title => @title,
:details => @description,
:timeZone => @timezone,
:when => [{:start => @start_time,
- :end => @end_time}]
+ :end => @end_time}],
+ :attendees => @attendees.map{|x| {:valueString => x[:name], :email => x[:email]}},
+ :sendEventNotifications => @send_event_notifications || false
}.delete_if{|k,v| v.nil?}
end
def connection
@@ -95,11 +99,11 @@
def fetch
if @calendar_id.nil?
@calendar.nil? and raise Error.new "calendar or calendar_id must be valid in the event"
@calendar_id = @calendar.id
end
- data = connection.get "/calendar/feeds/#{@calendar_id}/private/full/#{@id}"
+ data = decode_response connection.get "/calendar/feeds/#{@calendar_id}/private/full/#{@id}"
self.class.build_event data["entry"], @calendar
end
class << self
@@ -110,11 +114,20 @@
new(params)
end
end
def build_event(data, calendar = nil)
+ data.nil? and return Event.new
+
attendees = data["gd$who"]
- attendees.nil? or attendees = attendees.map{|attendee| {:name => attendee["valueString"], :email => attendee["email"]}}
+ attendees.nil? or attendees = attendees.inject([]) do |values, attendee|
+ if attendee.has_key?("gd$attendeeStatus")
+ values << { :name => attendee["valueString"],
+ :email => attendee["email"],
+ :status => attendee["gd$attendeeStatus"]["value"].split("\.").last}
+ end
+ values
+ end
start_time = data["gd$when"][0]["startTime"]
end_time = data["gd$when"][0]["endTime"]
Event.new({:id => data["id"]["$t"].split("full/").last,
\ No newline at end of file