exchanger 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/LICENSE +20 -0
  2. data/README.md +53 -0
  3. data/lib/exchanger.rb +79 -0
  4. data/lib/exchanger/attributes.rb +61 -0
  5. data/lib/exchanger/boolean.rb +4 -0
  6. data/lib/exchanger/client.rb +19 -0
  7. data/lib/exchanger/config.rb +32 -0
  8. data/lib/exchanger/dirty.rb +239 -0
  9. data/lib/exchanger/element.rb +161 -0
  10. data/lib/exchanger/elements/attendee.rb +10 -0
  11. data/lib/exchanger/elements/base_folder.rb +61 -0
  12. data/lib/exchanger/elements/calendar_folder.rb +11 -0
  13. data/lib/exchanger/elements/calendar_item.rb +59 -0
  14. data/lib/exchanger/elements/complete_name.rb +16 -0
  15. data/lib/exchanger/elements/contact.rb +49 -0
  16. data/lib/exchanger/elements/contacts_folder.rb +17 -0
  17. data/lib/exchanger/elements/distribution_list.rb +8 -0
  18. data/lib/exchanger/elements/email_address.rb +16 -0
  19. data/lib/exchanger/elements/entry.rb +11 -0
  20. data/lib/exchanger/elements/folder.rb +9 -0
  21. data/lib/exchanger/elements/identifier.rb +7 -0
  22. data/lib/exchanger/elements/im_address.rb +20 -0
  23. data/lib/exchanger/elements/item.rb +86 -0
  24. data/lib/exchanger/elements/mailbox.rb +34 -0
  25. data/lib/exchanger/elements/meeting_cancellation.rb +4 -0
  26. data/lib/exchanger/elements/meeting_message.rb +16 -0
  27. data/lib/exchanger/elements/meeting_request.rb +6 -0
  28. data/lib/exchanger/elements/meeting_response.rb +4 -0
  29. data/lib/exchanger/elements/message.rb +24 -0
  30. data/lib/exchanger/elements/phone_number.rb +13 -0
  31. data/lib/exchanger/elements/physical_address.rb +15 -0
  32. data/lib/exchanger/elements/search_folder.rb +5 -0
  33. data/lib/exchanger/elements/single_recipient.rb +6 -0
  34. data/lib/exchanger/elements/task.rb +5 -0
  35. data/lib/exchanger/elements/tasks_folder.rb +4 -0
  36. data/lib/exchanger/field.rb +139 -0
  37. data/lib/exchanger/operation.rb +110 -0
  38. data/lib/exchanger/operations/create_item.rb +64 -0
  39. data/lib/exchanger/operations/expand_dl.rb +42 -0
  40. data/lib/exchanger/operations/find_folder.rb +55 -0
  41. data/lib/exchanger/operations/find_item.rb +54 -0
  42. data/lib/exchanger/operations/get_folder.rb +55 -0
  43. data/lib/exchanger/operations/get_item.rb +44 -0
  44. data/lib/exchanger/operations/resolve_names.rb +43 -0
  45. data/lib/exchanger/operations/update_item.rb +43 -0
  46. data/lib/exchanger/persistence.rb +27 -0
  47. data/spec/calendar_item_spec.rb +26 -0
  48. data/spec/client_spec.rb +11 -0
  49. data/spec/contact_spec.rb +68 -0
  50. data/spec/element_spec.rb +4 -0
  51. data/spec/field_spec.rb +118 -0
  52. data/spec/folder_spec.rb +13 -0
  53. data/spec/mailbox_spec.rb +9 -0
  54. data/spec/spec_helper.rb +6 -0
  55. metadata +208 -0
