viewpoint 0.1.13 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -200,7 +200,7 @@ module Viewpoint
200
200
  def update!(updates)
201
201
  conn = Viewpoint::EWS::EWS.instance
202
202
  resp = conn.ews.update_item([{:id => @item_id, :change_key => @change_key}], {:updates => updates},
203
- {:message_disposition => 'SaveOnly', :conflict_resolution => 'AutoResolve', :send_meeting_invitations_or_cancellations => 'SendToNone'})
203
+ {:message_disposition => 'SaveOnly', :conflict_resolution => 'AutoResolve', :send_meeting_invitations_or_cancellations => 'SendOnlyToChanged'})
204
204
  if resp.status == 'Success'
205
205
  @item_id = resp.items.first[resp.items.first.keys.first][:item_id][:id]
206
206
  @change_key = resp.items.first[resp.items.first.keys.first][:item_id][:change_key]
@@ -59,8 +59,6 @@ module Viewpoint
59
59
  end
60
60
  end
61
61
 
62
-
63
-
64
62
  # Create a Contact in the Exchange Data Store
65
63
  def self.add_contact()
66
64
  item = {}
@@ -76,25 +74,41 @@ module Viewpoint
76
74
  end
77
75
  end
78
76
 
79
-
80
-
81
77
  # Initialize an Exchange Web Services item of type Contact
82
78
  def initialize(ews_item)
83
79
  super(ews_item)
84
80
  end
81
+
82
+ def set_email_addresses(email1, email2=nil, email3=nil)
83
+ changes = []
84
+ type = self.class.name.split(/::/).last.ruby_case.to_sym
85
+ k = :email_addresses
86
+ v = 'EmailAddress1'
87
+ changes << {:set_item_field =>
88
+ [{:indexed_field_uRI => {:field_uRI => FIELD_URIS[k][:text], :field_index => v}}, {type=>{k => {:entry => {:key => v, :text => email1}}}}]} unless email1.nil?
89
+ v = 'EmailAddress2'
90
+ changes << {:set_item_field =>
91
+ [{:indexed_field_uRI => {:field_uRI => FIELD_URIS[k][:text], :field_index => v}}, {type=>{k => {:entry => {:key => v, :text => email2}}}}]} unless email2.nil?
92
+ v = 'EmailAddress3'
93
+ changes << {:set_item_field =>
94
+ [{:indexed_field_uRI => {:field_uRI => FIELD_URIS[k][:text], :field_index => v}}, {type=>{k => {:entry => {:key => v, :text => email3}}}}]} unless email3.nil?
95
+ @updates.merge!({:preformatted => changes}) {|k,v1,v2| v1 + v2}
96
+ end
97
+
85
98
 
86
99
  private
87
100
 
88
101
  def init_methods
89
102
  super()
90
103
 
91
- define_str_var :file_as, :file_as_mapping, :display_name, :job_title, :given_name, :surname
104
+ define_str_var :file_as, :file_as_mapping, :display_name, :job_title, :given_name, :surname, :company_name
92
105
  define_attr_str_var :complete_name, :first_name, :middle_name, :last_name, :initials, :full_name
93
106
  define_inet_addresses :email_addresses, :im_addresses
94
107
  define_phone_numbers :phone_numbers
95
108
  define_physical_addresses :physical_addresses
96
109
  end
97
-
110
+
111
+
98
112
  # Define email_addresses or im_addresses for a Contact
99
113
  def define_inet_addresses(*inet_addresses)
100
114
  inet_addresses.each do |itype|
@@ -100,6 +100,13 @@ module Viewpoint
100
100
  end
101
101
  end
102
102
 
103
+ # Clear out any pending updates
104
+ # @return [TrueClass]
105
+ def clear_updates!
106
+ @updates = {}
107
+ true
108
+ end
109
+
103
110
  # Call UpdateItem for this item with the passed updates
104
111
  # @param [Hash] updates a well-formed update hash
105
112
  # @example {:set_item_field=>{:field_uRI=>{:field_uRI=>"message:IsRead"}, :message=>{:is_read=>{:text=>"true"}}}}
@@ -148,7 +148,7 @@ module Viewpoint
148
148
  :culture => {:text => 'contacts:Culture', :writable => true},
149
149
  :department => {:text => 'contacts:Department', :writable => true},
