Permalink
Browse files

change way setters are dynamically generated.

add status to Task#create_task
  • Loading branch information...
zenchild committed Jan 5, 2011
1 parent 0dda38a commit 88f82fca60cf976bb07cda722211c9a173c0c136
Showing with 48 additions and 42 deletions.
  1. +1 −1 lib/model/calendar_item.rb
  2. +43 −39 lib/model/model.rb
  3. +4 −2 lib/model/task.rb
@@ -200,7 +200,7 @@ def remove_attendees!(attendees)
def update!(updates)
conn = Viewpoint::EWS::EWS.instance
resp = conn.ews.update_item([{:id => @item_id, :change_key => @change_key}], {:updates => updates},
- {:message_disposition => 'SaveOnly', :conflict_resolution => 'AutoResolve', :send_meeting_invitations_or_cancellations => 'SendToNone'})
+ {:message_disposition => 'SaveOnly', :conflict_resolution => 'AutoResolve', :send_meeting_invitations_or_cancellations => 'SendOnlyToChanged'})
if resp.status == 'Success'
@item_id = resp.items.first[resp.items.first.keys.first][:item_id][:id]
@change_key = resp.items.first[resp.items.first.keys.first][:item_id][:change_key]
View
@@ -55,27 +55,28 @@ def initialize
# This is the text
# </method_name>
def define_str_var(*vars)
- map = ( vars.last.is_a?(Hash) ? vars.pop : {})
+ map = ( vars.last.is_a?(Hash) ? vars.pop : {})
vars.each do |var|
+ mname = ( map.has_key?(var) ? map[var] : var )
if(@ews_item[var])
- mname = ( map.has_key?(var) ? map[var] : var )
@ews_methods << mname
self.instance_eval <<-EOF
def #{mname}
@ews_item[:#{var}][:text]
end
EOF
- if(Item::FIELD_URIS.has_key?(var.to_sym) && Item::FIELD_URIS[var.to_sym][:writable])
- self.instance_eval <<-EOF
- def #{mname}=(newtext)
- @ews_item[:#{var}][:text] = newtext
- @updates[:#{var}] = @ews_item[:#{var}]
- end
- EOF
- end
else
@ews_methods_undef << var
end
+ if(Item::FIELD_URIS.has_key?(var.to_sym) && Item::FIELD_URIS[var.to_sym][:writable])
+ self.instance_eval <<-EOF
+ def #{mname}=(newtext)
+ @ews_item[:#{var}] = {} unless @ews_item[:#{var}]
+ @ews_item[:#{var}][:text] = newtext
+ @updates[:#{var}] = @ews_item[:#{var}]
+ end
+ EOF
+ end
end
end
@@ -107,28 +108,29 @@ def #{var}
end
end
end
-
+
def define_int_var(*vars)
vars.each do |var|
if(@ews_item[var])
@ews_methods << var
self.instance_eval <<-EOF
def #{var}
- @#{var} ||= @ews_item[:#{var}][:text].to_i
+ @ews_item[:#{var}][:text].to_i
end
EOF
- if(Item::FIELD_URIS.has_key?(var.to_sym) && Item::FIELD_URIS[var.to_sym][:writable])
- self.instance_eval <<-EOF
- def #{var}=(newint)
- @ews_item[:#{var}][:text] = newint.to_s
- @updates[:#{var}] = @ews_item[:#{var}]
- end
- EOF
- end
else
@ews_methods_undef << var
end
+ if(Item::FIELD_URIS.has_key?(var.to_sym) && Item::FIELD_URIS[var.to_sym][:writable])
+ self.instance_eval <<-EOF
+ def #{var}=(newint)
+ @ews_item[:#{var}] = {} unless @ews_item[:#{var}]
+ @ews_item[:#{var}][:text] = newint.to_s
+ @updates[:#{var}] = @ews_item[:#{var}]
+ end
+ EOF
+ end
end
end
@@ -138,21 +140,22 @@ def define_bool_var(*vars)
@ews_methods << "#{var}?".to_sym
self.instance_eval <<-EOF
def #{var}?
- @#{var} ||= (@ews_item[:#{var}][:text] == 'true') ? true : false
+ (@ews_item[:#{var}][:text] == 'true') ? true : false
end
EOF
- if(Item::FIELD_URIS.has_key?(var.to_sym) && Item::FIELD_URIS[var.to_sym][:writable])
- self.instance_eval <<-EOF
- def #{var}=(newbool)
- raise EwsError, "Value not boolean for method #{var}=" unless(newbool.is_a?(TrueClass) || newbool.is_a?(FalseClass))
- @ews_item[:#{var}][:text] = newbool.to_s
- @updates[:#{var}] = @ews_item[:#{var}]
- end
- EOF
- end
else
@ews_methods_undef << "#{var}?".to_sym
end
+ if(Item::FIELD_URIS.has_key?(var.to_sym) && Item::FIELD_URIS[var.to_sym][:writable])
+ self.instance_eval <<-EOF
+ def #{var}=(newbool)
+ raise EwsError, "Value not boolean for method #{var}=" unless(newbool.is_a?(TrueClass) || newbool.is_a?(FalseClass))
+ @ews_item[:#{var}] = {} unless @ews_item[:#{var}]
+ @ews_item[:#{var}][:text] = newbool.to_s
+ @updates[:#{var}] = @ews_item[:#{var}]
+ end
+ EOF
+ end
end
end
@@ -162,20 +165,21 @@ def define_datetime_var(*vars)
@ews_methods << var
self.instance_eval <<-EOF
def #{var}
- @#{var} ||= DateTime.parse(@ews_item[:#{var}][:text])
+ DateTime.parse(@ews_item[:#{var}][:text])
end
EOF
- if(Item::FIELD_URIS.has_key?(var.to_sym) && Item::FIELD_URIS[var.to_sym][:writable])
- self.instance_eval <<-EOF
- def #{var}=(newdate)
- @ews_item[:#{var}][:text] = newdate.to_s
- @updates[:#{var}] = @ews_item[:#{var}]
- end
- EOF
- end
else
@ews_methods_undef << var
end
+ if(Item::FIELD_URIS.has_key?(var.to_sym) && Item::FIELD_URIS[var.to_sym][:writable])
+ self.instance_eval <<-EOF
+ def #{var}=(newdate)
+ @ews_item[:#{var}] = {} unless @ews_item[:#{var}]
+ @ews_item[:#{var}][:text] = newdate.to_s
+ @updates[:#{var}] = @ews_item[:#{var}]
+ end
+ EOF
+ end
end
end
View
@@ -58,12 +58,15 @@ def self.create_item_from_hash(item, folder_id = :tasks, disposition = 'SaveOnly
# @param [String] body The task body
# @param [DateTime] v_start The date/time when this task begins
# @param [DateTime] v_end The date/time when this task is due
- def self.create_task(folder, subject, body, v_start = nil, v_end = nil)
+ # @param [Symbol] status The current status of this task
+ # :completed, :in_progress, :waiting_on_others,
+ def self.create_task(folder, subject, body, v_start = nil, v_end = nil, status = nil)
item = {}
item[:subject] = {:text => subject}
item[:body] = {:text => body, :body_type => 'Text'} unless body.nil?
item[:start_date] = {:text => v_start.to_s} unless v_start.nil?
item[:due_date] = {:text => v_end.to_s} unless v_end.nil?
+ item[:status] = {:text => status} unless status.nil?
self.create_item_from_hash(item, folder)
end
@@ -109,7 +112,6 @@ def recycle!(affected_task_occurrences='AllOccurrences')
def init_methods
super
-
define_str_var :status, :owner
define_bool_var :is_complete, :is_recurring, :is_team_task
define_int_var :percent_complete, :actual_work, :change_count

0 comments on commit 88f82fc

Please sign in to comment.