@@ -0,0 +1,11 @@
1
+ require "spec/spec_helper"
2
+
3
+ describe Exchanger::Client do
4
+ before do
5
+ @client = Exchanger::Client.new
6
+ end
7
+
8
+ it "should respond to #request" do
9
+ @client.should respond_to(:request)
10
+ end
11
+ end
@@ -0,0 +1,68 @@
1
+ require "spec/spec_helper"
2
+
3
+ describe Exchanger::Contact do
4
+ before do
5
+ @folder = Exchanger::Folder.find(:contacts, "edgars.beigarts@tieto.com")
6
+ end
7
+
8
+ it "should return calendar folder" do
9
+ @folder.class.should == Exchanger::ContactsFolder
10
+ end
11
+
12
+ it "should have contacts" do
13
+ @folder.items.size.should > 0
14
+ end
15
+
16
+ it "should create a new contact and update it" do
17
+ prev_items_size = @folder.items.size
18
+ @contact = @folder.new_contact(:given_name => "Edgars", :surname => "Beigarts", :nickname => "EBEI")
19
+ @contact.complete_name = \
20
+ Exchanger::CompleteName.new(:first_name => "Edgars", :last_name => "Beigarts") # read only
21
+ @contact.physical_addresses = [
22
+ Exchanger::PhysicalAddress.new(:key => "Business", :city => "Riga", :street => "Brivibas iela 1", :state => ""),
23
+ Exchanger::PhysicalAddress.new(:key => "Home", :city => "Riga", :street => "Brivibas iela 2")
24
+ ]
25
+ @contact.email_addresses = [
26
+ Exchanger::EmailAddress.new(:key => "EmailAddress1", :text => "edgars.beigarts@tieto.com")
27
+ ]
28
+ @contact.should be_changed
29
+ @contact.save
30
+ @contact.should_not be_new_record
31
+ @contact.should_not be_changed
32
+ @contact.reload
33
+ @contact.nickname.should == "EBEI"
34
+ @contact.physical_addresses.size.should == 2
35
+ @contact.physical_addresses[0].key.should == "Business"
36
+ @contact.physical_addresses[0].city.should == "Riga"
37
+ @contact.physical_addresses[1].key.should == "Home"
38
+ @contact.physical_addresses[1].city.should == "Riga"
39
+ @contact.email_addresses.size.should == 1
40
+ @contact.email_addresses[0].key.should == "EmailAddress1"
41
+ @contact.email_addresses[0].text.should == "edgars.beigarts@tieto.com"
42
+ @folder.items.size.should == prev_items_size + 1
43
+ @contact.nickname = "Test"
44
+ @contact.physical_addresses.pop # delete last address
45
+ @contact.should be_changed
46
+ @contact.save
47
+ @contact.should_not be_changed
48
+ @contact.physical_addresses.size.should == 1
49
+ end
50
+
51
+ it "should find a contact by id" do
52
+ @contact = @folder.items.first
53
+ Exchanger::Item.find(@contact.id).should be_an_instance_of(Exchanger::Contact)
54
+ end
55
+
56
+ it "should have parent folder" do
57
+ @contact = @folder.items.first
58
+ @contact.parent_folder.should == @folder
59
+ @contact = Exchanger::Item.find(@contact.id)
60
+ @contact.parent_folder.should == @folder
61
+ end
62
+
63
+ it "cannot create a contact without a parent_folder" do
64
+ @contact = Exchanger::Contact.new
65
+ @contact.save.should be_false
66
+ @contact.errors.should include("Parent folder can't be blank")
67
+ end
68
+ end
@@ -0,0 +1,4 @@
1
+ require "spec/spec_helper"
2
+
3
+ describe Exchanger::Element do
4
+ end
@@ -0,0 +1,118 @@
1
+ require "spec/spec_helper"
2
+
3
+ describe Exchanger::Field do
4
+ describe "String (default type)" do
5
+ before do
6
+ @field = Exchanger::Field.new(:full_name)
7
+ @full_name = "Edgars Beigarts"
8
+ @xml = Nokogiri::XML::Builder.new do |xml|
9
+ xml.FullName @full_name
10
+ end.doc.root
11
+ end
12
+
13
+ it "should convert value to XML" do
14
+ @field.to_xml(@full_name).to_s.gsub(/\n\s*/, "").should == @xml.to_s.gsub(/\n\s*/, "")
15
+ end
16
+
17
+ it "should convert XML to value" do
18
+ @field.value_from_xml(@xml).should == @full_name
19
+ end
20
+ end
21
+
22
+ describe "String (UID)" do
23
+ before do
24
+ @field = Exchanger::Field.new(:uid, :type => String, :name => "UID")
25
+ @uid = "123"
26
+ @xml = Nokogiri::XML::Builder.new do |xml|
27
+ xml.UID @uid
28
+ end.doc.root
29
+ end
30
+
31
+ it "should convert value to XML" do
32
+ @field.to_xml(@uid).to_s.gsub(/\n\s*/, "").should == @xml.to_s.gsub(/\n\s*/, "")
33
+ end
34
+
35
+ it "should convert XML to value" do
36
+ @field.value_from_xml(@xml).should == @uid
37
+ end
38
+ end
39
+
40
+ describe "Integer" do
41
+ before do
42
+ @field = Exchanger::Field.new(:total_count, :type => Integer)
43
+ @total_count = 5
44
+ @xml = Nokogiri::XML::Builder.new do |xml|
45
+ xml.TotalCount @total_count
46
+ end.doc.root
47
+ end
48
+
49
+ it "should convert value to XML" do
50
+ @field.to_xml(@total_count).to_s.gsub(/\n\s*/, "").should == @xml.to_s.gsub(/\n\s*/, "")
51
+ end
52
+
53
+ it "should convert XML to value" do
54
+ @field.value_from_xml(@xml).should == @total_count
55
+ end
56
+ end
57
+
58
+ describe "Boolean" do
59
+ before do
60
+ @field = Exchanger::Field.new(:is_read, :type => Exchanger::Boolean)
61
+ @is_read = true
62
+ @xml = Nokogiri::XML::Builder.new do |xml|
63
+ xml.IsRead @is_read.to_s
64
+ end.doc.root
65
+ end
66
+
67
+ it "should convert value to XML" do
68
+ @field.to_xml(@is_read).to_s.gsub(/\n\s*/, "").should == @xml.to_s.gsub(/\n\s*/, "")
69
+ end
70
+
71
+ it "should convert XML to value" do
72
+ @field.value_from_xml(@xml).should == @is_read
73
+ end
74
+ end
75
+
76
+ describe "Time" do
77
+ before do
78
+ @field = Exchanger::Field.new(:date_time_sent, :type => Time)
79
+ @date_time_sent_as_str = "2010-05-21T05:57:57Z"
80
+ @date_time_sent = Time.utc(2010, 5, 21, 5, 57, 57)
81
+ @xml = Nokogiri::XML::Builder.new do |xml|
82
+ xml.DateTimeSent @date_time_sent_as_str
83
+ end.doc.root
84
+ end
85
+
86
+ it "should convert value to XML" do
87
+ @field.to_xml(@date_time_sent).to_s.gsub(/\n\s*/, "").should == @xml.to_s.gsub(/\n\s*/, "")
88
+ end
89
+
90
+ it "should convert XML to value" do
91
+ @field.value_from_xml(@xml).should == @date_time_sent
92
+ end
93
+ end
94
+
95
+ describe "Array of Physical Addresses" do
96
+ before do
97
+ @field = Exchanger::Field.new(:phone_numbers, :type => [Exchanger::PhysicalAddress])
98
+ @address = Exchanger::PhysicalAddress.new(:street => "Brivibas str.", :city => "Riga", :state => "Latvia")
99
+ @xml = Nokogiri::XML::Builder.new do |xml|
100
+ xml.PhoneNumbers do
101
+ xml.Entry do
102
+ xml.Street @address.street
103
+ xml.City @address.city
104
+ xml.State @address.state
105
+ end
106
+ end
107
+ end.doc.root
108
+ end
109
+
110
+ it "should convert value to XML" do
111
+ @field.to_xml([@address]).to_s.gsub(/\n\s*/, "").should == @xml.to_s.gsub(/\n\s*/, "")
112
+ end
113
+
114
+ it "should convert XML to value" do
115
+ @field.value_from_xml(@xml).should == [@address]
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,13 @@
1
+ require "spec/spec_helper"
2
+
3
+ describe Exchanger::Folder do
4
+ describe "Root" do
5
+ before do
6
+ @folder = Exchanger::Folder.find(:root)
7
+ end
8
+
9
+ it "should have sub folders" do
10
+ @folder.folders.size.should > 0
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Exchanger::Mailbox do
4
+ it "should resolve names for distribution list and show members" do
5
+ @mailboxes = Exchanger::Mailbox.search("DL")
6
+ @mailboxes.size.should > 0
7
+ @mailboxes[0].members.size.should > 0
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ $:.unshift File.dirname(__FILE__) + '/../lib'
2
+
3
+ require "rubygems"
4
+ require "exchanger"
5
+
6
+ Exchanger::Config.instance.from_hash(YAML.load_file("#{File.dirname(__FILE__)}/config.yml"))
metadata ADDED
@@ -0,0 +1,208 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: exchanger
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Edgars Beigarts
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-07 00:00:00 +03:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activesupport
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 2
32
+ - 2
33
+ - 2
34
+ version: 2.2.2
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: nokogiri
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 27
46
+ segments:
47
+ - 1
48
+ - 3
49
+ - 0
50
+ version: 1.3.0
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: httpclient
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 119
62
+ segments:
63
+ - 2
64
+ - 1
65
+ - 5
66
+ - 2
67
+ version: 2.1.5.2
68
+ type: :runtime
69
+ version_requirements: *id003
70
+ - !ruby/object:Gem::Dependency
71
+ name: rubyntlm
72
+ prerelease: false
73
+ requirement: &id004 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 25
79
+ segments:
80
+ - 0
81
+ - 1
82
+ - 1
83
+ version: 0.1.1
84
+ type: :runtime
85
+ version_requirements: *id004
86
+ - !ruby/object:Gem::Dependency
87
+ name: rspec
88
+ prerelease: false
89
+ requirement: &id005 !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ hash: 27
95
+ segments:
96
+ - 1
97
+ - 3
98
+ - 0
99
+ version: 1.3.0
100
+ type: :development
101
+ version_requirements: *id005
102
+ description: Ruby library for accessing Microsoft Exchange using Exchange Web Services
103
+ email: 1@wb4.lv
104
+ executables: []
105
+
106
+ extensions: []
107
+
108
+ extra_rdoc_files:
109
+ - LICENSE
110
+ - README.md
111
+ files:
112
+ - LICENSE
113
+ - README.md
114
+ - lib/exchanger.rb
115
+ - lib/exchanger/attributes.rb
116
+ - lib/exchanger/boolean.rb
117
+ - lib/exchanger/client.rb
118
+ - lib/exchanger/config.rb
119
+ - lib/exchanger/dirty.rb
120
+ - lib/exchanger/element.rb
121
+ - lib/exchanger/elements/attendee.rb
122
+ - lib/exchanger/elements/base_folder.rb
123
+ - lib/exchanger/elements/calendar_folder.rb
124
+ - lib/exchanger/elements/calendar_item.rb
125
+ - lib/exchanger/elements/complete_name.rb
126
+ - lib/exchanger/elements/contact.rb
127
+ - lib/exchanger/elements/contacts_folder.rb
128
+ - lib/exchanger/elements/distribution_list.rb
129
+ - lib/exchanger/elements/email_address.rb
130
+ - lib/exchanger/elements/entry.rb
131
+ - lib/exchanger/elements/folder.rb
132
+ - lib/exchanger/elements/identifier.rb
133
+ - lib/exchanger/elements/im_address.rb
134
+ - lib/exchanger/elements/item.rb
135
+ - lib/exchanger/elements/mailbox.rb
136
+ - lib/exchanger/elements/meeting_cancellation.rb
137
+ - lib/exchanger/elements/meeting_message.rb
138
+ - lib/exchanger/elements/meeting_request.rb
139
+ - lib/exchanger/elements/meeting_response.rb
140
+ - lib/exchanger/elements/message.rb
141
+ - lib/exchanger/elements/phone_number.rb
142
+ - lib/exchanger/elements/physical_address.rb
143
+ - lib/exchanger/elements/search_folder.rb
144
+ - lib/exchanger/elements/single_recipient.rb
145
+ - lib/exchanger/elements/task.rb
146
+ - lib/exchanger/elements/tasks_folder.rb
147
+ - lib/exchanger/field.rb
148
+ - lib/exchanger/operation.rb
149
+ - lib/exchanger/operations/create_item.rb
150
+ - lib/exchanger/operations/expand_dl.rb
151
+ - lib/exchanger/operations/find_folder.rb
152
+ - lib/exchanger/operations/find_item.rb
153
+ - lib/exchanger/operations/get_folder.rb
154
+ - lib/exchanger/operations/get_item.rb
155
+ - lib/exchanger/operations/resolve_names.rb
156
+ - lib/exchanger/operations/update_item.rb
157
+ - lib/exchanger/persistence.rb
158
+ - spec/calendar_item_spec.rb
159
+ - spec/client_spec.rb
160
+ - spec/contact_spec.rb
161
+ - spec/element_spec.rb
162
+ - spec/field_spec.rb
163
+ - spec/folder_spec.rb
164
+ - spec/mailbox_spec.rb
165
+ - spec/spec_helper.rb
166
+ has_rdoc: true
167
+ homepage: http://github.com/ebeigarts/exchanger
168
+ licenses: []
169
+
170
+ post_install_message:
171
+ rdoc_options:
172
+ - --charset=UTF-8
173
+ require_paths:
174
+ - lib
175
+ required_ruby_version: !ruby/object:Gem::Requirement
176
+ none: false
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ hash: 3
181
+ segments:
182
+ - 0
183
+ version: "0"
184
+ required_rubygems_version: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ hash: 3
190
+ segments:
191
+ - 0
192
+ version: "0"
193
+ requirements: []
194
+
195
+ rubyforge_project:
196
+ rubygems_version: 1.3.7
197
+ signing_key:
198
+ specification_version: 3
199
+ summary: Ruby library for accessing Microsoft Exchange using Exchange Web Services
200
+ test_files:
201
+ - spec/calendar_item_spec.rb
202
+ - spec/client_spec.rb
203
+ - spec/contact_spec.rb
204
+ - spec/element_spec.rb
205
+ - spec/field_spec.rb
206
+ - spec/folder_spec.rb
207
+ - spec/mailbox_spec.rb
208
+ - spec/spec_helper.rb