150
150
  :display_name => {:text => 'contacts:DisplayName', :writable => true},
151
- :email_addresses => {:text => 'contacts:EmailAddresses', :writable => true},
151
+ :email_addresses => {:ftype => :indexed_field_uRI, :text => 'contacts:EmailAddress', :writable => true},
152
152
  :file_as => {:text => 'contacts:FileAs', :writable => true},
153
153
  :file_as_mapping => {:text => 'contacts:FileAsMapping', :writable => true},
154
154
  :generation => {:text => 'contacts:Generation', :writable => true},
@@ -55,27 +55,28 @@ module Viewpoint
55
55
  # This is the text
56
56
  # </method_name>
57
57
  def define_str_var(*vars)
58
- map = ( vars.last.is_a?(Hash) ? vars.pop : {})
58
+ map = ( vars.last.is_a?(Hash) ? vars.pop : {})
59
59
  vars.each do |var|
60
+ mname = ( map.has_key?(var) ? map[var] : var )
60
61
  if(@ews_item[var])
61
- mname = ( map.has_key?(var) ? map[var] : var )
62
62
  @ews_methods << mname
63
63
  self.instance_eval <<-EOF
64
64
  def #{mname}
65
65
  @ews_item[:#{var}][:text]
66
66
  end
67
67
  EOF
68
- if(Item::FIELD_URIS.has_key?(var.to_sym) && Item::FIELD_URIS[var.to_sym][:writable])
69
- self.instance_eval <<-EOF
70
- def #{mname}=(newtext)
71
- @ews_item[:#{var}][:text] = newtext
72
- @updates[:#{var}] = @ews_item[:#{var}]
73
- end
74
- EOF
75
- end
76
68
  else
77
69
  @ews_methods_undef << var
78
70
  end
71
+ if(Item::FIELD_URIS.has_key?(var.to_sym) && Item::FIELD_URIS[var.to_sym][:writable])
72
+ self.instance_eval <<-EOF
73
+ def #{mname}=(newtext)
74
+ @ews_item[:#{var}] = {} unless @ews_item[:#{var}]
75
+ @ews_item[:#{var}][:text] = newtext
76
+ @updates[:#{var}] = @ews_item[:#{var}]
77
+ end
78
+ EOF
79
+ end
79
80
  end
80
81
  end
81
82
 
@@ -107,7 +108,7 @@ module Viewpoint
107
108
  end
108
109
  end
109
110
  end
110
-
111
+
111
112
 
112
113
  def define_int_var(*vars)
113
114
  vars.each do |var|
@@ -115,20 +116,21 @@ module Viewpoint
115
116
  @ews_methods << var
116
117
  self.instance_eval <<-EOF
117
118
  def #{var}
118
- @#{var} ||= @ews_item[:#{var}][:text].to_i
119
+ @ews_item[:#{var}][:text].to_i
119
120
  end
120
121
  EOF
121
- if(Item::FIELD_URIS.has_key?(var.to_sym) && Item::FIELD_URIS[var.to_sym][:writable])
122
- self.instance_eval <<-EOF
123
- def #{var}=(newint)
124
- @ews_item[:#{var}][:text] = newint.to_s
125
- @updates[:#{var}] = @ews_item[:#{var}]
126
- end
127
- EOF
128
- end
129
122
  else
130
123
  @ews_methods_undef << var
131
124
  end
125
+ if(Item::FIELD_URIS.has_key?(var.to_sym) && Item::FIELD_URIS[var.to_sym][:writable])
126
+ self.instance_eval <<-EOF
127
+ def #{var}=(newint)
128
+ @ews_item[:#{var}] = {} unless @ews_item[:#{var}]
129
+ @ews_item[:#{var}][:text] = newint.to_s
130
+ @updates[:#{var}] = @ews_item[:#{var}]
131
+ end
132
+ EOF
133
+ end
132
134
  end
133
135
  end
134
136
 
@@ -138,21 +140,22 @@ module Viewpoint
138
140
  @ews_methods << "#{var}?".to_sym
139
141
  self.instance_eval <<-EOF
140
142
  def #{var}?
141
- @#{var} ||= (@ews_item[:#{var}][:text] == 'true') ? true : false
143
+ (@ews_item[:#{var}][:text] == 'true') ? true : false
142
144
  end
143
145
  EOF
144
- if(Item::FIELD_URIS.has_key?(var.to_sym) && Item::FIELD_URIS[var.to_sym][:writable])
145
- self.instance_eval <<-EOF
146
- def #{var}=(newbool)
147
- raise EwsError, "Value not boolean for method #{var}=" unless(newbool.is_a?(TrueClass) || newbool.is_a?(FalseClass))
148
- @ews_item[:#{var}][:text] = newbool.to_s
149
- @updates[:#{var}] = @ews_item[:#{var}]
150
- end
151
- EOF
152
- end
153
146
  else
154
147
  @ews_methods_undef << "#{var}?".to_sym
155
148
  end
149
+ if(Item::FIELD_URIS.has_key?(var.to_sym) && Item::FIELD_URIS[var.to_sym][:writable])
150
+ self.instance_eval <<-EOF
151
+ def #{var}=(newbool)
152
+ raise EwsError, "Value not boolean for method #{var}=" unless(newbool.is_a?(TrueClass) || newbool.is_a?(FalseClass))
153
+ @ews_item[:#{var}] = {} unless @ews_item[:#{var}]
154
+ @ews_item[:#{var}][:text] = newbool.to_s
155
+ @updates[:#{var}] = @ews_item[:#{var}]
156
+ end
157
+ EOF
158
+ end
156
159
  end
157
160
  end
158
161
 
@@ -162,20 +165,21 @@ module Viewpoint
162
165
  @ews_methods << var
163
166
  self.instance_eval <<-EOF
164
167
  def #{var}
165
- @#{var} ||= DateTime.parse(@ews_item[:#{var}][:text])
168
+ DateTime.parse(@ews_item[:#{var}][:text])
166
169
  end
167
170
  EOF
168
- if(Item::FIELD_URIS.has_key?(var.to_sym) && Item::FIELD_URIS[var.to_sym][:writable])
169
- self.instance_eval <<-EOF
170
- def #{var}=(newdate)
171
- @ews_item[:#{var}][:text] = newdate.to_s
172
- @updates[:#{var}] = @ews_item[:#{var}]
173
- end
174
- EOF
175
- end
176
171
  else
177
172
  @ews_methods_undef << var
178
173
  end
174
+ if(Item::FIELD_URIS.has_key?(var.to_sym) && Item::FIELD_URIS[var.to_sym][:writable])
175
+ self.instance_eval <<-EOF
176
+ def #{var}=(newdate)
177
+ @ews_item[:#{var}] = {} unless @ews_item[:#{var}]
178
+ @ews_item[:#{var}][:text] = newdate.to_s
179
+ @updates[:#{var}] = @ews_item[:#{var}]
180
+ end
181
+ EOF
182
+ end
179
183
  end
180
184
  end
181
185
 
@@ -58,12 +58,15 @@ module Viewpoint
58
58
  # @param [String] body The task body
59
59
  # @param [DateTime] v_start The date/time when this task begins
60
60
  # @param [DateTime] v_end The date/time when this task is due
61
- def self.create_task(folder, subject, body, v_start = nil, v_end = nil)
61
+ # @param [Symbol] status The current status of this task
62
+ # :completed, :in_progress, :waiting_on_others,
63
+ def self.create_task(folder, subject, body, v_start = nil, v_end = nil, status = nil)
62
64
  item = {}
63
65
  item[:subject] = {:text => subject}
64
66
  item[:body] = {:text => body, :body_type => 'Text'} unless body.nil?
65
67
  item[:start_date] = {:text => v_start.to_s} unless v_start.nil?
66
68
  item[:due_date] = {:text => v_end.to_s} unless v_end.nil?
69
+ item[:status] = {:text => status} unless status.nil?
67
70
 
68
71
  self.create_item_from_hash(item, folder)
69
72
  end
@@ -109,7 +112,6 @@ module Viewpoint
109
112
 
110
113
  def init_methods
111
114
  super
112
-
113
115
  define_str_var :status, :owner
114
116
  define_bool_var :is_complete, :is_recurring, :is_team_task
115
117
  define_int_var :percent_complete, :actual_work, :change_count
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 13
9
- version: 0.1.13
8
+ - 14
9
+ version: 0.1.14
10
10
  platform: ruby
11
11
  authors:
12
12
  - Dan Wanek
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-31 00:00:00 -06:00
17
+ date: 2011-01-05 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency